[−][src]Trait sentry_contrib_native::Transport
Trait used to define a custom transport that Sentry can use to send events to a Sentry service.
Examples
#![cfg(feature = "custom-transport")] use reqwest::blocking::Client; struct CustomTransport { dsn: Dsn, client: Client, }; impl CustomTransport { fn new(options: &Options) -> Self { CustomTransport { dsn: Dsn::new(options.dsn().unwrap()).unwrap(), client: Client::new(), } } } impl Transport for CustomTransport { fn send(&self, envelope: RawEnvelope) { let dsn = self.dsn.clone(); let client = self.client.clone(); 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
custom-transport
example for a more sophisticated implementation.
Required methods
fn send(&self, envelope: RawEnvelope)
Sends the specified Envelope to a Sentry service.
It is highly recommended to not block in this method, but rather to enqueue the worker to another thread.
Provided methods
#[must_use]fn shutdown(self: Box<Self>, timeout: Duration) -> Shutdown
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.