Skip to main content

sentry_core/
clientoptions.rs

1use std::borrow::Cow;
2use std::fmt;
3use std::sync::Arc;
4use std::time::Duration;
5
6use crate::constants::USER_AGENT;
7use crate::performance::{TracesSampler, TransactionContext};
8use crate::protocol::{Breadcrumb, Event, Log, Metric};
9use crate::types::Dsn;
10use crate::{Integration, IntoDsn, TransportFactory};
11
12/// Type alias for before event/breadcrumb handlers.
13pub type BeforeCallback<T> = Arc<dyn Fn(T) -> Option<T> + Send + Sync>;
14
15/// The Session Mode of the SDK.
16///
17/// Depending on the use-case, the SDK can be set to two different session modes:
18///
19/// * **Application Mode Sessions**:
20///   This mode should be used for user-attended programs, which typically have
21///   a single long running session that span the applications' lifetime.
22///
23/// * **Request Mode Sessions**:
24///   This mode is intended for servers that use one session per incoming
25///   request, and thus have a lot of very short lived sessions.
26///
27/// Setting the SDK to *request-mode* sessions means that session durations will
28/// not be tracked, and sessions will be pre-aggregated before being sent upstream.
29/// This applies both to automatic and manually triggered sessions.
30///
31/// **NOTE**: Support for *request-mode* sessions was added in Sentry `21.2`.
32///
33/// See the
34/// [Documentation on Session Modes](https://develop.sentry.dev/sdk/sessions/#sdk-considerations)
35/// for more information.
36///
37/// **NOTE**: The `release-health` feature (enabled by default) needs to be enabled for this
38/// option to have any effect.
39#[derive(Copy, Clone, Debug, PartialEq, Eq)]
40pub enum SessionMode {
41    /// Long running application session.
42    Application,
43    /// Lots of short per-request sessions.
44    Request,
45}
46
47/// The maximum size of an HTTP request body that the SDK captures.
48///
49/// Only request bodies that parse as JSON or form data are currently captured.
50/// See the Sentry documentation on [attaching request bodies] and [handling sensitive data] for
51/// more information.
52///
53/// [attaching request bodies]: https://develop.sentry.dev/sdk/expected-features/#attaching-request-body-in-server-sdks
54/// [handling sensitive data]: https://develop.sentry.dev/sdk/expected-features/data-handling/#sensitive-data
55#[derive(Clone, Copy, PartialEq)]
56pub enum MaxRequestBodySize {
57    /// Don't capture request body
58    None,
59    /// Capture up to 1000 bytes
60    Small,
61    /// Capture up to 10000 bytes
62    Medium,
63    /// Capture entire body
64    Always,
65    /// Capture up to a specific size
66    Explicit(usize),
67}
68
69impl MaxRequestBodySize {
70    /// Check if the content length is within the size limit.
71    pub fn is_within_size_limit(&self, content_length: usize) -> bool {
72        match self {
73            MaxRequestBodySize::None => false,
74            MaxRequestBodySize::Small => content_length <= 1_000,
75            MaxRequestBodySize::Medium => content_length <= 10_000,
76            MaxRequestBodySize::Always => true,
77            MaxRequestBodySize::Explicit(size) => content_length <= *size,
78        }
79    }
80}
81
82/// Configuration settings for the client.
83///
84/// These options are explained in more detail in the general
85/// [sentry documentation](https://docs.sentry.io/error-reporting/configuration/?platform=rust).
86///
87/// # Examples
88///
89/// ```
90/// let _options = sentry::ClientOptions::new().debug(true);
91/// ```
92#[derive(Clone)]
93#[must_use = "ClientOptions must be passed to sentry::init to have any effect"]
94pub struct ClientOptions {
95    // Common options
96    /// The DSN to use.
97    ///
98    /// See [`dsn`](method@ClientOptions::dsn) for details.
99    pub dsn: Option<Dsn>,
100    /// Enables debug mode.
101    ///
102    /// See [`debug`](method@ClientOptions::debug) for details.
103    pub debug: bool,
104    /// The release to be sent with events.
105    ///
106    /// See [`release`](method@ClientOptions::release) for details.
107    pub release: Option<Cow<'static, str>>,
108    /// The environment to be sent with events.
109    ///
110    /// See [`environment`](method@ClientOptions::environment) for details.
111    pub environment: Option<Cow<'static, str>>,
112    /// The sample rate for event submission.
113    ///
114    /// See [`sample_rate`](method@ClientOptions::sample_rate) for details.
115    pub sample_rate: f32,
116    /// The sample rate for tracing transactions.
117    ///
118    /// See [`traces_sample_rate`](method@ClientOptions::traces_sample_rate) for details.
119    pub traces_sample_rate: f32,
120    /// The sampler callback for tracing transactions.
121    ///
122    /// See [`traces_sampler`](method@ClientOptions::traces_sampler) for details.
123    pub traces_sampler: Option<Arc<TracesSampler>>,
124    /// Maximum number of breadcrumbs.
125    ///
126    /// See [`max_breadcrumbs`](method@ClientOptions::max_breadcrumbs) for details.
127    pub max_breadcrumbs: usize,
128    /// Attaches stacktraces to messages.
129    ///
130    /// See [`attach_stacktrace`](method@ClientOptions::attach_stacktrace) for details.
131    pub attach_stacktrace: bool,
132    /// Whether to send default PII.
133    ///
134    /// See [`send_default_pii`](method@ClientOptions::send_default_pii) for details.
135    pub send_default_pii: bool,
136    /// The server name to be reported.
137    ///
138    /// See [`server_name`](method@ClientOptions::server_name) for details.
139    pub server_name: Option<Cow<'static, str>>,
140    /// Module prefixes that are always considered "in_app".
141    ///
142    /// See [`in_app_include`](method@ClientOptions::in_app_include) for details.
143    pub in_app_include: Vec<&'static str>,
144    /// Module prefixes that are never "in_app".
145    ///
146    /// See [`in_app_exclude`](method@ClientOptions::in_app_exclude) for details.
147    pub in_app_exclude: Vec<&'static str>,
148    // Integration options
149    /// A list of integrations to enable.
150    ///
151    /// See [`integrations`](method@ClientOptions::integrations) and
152    /// [`add_integration`](method@ClientOptions::add_integration) for details.
153    pub integrations: Vec<Arc<dyn Integration>>,
154    /// Whether to add default integrations.
155    ///
156    /// See [`default_integrations`](method@ClientOptions::default_integrations) for details.
157    pub default_integrations: bool,
158    // Hooks
159    /// Callback that is executed before event sending.
160    ///
161    /// See [`before_send`](method@ClientOptions::before_send) for details.
162    pub before_send: Option<BeforeCallback<Event<'static>>>,
163    /// Callback that is executed for each Breadcrumb being added.
164    ///
165    /// See [`before_breadcrumb`](method@ClientOptions::before_breadcrumb) for details.
166    pub before_breadcrumb: Option<BeforeCallback<Breadcrumb>>,
167    /// Callback that is executed for each Log being added.
168    ///
169    /// See [`before_send_log`](method@ClientOptions::before_send_log) for details.
170    pub before_send_log: Option<BeforeCallback<Log>>,
171    // Transport options
172    /// The transport to use.
173    ///
174    /// See [`transport`](method@ClientOptions::transport) for details.
175    pub transport: Option<Arc<dyn TransportFactory>>,
176    /// An optional HTTP proxy to use.
177    ///
178    /// See [`http_proxy`](method@ClientOptions::http_proxy) for details.
179    pub http_proxy: Option<Cow<'static, str>>,
180    /// An optional HTTPS proxy to use.
181    ///
182    /// See [`https_proxy`](method@ClientOptions::https_proxy) for details.
183    pub https_proxy: Option<Cow<'static, str>>,
184    /// The timeout on client drop for draining events on shutdown.
185    ///
186    /// See [`shutdown_timeout`](method@ClientOptions::shutdown_timeout) for details.
187    pub shutdown_timeout: Duration,
188    /// The maximum size of an HTTP request body to capture.
189    ///
190    /// See [`max_request_body_size`](method@ClientOptions::max_request_body_size) for details.
191    pub max_request_body_size: MaxRequestBodySize,
192    /// Whether captured structured logs should be sent to Sentry.
193    ///
194    /// See [`enable_logs`](method@ClientOptions::enable_logs) for details.
195    pub enable_logs: bool,
196    /// Whether metric capture APIs should capture metrics.
197    ///
198    /// See [`enable_metrics`](method@ClientOptions::enable_metrics) for details.
199    pub enable_metrics: bool,
200    /// Callback that is executed for each [`Metric`] before sending.
201    ///
202    /// See [`before_send_metric`](method@ClientOptions::before_send_metric) for details.
203    pub before_send_metric: Option<BeforeCallback<Metric>>,
204    // Other options not documented in Unified API
205    /// Whether to disable SSL verification.
206    ///
207    /// See [`accept_invalid_certs`](method@ClientOptions::accept_invalid_certs) for details.
208    pub accept_invalid_certs: bool,
209    /// Whether Release Health Session tracking is enabled.
210    ///
211    /// See [`auto_session_tracking`](method@ClientOptions::auto_session_tracking) for details.
212    pub auto_session_tracking: bool,
213    /// Determine how Sessions are being tracked.
214    ///
215    /// See [`session_mode`](method@ClientOptions::session_mode) for details.
216    pub session_mode: SessionMode,
217    /// The user agent that should be reported.
218    ///
219    /// See [`user_agent`](method@ClientOptions::user_agent) for details.
220    pub user_agent: Cow<'static, str>,
221}
222
223impl ClientOptions {
224    /// Creates new Options.
225    #[inline]
226    pub fn new() -> Self {
227        Self::default()
228    }
229
230    /// Sets the [DSN](field@ClientOptions::dsn) to use.
231    ///
232    /// # Panics
233    ///
234    /// Panics if the value fails to parse as a [DSN](`Dsn`).
235    #[inline]
236    pub fn dsn(self, dsn: &str) -> Self {
237        let dsn = Some(dsn.parse().expect("invalid value for DSN"));
238        Self { dsn, ..self }
239    }
240
241    /// Enables or disables [debug mode](field@ClientOptions::debug).
242    ///
243    /// In debug mode debug information is printed to stderr to help you understand what sentry is
244    /// doing. Defaults to `false`.
245    #[inline]
246    pub fn debug(self, debug: bool) -> Self {
247        Self { debug, ..self }
248    }
249
250    /// Sets the [release](field@ClientOptions::release) to be sent with events.
251    #[inline]
252    pub fn release<T>(self, release: T) -> Self
253    where
254        T: Into<Cow<'static, str>>,
255    {
256        let release = Some(release.into());
257        Self { release, ..self }
258    }
259
260    /// Sets the [release](field@ClientOptions::release) to be sent with events if one is provided.
261    ///
262    /// Use this with [`release_name!`](crate::release_name), which returns the release as an
263    /// `Option`.
264    #[inline]
265    pub fn maybe_release<T>(self, release: Option<T>) -> Self
266    where
267        T: Into<Cow<'static, str>>,
268    {
269        match release {
270            Some(release) => self.release(release),
271            None => self,
272        }
273    }
274
275    /// Sets the [environment](field@ClientOptions::environment) to be sent with events.
276    ///
277    /// Defaults to either `"development"` or `"production"` depending on the `debug_assertions`
278    /// cfg-attribute.
279    #[inline]
280    pub fn environment<T>(self, environment: T) -> Self
281    where
282        T: Into<Cow<'static, str>>,
283    {
284        let environment = Some(environment.into());
285        Self {
286            environment,
287            ..self
288        }
289    }
290
291    /// Sets the [sample rate](field@ClientOptions::sample_rate) for event submission.
292    ///
293    /// Must be between `0.0` and `1.0`. Defaults to `1.0`.
294    ///
295    /// # Panics
296    ///
297    /// Panics if the `sample_rate` is outside the allowed range.
298    #[inline]
299    pub fn sample_rate(self, sample_rate: f32) -> Self {
300        if !(0.0..=1.0).contains(&sample_rate) {
301            panic!("Sample rate {sample_rate} is outside the allowed range [0.0, 1.0].")
302        }
303
304        Self {
305            sample_rate,
306            ..self
307        }
308    }
309
310    /// Sets the [sample rate](field@ClientOptions::traces_sample_rate) for tracing transactions.
311    ///
312    /// Must be between `0.0` and `1.0`. Defaults to `0.0`.
313    ///
314    /// # Panics
315    ///
316    /// Panics if the `traces_sample_rate` is outside the allowed range.
317    #[inline]
318    pub fn traces_sample_rate(self, traces_sample_rate: f32) -> Self {
319        if !(0.0..=1.0).contains(&traces_sample_rate) {
320            panic!(
321                "Traces sample rate {traces_sample_rate} is outside the allowed range [0.0, 1.0]."
322            )
323        }
324
325        Self {
326            traces_sample_rate,
327            ..self
328        }
329    }
330
331    /// Sets the [sampler callback](field@ClientOptions::traces_sampler) for tracing transactions.
332    ///
333    /// Return a sample rate between `0.0` and `1.0` for the transaction in question. Takes
334    /// priority over [`traces_sample_rate`](method@ClientOptions::traces_sample_rate).
335    #[inline]
336    pub fn traces_sampler<F>(self, traces_sampler: F) -> Self
337    where
338        F: Fn(&TransactionContext) -> f32 + Send + Sync + 'static,
339    {
340        let traces_sampler = Some(Arc::new(traces_sampler) as Arc<TracesSampler>);
341        Self {
342            traces_sampler,
343            ..self
344        }
345    }
346
347    /// Sets the [maximum number of breadcrumbs](field@ClientOptions::max_breadcrumbs).
348    ///
349    /// Defaults to `100`.
350    #[inline]
351    pub fn max_breadcrumbs(self, max_breadcrumbs: usize) -> Self {
352        Self {
353            max_breadcrumbs,
354            ..self
355        }
356    }
357
358    /// Enables or disables [attaching stacktraces](field@ClientOptions::attach_stacktrace) to
359    /// messages.
360    ///
361    /// Defaults to `false`.
362    #[inline]
363    pub fn attach_stacktrace(self, attach_stacktrace: bool) -> Self {
364        Self {
365            attach_stacktrace,
366            ..self
367        }
368    }
369
370    /// Enables or disables sending [default PII](field@ClientOptions::send_default_pii).
371    ///
372    /// This includes information such as potentially sensitive HTTP headers and user IP addresses
373    /// in HTTP server integrations. Defaults to `false`.
374    #[inline]
375    pub fn send_default_pii(self, send_default_pii: bool) -> Self {
376        Self {
377            send_default_pii,
378            ..self
379        }
380    }
381
382    /// Sets the [server name](field@ClientOptions::server_name) to be reported.
383    #[inline]
384    pub fn server_name<T>(self, server_name: T) -> Self
385    where
386        T: Into<Cow<'static, str>>,
387    {
388        let server_name = Some(server_name.into());
389        Self {
390            server_name,
391            ..self
392        }
393    }
394
395    /// Sets [module prefixes](field@ClientOptions::in_app_include) that are always considered
396    /// in-app.
397    #[inline]
398    pub fn in_app_include<I>(self, in_app_include: I) -> Self
399    where
400        I: IntoIterator<Item = &'static str>,
401    {
402        let in_app_include = in_app_include.into_iter().collect();
403        Self {
404            in_app_include,
405            ..self
406        }
407    }
408
409    /// Sets [module prefixes](field@ClientOptions::in_app_exclude) that are never considered
410    /// in-app.
411    #[inline]
412    pub fn in_app_exclude<I>(self, in_app_exclude: I) -> Self
413    where
414        I: IntoIterator<Item = &'static str>,
415    {
416        let in_app_exclude = in_app_exclude.into_iter().collect();
417        Self {
418            in_app_exclude,
419            ..self
420        }
421    }
422
423    /// Sets the [integrations](field@ClientOptions::integrations) to enable, replacing the
424    /// existing list.
425    ///
426    /// See [`sentry::integrations`](integrations/index.html#installing-integrations) for how to
427    /// use this to enable extra integrations. Use
428    /// [`add_integration`](method@ClientOptions::add_integration) to append.
429    #[inline]
430    pub fn integrations<I>(self, integrations: I) -> Self
431    where
432        I: IntoIterator<Item = Arc<dyn Integration>>,
433    {
434        let integrations = integrations.into_iter().collect();
435        Self {
436            integrations,
437            ..self
438        }
439    }
440
441    /// Enables or disables [default integrations](field@ClientOptions::default_integrations).
442    ///
443    /// See [`sentry::integrations`](integrations/index.html#default-integrations) for details.
444    /// Defaults to `true`.
445    #[inline]
446    pub fn default_integrations(self, default_integrations: bool) -> Self {
447        Self {
448            default_integrations,
449            ..self
450        }
451    }
452
453    /// Sets the [callback](field@ClientOptions::before_send) that is executed before event
454    /// sending.
455    #[inline]
456    pub fn before_send<F>(self, before_send: F) -> Self
457    where
458        F: Fn(Event<'static>) -> Option<Event<'static>> + Send + Sync + 'static,
459    {
460        let before_send = Some(Arc::new(before_send) as BeforeCallback<Event<'static>>);
461        Self {
462            before_send,
463            ..self
464        }
465    }
466
467    /// Sets the [callback](field@ClientOptions::before_breadcrumb) that is executed before adding
468    /// each breadcrumb.
469    #[inline]
470    pub fn before_breadcrumb<F>(self, before_breadcrumb: F) -> Self
471    where
472        F: Fn(Breadcrumb) -> Option<Breadcrumb> + Send + Sync + 'static,
473    {
474        let before_breadcrumb = Some(Arc::new(before_breadcrumb) as BeforeCallback<Breadcrumb>);
475        Self {
476            before_breadcrumb,
477            ..self
478        }
479    }
480
481    /// Sets the [callback](field@ClientOptions::before_send_log) that is executed before sending
482    /// each log.
483    #[cfg(feature = "logs")]
484    #[inline]
485    pub fn before_send_log<F>(self, before_send_log: F) -> Self
486    where
487        F: Fn(Log) -> Option<Log> + Send + Sync + 'static,
488    {
489        let before_send_log = Some(Arc::new(before_send_log) as BeforeCallback<Log>);
490        Self {
491            before_send_log,
492            ..self
493        }
494    }
495
496    /// Sets the [callback](field@ClientOptions::before_send_metric) that is executed before
497    /// sending each metric.
498    ///
499    /// This callback can modify a metric or return `None` to drop it.
500    #[cfg(feature = "metrics")]
501    #[inline]
502    pub fn before_send_metric<F>(self, before_send_metric: F) -> Self
503    where
504        F: Fn(Metric) -> Option<Metric> + Send + Sync + 'static,
505    {
506        let before_send_metric = Some(Arc::new(before_send_metric) as BeforeCallback<Metric>);
507        Self {
508            before_send_metric,
509            ..self
510        }
511    }
512
513    /// Sets the [transport](field@ClientOptions::transport) to use.
514    ///
515    /// This is typically either a function taking the client options by reference and returning a
516    /// transport, an `Arc<Transport>`, or the `DefaultTransportFactory`. Types that do not
517    /// implement [`TransportFactory`] use direct field assignment.
518    #[inline]
519    pub fn transport<T: TransportFactory + 'static>(self, transport: T) -> Self {
520        let transport = Some(Arc::new(transport) as Arc<dyn TransportFactory>);
521        Self { transport, ..self }
522    }
523
524    /// Sets the optional [HTTP proxy](field@ClientOptions::http_proxy) to use.
525    ///
526    /// This defaults to the `http_proxy` environment variable.
527    #[inline]
528    pub fn http_proxy<T>(self, http_proxy: T) -> Self
529    where
530        T: Into<Cow<'static, str>>,
531    {
532        let http_proxy = Some(http_proxy.into());
533        Self { http_proxy, ..self }
534    }
535
536    /// Sets the optional [HTTPS proxy](field@ClientOptions::https_proxy) to use.
537    ///
538    /// This defaults to the `HTTPS_PROXY` environment variable, or `http_proxy` if that one
539    /// exists.
540    #[inline]
541    pub fn https_proxy<T>(self, https_proxy: T) -> Self
542    where
543        T: Into<Cow<'static, str>>,
544    {
545        let https_proxy = Some(https_proxy.into());
546        Self {
547            https_proxy,
548            ..self
549        }
550    }
551
552    /// Sets the [shutdown drain timeout](field@ClientOptions::shutdown_timeout).
553    ///
554    /// Defaults to 2 seconds.
555    #[inline]
556    pub fn shutdown_timeout(self, shutdown_timeout: Duration) -> Self {
557        Self {
558            shutdown_timeout,
559            ..self
560        }
561    }
562
563    /// Sets the [maximum request body size](field@ClientOptions::max_request_body_size) to
564    /// capture.
565    ///
566    /// Controls the maximum size of an HTTP request body that can be captured when using HTTP
567    /// server integrations. Needs [`send_default_pii`](method@ClientOptions::send_default_pii) to
568    /// be enabled to have any effect. Defaults to [`MaxRequestBodySize::Medium`].
569    #[inline]
570    pub fn max_request_body_size(self, max_request_body_size: MaxRequestBodySize) -> Self {
571        Self {
572            max_request_body_size,
573            ..self
574        }
575    }
576
577    /// Enables or disables sending [structured logs](field@ClientOptions::enable_logs).
578    ///
579    /// The `logs` feature is required to capture logs. Defaults to `true`.
580    #[inline]
581    pub fn enable_logs(self, enable_logs: bool) -> Self {
582        Self {
583            enable_logs,
584            ..self
585        }
586    }
587
588    /// Enables or disables [metric capture APIs](field@ClientOptions::enable_metrics).
589    ///
590    /// The `metrics` feature is required to capture metrics. Defaults to `true`.
591    #[inline]
592    pub fn enable_metrics(self, enable_metrics: bool) -> Self {
593        Self {
594            enable_metrics,
595            ..self
596        }
597    }
598
599    /// Enables or disables
600    /// [accepting invalid TLS certificates](field@ClientOptions::accept_invalid_certs).
601    ///
602    /// This introduces significant vulnerabilities, and should only be used as a last resort.
603    /// Defaults to `false`.
604    #[inline]
605    pub fn accept_invalid_certs(self, accept_invalid_certs: bool) -> Self {
606        Self {
607            accept_invalid_certs,
608            ..self
609        }
610    }
611
612    /// Enables or disables
613    /// [automatic session tracking](field@ClientOptions::auto_session_tracking).
614    ///
615    /// When enabled, a new "user-mode" session is started at `sentry::init` and persists for the
616    /// application lifetime. Defaults to `false`.
617    #[cfg(feature = "release-health")]
618    #[inline]
619    pub fn auto_session_tracking(self, auto_session_tracking: bool) -> Self {
620        Self {
621            auto_session_tracking,
622            ..self
623        }
624    }
625
626    /// Sets how [sessions are tracked](field@ClientOptions::session_mode).
627    ///
628    /// See [`SessionMode`] for the available modes. Defaults to [`SessionMode::Application`].
629    #[cfg(feature = "release-health")]
630    #[inline]
631    pub fn session_mode(self, session_mode: SessionMode) -> Self {
632        Self {
633            session_mode,
634            ..self
635        }
636    }
637
638    /// Sets the [user agent](field@ClientOptions::user_agent) that should be reported.
639    ///
640    /// Defaults to the SDK user agent.
641    #[inline]
642    pub fn user_agent<T>(self, user_agent: T) -> Self
643    where
644        T: Into<Cow<'static, str>>,
645    {
646        let user_agent = user_agent.into();
647        Self { user_agent, ..self }
648    }
649
650    /// Adds a configured integration to the options.
651    ///
652    /// # Examples
653    ///
654    /// ```
655    /// struct MyIntegration;
656    ///
657    /// impl sentry::Integration for MyIntegration {}
658    ///
659    /// let options = sentry::ClientOptions::new().add_integration(MyIntegration);
660    /// assert_eq!(options.integrations.len(), 1);
661    /// ```
662    #[inline]
663    pub fn add_integration<I: Integration>(mut self, integration: I) -> Self {
664        self.integrations.push(Arc::new(integration));
665        self
666    }
667}
668impl fmt::Debug for ClientOptions {
669    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
670        #[derive(Debug)]
671        struct BeforeSend;
672        let before_send = self.before_send.as_ref().map(|_| BeforeSend);
673        #[derive(Debug)]
674        struct BeforeBreadcrumb;
675        let before_breadcrumb = self.before_breadcrumb.as_ref().map(|_| BeforeBreadcrumb);
676        let before_send_log = {
677            #[derive(Debug)]
678            struct BeforeSendLog;
679            self.before_send_log.as_ref().map(|_| BeforeSendLog)
680        };
681        let before_send_metric = {
682            #[derive(Debug)]
683            struct BeforeSendMetric;
684            self.before_send_metric.as_ref().map(|_| BeforeSendMetric)
685        };
686        #[derive(Debug)]
687        struct TransportFactory;
688
689        let integrations: Vec<_> = self.integrations.iter().map(|i| i.name()).collect();
690
691        let mut debug_struct = f.debug_struct("ClientOptions");
692        debug_struct
693            .field("dsn", &self.dsn)
694            .field("debug", &self.debug)
695            .field("release", &self.release)
696            .field("environment", &self.environment)
697            .field("sample_rate", &self.sample_rate)
698            .field("traces_sample_rate", &self.traces_sample_rate)
699            .field(
700                "traces_sampler",
701                &self
702                    .traces_sampler
703                    .as_ref()
704                    .map(|arc| std::ptr::addr_of!(**arc)),
705            )
706            .field("max_breadcrumbs", &self.max_breadcrumbs)
707            .field("attach_stacktrace", &self.attach_stacktrace)
708            .field("send_default_pii", &self.send_default_pii)
709            .field("server_name", &self.server_name)
710            .field("in_app_include", &self.in_app_include)
711            .field("in_app_exclude", &self.in_app_exclude)
712            .field("integrations", &integrations)
713            .field("default_integrations", &self.default_integrations)
714            .field("before_send", &before_send)
715            .field("before_breadcrumb", &before_breadcrumb)
716            .field("transport", &TransportFactory)
717            .field("http_proxy", &self.http_proxy)
718            .field("https_proxy", &self.https_proxy)
719            .field("shutdown_timeout", &self.shutdown_timeout)
720            .field("accept_invalid_certs", &self.accept_invalid_certs)
721            .field("auto_session_tracking", &self.auto_session_tracking)
722            .field("session_mode", &self.session_mode)
723            .field("enable_logs", &self.enable_logs)
724            .field("before_send_log", &before_send_log)
725            .field("enable_metrics", &self.enable_metrics)
726            .field("before_send_metric", &before_send_metric)
727            .field("user_agent", &self.user_agent)
728            .finish()
729    }
730}
731
732impl Default for ClientOptions {
733    fn default() -> ClientOptions {
734        ClientOptions {
735            dsn: None,
736            debug: false,
737            release: None,
738            environment: None,
739            sample_rate: 1.0,
740            traces_sample_rate: 0.0,
741            traces_sampler: None,
742            max_breadcrumbs: 100,
743            attach_stacktrace: false,
744            send_default_pii: false,
745            server_name: None,
746            in_app_include: vec![],
747            in_app_exclude: vec![],
748            integrations: vec![],
749            default_integrations: true,
750            before_send: None,
751            before_breadcrumb: None,
752            transport: None,
753            http_proxy: None,
754            https_proxy: None,
755            shutdown_timeout: Duration::from_secs(2),
756            accept_invalid_certs: false,
757            auto_session_tracking: false,
758            session_mode: SessionMode::Application,
759            user_agent: Cow::Borrowed(USER_AGENT),
760            max_request_body_size: MaxRequestBodySize::Medium,
761            enable_logs: true,
762            before_send_log: None,
763            enable_metrics: true,
764            before_send_metric: None,
765        }
766    }
767}
768
769impl<T: IntoDsn> From<(T, ClientOptions)> for ClientOptions {
770    fn from((into_dsn, mut opts): (T, ClientOptions)) -> ClientOptions {
771        opts.dsn = into_dsn.into_dsn().expect("invalid value for DSN");
772        opts
773    }
774}
775
776impl<T: IntoDsn> From<T> for ClientOptions {
777    fn from(into_dsn: T) -> ClientOptions {
778        ClientOptions {
779            dsn: into_dsn.into_dsn().expect("invalid value for DSN"),
780            ..ClientOptions::default()
781        }
782    }
783}