1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
use std::borrow::Cow;
use std::fmt;
use std::sync::Arc;
use std::time::Duration;
use crate::constants::USER_AGENT;
use crate::protocol::{Breadcrumb, Event};
use crate::types::Dsn;
use crate::{Integration, IntoDsn, TransportFactory};
pub type BeforeCallback<T> = Arc<dyn Fn(T) -> Option<T> + Send + Sync>;
#[derive(Clone)]
pub struct ClientOptions {
pub dsn: Option<Dsn>,
pub debug: bool,
pub release: Option<Cow<'static, str>>,
pub environment: Option<Cow<'static, str>>,
pub sample_rate: f32,
pub max_breadcrumbs: usize,
pub attach_stacktrace: bool,
pub send_default_pii: bool,
pub server_name: Option<Cow<'static, str>>,
pub in_app_include: Vec<&'static str>,
pub in_app_exclude: Vec<&'static str>,
pub integrations: Vec<Arc<dyn Integration>>,
pub default_integrations: bool,
pub before_send: Option<BeforeCallback<Event<'static>>>,
pub before_breadcrumb: Option<BeforeCallback<Breadcrumb>>,
pub transport: Option<Arc<dyn TransportFactory>>,
pub http_proxy: Option<Cow<'static, str>>,
pub https_proxy: Option<Cow<'static, str>>,
pub shutdown_timeout: Duration,
pub extra_border_frames: Vec<&'static str>,
pub trim_backtraces: bool,
pub user_agent: Cow<'static, str>,
}
impl ClientOptions {
pub fn new() -> Self {
Self::default()
}
pub fn add_integration<I: Integration>(mut self, integration: I) -> Self {
self.integrations.push(Arc::new(integration));
self
}
}
impl fmt::Debug for ClientOptions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[derive(Debug)]
struct BeforeSend;
let before_send = self.before_send.as_ref().map(|_| BeforeSend);
#[derive(Debug)]
struct BeforeBreadcrumb;
let before_breadcrumb = self.before_breadcrumb.as_ref().map(|_| BeforeBreadcrumb);
#[derive(Debug)]
struct TransportFactory;
let integrations: Vec<_> = self.integrations.iter().map(|i| i.name()).collect();
f.debug_struct("ClientOptions")
.field("dsn", &self.dsn)
.field("debug", &self.debug)
.field("release", &self.release)
.field("environment", &self.environment)
.field("sample_rate", &self.sample_rate)
.field("max_breadcrumbs", &self.max_breadcrumbs)
.field("attach_stacktrace", &self.attach_stacktrace)
.field("send_default_pii", &self.send_default_pii)
.field("server_name", &self.server_name)
.field("in_app_include", &self.in_app_include)
.field("in_app_exclude", &self.in_app_exclude)
.field("integrations", &integrations)
.field("default_integrations", &self.default_integrations)
.field("before_send", &before_send)
.field("before_breadcrumb", &before_breadcrumb)
.field("transport", &TransportFactory)
.field("http_proxy", &self.http_proxy)
.field("https_proxy", &self.https_proxy)
.field("shutdown_timeout", &self.shutdown_timeout)
.field("extra_border_frames", &self.extra_border_frames)
.field("trim_backtraces", &self.trim_backtraces)
.field("user_agent", &self.user_agent)
.finish()
}
}
impl Default for ClientOptions {
fn default() -> ClientOptions {
ClientOptions {
dsn: None,
debug: false,
release: None,
environment: None,
sample_rate: 1.0,
max_breadcrumbs: 100,
attach_stacktrace: false,
send_default_pii: false,
server_name: None,
in_app_include: vec![],
in_app_exclude: vec![],
integrations: vec![],
default_integrations: true,
before_send: None,
before_breadcrumb: None,
transport: None,
http_proxy: None,
https_proxy: None,
shutdown_timeout: Duration::from_secs(2),
extra_border_frames: vec![],
trim_backtraces: true,
user_agent: Cow::Borrowed(&USER_AGENT),
}
}
}
impl<T: IntoDsn> From<(T, ClientOptions)> for ClientOptions {
fn from((into_dsn, mut opts): (T, ClientOptions)) -> ClientOptions {
opts.dsn = into_dsn.into_dsn().expect("invalid value for DSN");
opts
}
}
impl<T: IntoDsn> From<T> for ClientOptions {
fn from(into_dsn: T) -> ClientOptions {
ClientOptions {
dsn: into_dsn.into_dsn().expect("invalid value for DSN"),
..ClientOptions::default()
}
}
}