Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sentry-core/src/clientoptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -328,6 +334,7 @@ impl Default for ClientOptions {
enable_logs: true,
#[cfg(feature = "logs")]
before_send_log: None,
transport_channel_capacity: 30,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/transports/curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/transports/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions sentry/src/transports/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -25,11 +27,11 @@ pub struct TransportThread {
}

impl TransportThread {
pub fn new<SendFn>(mut send: SendFn) -> Self
pub fn new<SendFn>(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()
Expand Down
7 changes: 4 additions & 3 deletions sentry/src/transports/tokio_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -25,13 +27,12 @@ pub struct TransportThread {
}

impl TransportThread {
pub fn new<SendFn, SendFuture>(mut send: SendFn) -> Self
pub fn new<SendFn, SendFuture>(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<Output = RateLimiter>,
{
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()
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/transports/ureq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading