pub trait Transport: 'static + Send + Sync {
    fn send(&self, envelope: RawEnvelope);

    fn shutdown(self: Box<Self>, timeout: Duration) -> Shutdown { ... }
}
Expand description

Trait used to define a custom transport that Sentry can use to send events to a Sentry service.

Examples

#![cfg(feature = "transport-custom")]

use reqwest::blocking::Client;

struct CustomTransport {
    dsn: Dsn,
    client: Client,
};

impl CustomTransport {
    fn new(options: &Options) -> Result<Self, ()> {
        Ok(CustomTransport {
            dsn: options.dsn().and_then(|dsn| Dsn::new(dsn).ok()).ok_or(())?,
            client: Client::new(),
        })
    }
}

impl Transport for CustomTransport {
    fn send(&self, envelope: RawEnvelope) {
        let dsn = self.dsn.clone();
        let client = self.client.clone();

        // in a correct implementation envelopes have to be sent in order for sessions to work
        std::thread::spawn(move || {
            let request = envelope
                .to_request(dsn)
                .map(|body| body.as_bytes().to_vec());
            client
                .execute(request.try_into().unwrap())
                .expect("failed to send envelope")
        });
    }
}

let dsn = "https://public_key_1234@organization_1234.ingest.sentry.io/project_id_1234";

let mut options = Options::new();
options.set_dsn(dsn);
options.set_transport(CustomTransport::new);

See the transport-custom example for a more sophisticated implementation.

Required methods

Sends the specified envelope to a Sentry service.

It is required to send envelopes in order for sessions to work correctly.

It is highly recommended to not block in this method, but rather to enqueue the worker to another thread.

Provided methods

Shuts down the transport worker. The worker should try to flush all of the pending requests to Sentry before shutdown. If the worker is successfully able to empty its queue and shutdown before the specified timeout duration, it should return Shutdown::Success, otherwise it should return Shutdown::TimedOut.

The default implementation will block the thread for timeout duration and always return Shutdown::TimedOut, it has to be adjusted to work correctly.

Implementors