diff --git a/sentry-core/src/clientoptions.rs b/sentry-core/src/clientoptions.rs index 33b5bbd4..3aaaa237 100644 --- a/sentry-core/src/clientoptions.rs +++ b/sentry-core/src/clientoptions.rs @@ -196,6 +196,8 @@ pub struct ClientOptions { pub trim_backtraces: bool, /// The user agent that should be reported. pub user_agent: Cow<'static, str>, + /// The maximum number of envelopes that can be enqueued for sending in the transport channel (defaults to 30). + pub transport_channel_capacity: usize, } impl ClientOptions { @@ -287,6 +289,10 @@ impl fmt::Debug for ClientOptions { .field("extra_border_frames", &self.extra_border_frames) .field("trim_backtraces", &self.trim_backtraces) .field("user_agent", &self.user_agent) + .field( + "transport_channel_capacity", + &self.transport_channel_capacity, + ) .finish() } } @@ -328,6 +334,7 @@ impl Default for ClientOptions { enable_logs: true, #[cfg(feature = "logs")] before_send_log: None, + transport_channel_capacity: 30, } } } diff --git a/sentry/src/transports/curl.rs b/sentry/src/transports/curl.rs index 7cf5a2b4..7ba3b56e 100644 --- a/sentry/src/transports/curl.rs +++ b/sentry/src/transports/curl.rs @@ -38,7 +38,7 @@ impl CurlHttpTransport { let accept_invalid_certs = options.accept_invalid_certs; let mut handle = client; - let thread = TransportThread::new(move |envelope, rl| { + let thread = TransportThread::new(options, move |envelope, rl| { handle.reset(); handle.url(&url).unwrap(); handle.custom_request("POST").unwrap(); diff --git a/sentry/src/transports/reqwest.rs b/sentry/src/transports/reqwest.rs index 9e21364a..6db1f749 100644 --- a/sentry/src/transports/reqwest.rs +++ b/sentry/src/transports/reqwest.rs @@ -62,7 +62,7 @@ impl ReqwestHttpTransport { let auth = dsn.to_auth(Some(&user_agent)).to_string(); let url = dsn.envelope_api_url().to_string(); - let thread = TransportThread::new(move |envelope, mut rl| { + let thread = TransportThread::new(options, move |envelope, mut rl| { let mut body = Vec::new(); envelope.to_writer(&mut body).unwrap(); let request = client.post(&url).header("X-Sentry-Auth", &auth).body(body); diff --git a/sentry/src/transports/thread.rs b/sentry/src/transports/thread.rs index 6ccca6fa..9f842bdc 100644 --- a/sentry/src/transports/thread.rs +++ b/sentry/src/transports/thread.rs @@ -4,6 +4,8 @@ use std::sync::Arc; use std::thread::{self, JoinHandle}; use std::time::Duration; +use sentry_core::ClientOptions; + use super::ratelimit::{RateLimiter, RateLimitingCategory}; use crate::{sentry_debug, Envelope}; @@ -25,11 +27,11 @@ pub struct TransportThread { } impl TransportThread { - pub fn new(mut send: SendFn) -> Self + pub fn new(options: &ClientOptions, mut send: SendFn) -> Self where SendFn: FnMut(Envelope, &mut RateLimiter) + Send + 'static, { - let (sender, receiver) = sync_channel(30); + let (sender, receiver) = sync_channel(options.transport_channel_capacity); let shutdown = Arc::new(AtomicBool::new(false)); let shutdown_worker = shutdown.clone(); let handle = thread::Builder::new() diff --git a/sentry/src/transports/tokio_thread.rs b/sentry/src/transports/tokio_thread.rs index 5ef734e3..b2d8ef04 100644 --- a/sentry/src/transports/tokio_thread.rs +++ b/sentry/src/transports/tokio_thread.rs @@ -4,6 +4,8 @@ use std::sync::Arc; use std::thread::{self, JoinHandle}; use std::time::Duration; +use sentry_core::ClientOptions; + use super::ratelimit::{RateLimiter, RateLimitingCategory}; use crate::{sentry_debug, Envelope}; @@ -25,13 +27,12 @@ pub struct TransportThread { } impl TransportThread { - pub fn new(mut send: SendFn) -> Self + pub fn new(options: &ClientOptions, mut send: SendFn) -> Self where SendFn: FnMut(Envelope, RateLimiter) -> SendFuture + Send + 'static, - // NOTE: returning RateLimiter here, otherwise we are in borrow hell SendFuture: std::future::Future, { - let (sender, receiver) = sync_channel(30); + let (sender, receiver) = sync_channel(options.transport_channel_capacity); let shutdown = Arc::new(AtomicBool::new(false)); let shutdown_worker = shutdown.clone(); let handle = thread::Builder::new() diff --git a/sentry/src/transports/ureq.rs b/sentry/src/transports/ureq.rs index 9fa20fe4..938e4d14 100644 --- a/sentry/src/transports/ureq.rs +++ b/sentry/src/transports/ureq.rs @@ -83,7 +83,7 @@ impl UreqHttpTransport { let auth = dsn.to_auth(Some(&user_agent)).to_string(); let url = dsn.envelope_api_url().to_string(); - let thread = TransportThread::new(move |envelope, rl| { + let thread = TransportThread::new(options, move |envelope, rl| { let mut body = Vec::new(); envelope.to_writer(&mut body).unwrap(); let request = agent.post(&url).header("X-Sentry-Auth", &auth).send(&body);