Skip to content

Commit fa5133f

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

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

objectstore-server/src/config.rs

Lines changed: 9 additions & 2 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
}

objectstore-server/src/observability.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::env;
22

33
use sentry::integrations::tracing as sentry_tracing;
4-
use tracing::Level;
54
use tracing::level_filters::LevelFilter;
6-
use tracing_subscriber::{EnvFilter, prelude::*};
5+
use tracing::Level;
6+
use tracing_subscriber::{prelude::*, EnvFilter};
77

88
use crate::config::Config;
99

@@ -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)