Skip to content

Commit 19b8e3c

Browse files
authored
feat(sentry): Add config for global tags (#211)
Add a config option to set global tags that will be added to all data that the Sentry SDK is using. We will use this to differentiate the deployments.
1 parent f3d0435 commit 19b8e3c

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

objectstore-server/src/config.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,31 @@ pub struct Sentry {
450450
///
451451
/// `OS__SENTRY__DEBUG`
452452
pub debug: bool,
453+
454+
/// Additional tags to attach to all Sentry events.
455+
///
456+
/// Key-value pairs that are sent as tags with every event reported to Sentry. Useful for adding
457+
/// context such as deployment identifiers or environment details.
458+
///
459+
/// # Default
460+
///
461+
/// Empty (no tags)
462+
///
463+
/// # Environment Variables
464+
///
465+
/// Each tag is set individually:
466+
/// - `OS__SENTRY__TAGS__FOO=foo`
467+
/// - `OS__SENTRY__TAGS__BAR=bar`
468+
///
469+
/// # YAML Example
470+
///
471+
/// ```yaml
472+
/// sentry:
473+
/// tags:
474+
/// foo: foo
475+
/// bar: bar
476+
/// ```
477+
pub tags: BTreeMap<String, String>,
453478
}
454479

455480
impl Sentry {
@@ -471,6 +496,7 @@ impl Default for Sentry {
471496
traces_sample_rate: 0.01,
472497
inherit_sampling_decision: true,
473498
debug: false,
499+
tags: BTreeMap::new(),
474500
}
475501
}
476502
}

objectstore-server/src/observability.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn init_sentry(config: &Config) -> Option<sentry::ClientInitGuard> {
2525
let config = &config.sentry;
2626
let dsn = config.dsn.as_ref()?;
2727

28-
Some(sentry::init(sentry::ClientOptions {
28+
let guard = sentry::init(sentry::ClientOptions {
2929
dsn: dsn.expose_secret().parse().ok(),
3030
release: Some(RELEASE.into()),
3131
environment: config.environment.clone(),
@@ -47,7 +47,15 @@ pub fn init_sentry(config: &Config) -> Option<sentry::ClientInitGuard> {
4747
enable_logs: true,
4848
debug: config.debug,
4949
..Default::default()
50-
}))
50+
});
51+
52+
sentry::configure_scope(|scope| {
53+
for (k, v) in &config.tags {
54+
scope.set_tag(k, v);
55+
}
56+
});
57+
58+
Some(guard)
5159
}
5260

5361
pub fn init_tracing(config: &Config) {

0 commit comments

Comments
 (0)