Skip to content

Commit 74970ef

Browse files
committed
ops: make sentry sampling rates configurable
1 parent 9c4be5d commit 74970ef

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

objectstore-server/src/config.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ pub enum Storage {
3131
},
3232
}
3333

34+
#[derive(Debug, Clone, Deserialize, Serialize)]
35+
pub struct Sentry {
36+
pub dsn: String,
37+
pub sample_rate: Option<f32>,
38+
pub traces_sample_rate: Option<f32>,
39+
}
40+
3441
#[derive(Debug, Clone, Deserialize, Serialize)]
3542
pub struct Config {
3643
// server addr config
@@ -41,7 +48,7 @@ pub struct Config {
4148
pub long_term_storage: Storage,
4249

4350
// others
44-
pub sentry_dsn: Option<String>,
51+
pub sentry: Option<Sentry>,
4552
pub datadog_key: Option<String>,
4653
pub metric_tags: BTreeMap<String, String>,
4754
}
@@ -58,7 +65,7 @@ impl Default for Config {
5865
path: PathBuf::from("data"),
5966
},
6067

61-
sentry_dsn: None,
68+
sentry: None,
6269
datadog_key: None,
6370
metric_tags: Default::default(),
6471
}
@@ -106,6 +113,9 @@ mod tests {
106113
jail.set_env("fss_long_term_storage__bucket", "whatever");
107114
jail.set_env("fss_metric_tags__foo", "bar");
108115
jail.set_env("fss_metric_tags__baz", "qux");
116+
jail.set_env("fss_sentry__dsn", "abcde");
117+
jail.set_env("fss_sentry__sample_rate", "0.5");
118+
jail.set_env("fss_sentry__traces_sample_rate", "0.5");
109119

110120
let config = Config::from_args(Args::default()).unwrap();
111121

@@ -120,6 +130,15 @@ mod tests {
120130
[("foo".into(), "bar".into()), ("baz".into(), "qux".into())].into()
121131
);
122132

133+
let Sentry {
134+
dsn,
135+
sample_rate,
136+
traces_sample_rate,
137+
} = &dbg!(&config).sentry.as_ref().unwrap();
138+
assert_eq!(dsn, "abcde");
139+
assert_eq!(sample_rate, &Some(0.5));
140+
assert_eq!(traces_sample_rate, &Some(0.5));
141+
123142
Ok(())
124143
});
125144
}
@@ -134,6 +153,10 @@ mod tests {
134153
type: s3compatible
135154
endpoint: http://localhost:8888
136155
bucket: whatever
156+
sentry:
157+
dsn: abcde
158+
sample_rate: 0.5
159+
traces_sample_rate: 0.5
137160
"#,
138161
)
139162
.unwrap();
@@ -143,10 +166,19 @@ mod tests {
143166
};
144167
let config = Config::from_args(args).unwrap();
145168

146-
let Storage::S3Compatible { endpoint, bucket } = dbg!(config).long_term_storage else {
169+
let Storage::S3Compatible { endpoint, bucket } = &dbg!(&config).long_term_storage else {
147170
panic!("expected s3 storage");
148171
};
149172
assert_eq!(endpoint, "http://localhost:8888");
150173
assert_eq!(bucket, "whatever");
174+
175+
let Sentry {
176+
dsn,
177+
sample_rate,
178+
traces_sample_rate,
179+
} = &dbg!(&config).sentry.as_ref().unwrap();
180+
assert_eq!(dsn, "abcde");
181+
assert_eq!(sample_rate, &Some(0.5));
182+
assert_eq!(traces_sample_rate, &Some(0.5));
151183
}
152184
}

objectstore-server/src/observability.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ pub fn maybe_initialize_metrics(config: &Config) -> std::io::Result<Option<merni
2222
}
2323

2424
pub fn maybe_initialize_sentry(config: &Config) -> Option<sentry::ClientInitGuard> {
25-
config.sentry_dsn.as_ref().map(|sentry_dsn| {
25+
config.sentry.as_ref().map(|sentry_config| {
2626
sentry::init(sentry::ClientOptions {
27-
dsn: sentry_dsn.parse().ok(),
27+
dsn: sentry_config.dsn.parse().ok(),
2828
enable_logs: true,
29-
sample_rate: 1.0,
30-
traces_sample_rate: 1.0,
29+
sample_rate: sentry_config.sample_rate.unwrap_or(1.0),
30+
traces_sample_rate: sentry_config.traces_sample_rate.unwrap_or(0.01),
3131
..Default::default()
3232
})
3333
})
@@ -36,7 +36,7 @@ pub fn maybe_initialize_sentry(config: &Config) -> Option<sentry::ClientInitGuar
3636
pub fn initialize_tracing(config: &Config) {
3737
// Same as the default filter, except it converts warnings into events
3838
// and also sends everything at or above INFO as logs instead of breadcrumbs.
39-
let sentry_layer = config.sentry_dsn.as_ref().map(|_| {
39+
let sentry_layer = config.sentry.as_ref().map(|_| {
4040
sentry_tracing::layer().event_filter(|metadata| match *metadata.level() {
4141
Level::ERROR | Level::WARN => {
4242
sentry_tracing::EventFilter::Event | sentry_tracing::EventFilter::Log

0 commit comments

Comments
 (0)