From f07e9256acc7278374dabc3ec4023604de214493 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 28 Aug 2024 09:21:12 +0200 Subject: [PATCH] feat(metrics): Add platform tag (#1511) This adds a configurable platform tag to metrics. If this is set, the platform (read from the SYMBOLICATOR_PLATFORM env variable) will be reported with every metric. --- crates/symbolicator-service/src/config.rs | 6 ++++++ crates/symbolicator/src/cli.rs | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/crates/symbolicator-service/src/config.rs b/crates/symbolicator-service/src/config.rs index 4ad1d82eb..4952ca033 100644 --- a/crates/symbolicator-service/src/config.rs +++ b/crates/symbolicator-service/src/config.rs @@ -91,6 +91,11 @@ pub struct Metrics { pub hostname_tag: Option, /// A tag name to report the environment to, for each metric. Defaults to not sending such a tag. pub environment_tag: Option, + /// A tag name to report the platform to, for each metric. Defaults to not sending such a tag. + /// + /// If this is set, the platform will be read from the `SYMBOLICLATOR_PLATFORM` + /// environment variable. + pub platform_tag: Option, /// A map containing custom tags and their values. /// /// These tags will be appended to every metric. @@ -107,6 +112,7 @@ impl Default for Metrics { prefix: "symbolicator".into(), hostname_tag: None, environment_tag: None, + platform_tag: None, custom_tags: BTreeMap::new(), } } diff --git a/crates/symbolicator/src/cli.rs b/crates/symbolicator/src/cli.rs index 9550e4c83..bda3a4196 100644 --- a/crates/symbolicator/src/cli.rs +++ b/crates/symbolicator/src/cli.rs @@ -140,6 +140,20 @@ pub fn execute() -> Result<()> { } }; + if let Some(platform_tag) = config.metrics.platform_tag.clone() { + if tags.contains_key(&platform_tag) { + tracing::warn!( + "tag {} defined both as platform tag and as a custom tag", + platform_tag + ); + } + if let Ok(platform) = std::env::var("SYMBOLICATOR_PLATFORM") { + tags.insert(platform_tag, platform.to_string()); + } else { + tracing::error!("platform not available"); + } + }; + metrics::configure_statsd(&config.metrics.prefix, statsd, tags); }