From 985787e85fc494142c9809663a81ab1899a72b3d Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 9 Dec 2025 14:41:32 +1100 Subject: [PATCH 1/2] chore: expose transport utils --- sentry/src/transports/mod.rs | 8 ++++++++ sentry/src/transports/thread.rs | 8 ++++++++ sentry/src/transports/tokio_thread.rs | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/sentry/src/transports/mod.rs b/sentry/src/transports/mod.rs index 424c8a7a..d16f801b 100644 --- a/sentry/src/transports/mod.rs +++ b/sentry/src/transports/mod.rs @@ -8,10 +8,18 @@ use std::sync::Arc; #[cfg(feature = "httpdate")] mod ratelimit; +#[cfg(feature = "httpdate")] +pub use self::ratelimit::{RateLimiter, RateLimitingCategory}; + #[cfg(any(feature = "curl", feature = "ureq"))] mod thread; +#[cfg(any(feature = "curl", feature = "ureq"))] +pub use self::thread::TransportThread as StdTransportThread; + #[cfg(feature = "reqwest")] mod tokio_thread; +#[cfg(feature = "reqwest")] +pub use self::tokio_thread::TransportThread as TokioTransportThread; #[cfg(feature = "reqwest")] mod reqwest; diff --git a/sentry/src/transports/thread.rs b/sentry/src/transports/thread.rs index 6ccca6fa..989de6f5 100644 --- a/sentry/src/transports/thread.rs +++ b/sentry/src/transports/thread.rs @@ -18,6 +18,7 @@ enum Task { Shutdown, } +/// A background-thread dedicated to sending [`Envelope`]s whilst respecting the rate limits imposed in the responses. pub struct TransportThread { sender: SyncSender, shutdown: Arc, @@ -25,6 +26,7 @@ pub struct TransportThread { } impl TransportThread { + /// Spawn a new background thread. pub fn new(mut send: SendFn) -> Self where SendFn: FnMut(Envelope, &mut RateLimiter) + Send + 'static, @@ -78,6 +80,9 @@ impl TransportThread { } } + /// Send an [`Envelope`]. + /// + /// In case the background thread cannot keep up, the [`Envelope`] is dropped. pub fn send(&self, envelope: Envelope) { // Using send here would mean that when the channel fills up for whatever // reason, trying to send an envelope would block everything. We'd rather @@ -87,6 +92,9 @@ impl TransportThread { } } + /// Flush all pending [`Envelope`]s. + /// + /// Returns true if successful within given timeout. pub fn flush(&self, timeout: Duration) -> bool { let (sender, receiver) = sync_channel(1); let _ = self.sender.send(Task::Flush(sender)); diff --git a/sentry/src/transports/tokio_thread.rs b/sentry/src/transports/tokio_thread.rs index 5ef734e3..e39557ae 100644 --- a/sentry/src/transports/tokio_thread.rs +++ b/sentry/src/transports/tokio_thread.rs @@ -18,6 +18,7 @@ enum Task { Shutdown, } +/// A background-thread powered by [`tokio`] dedicated to sending [`Envelope`]s whilst respecting the rate limits imposed in the responses. pub struct TransportThread { sender: SyncSender, shutdown: Arc, @@ -25,6 +26,7 @@ pub struct TransportThread { } impl TransportThread { + /// Spawn a new background thread. pub fn new(mut send: SendFn) -> Self where SendFn: FnMut(Envelope, RateLimiter) -> SendFuture + Send + 'static, @@ -89,6 +91,9 @@ impl TransportThread { } } + /// Send an [`Envelope`]. + /// + /// In case the background thread cannot keep up, the [`Envelope`] is dropped. pub fn send(&self, envelope: Envelope) { // Using send here would mean that when the channel fills up for whatever // reason, trying to send an envelope would block everything. We'd rather @@ -98,6 +103,9 @@ impl TransportThread { } } + /// Flush all pending [`Envelope`]s. + /// + /// Returns true if successful within given timeout. pub fn flush(&self, timeout: Duration) -> bool { let (sender, receiver) = sync_channel(1); let _ = self.sender.send(Task::Flush(sender)); From fbca4319724c10fe3b5a0cb3381cf81aaec97171 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 9 Dec 2025 14:46:09 +1100 Subject: [PATCH 2/2] docs: add changelog entry --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 361d466c..869f12d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Features + +- Expose transport utilities ([#949](https://github.com/getsentry/sentry-rust/pull/949)) + ## 0.46.0 ### Breaking changes