From 7c0241d189939b8d7280938c277af928a16ae975 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Mon, 19 Aug 2024 11:14:30 +0200 Subject: [PATCH] feat(metrics): Add platform tag --- crates/symbolicator-service/src/config.rs | 3 +++ crates/symbolicator/src/cli.rs | 27 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/crates/symbolicator-service/src/config.rs b/crates/symbolicator-service/src/config.rs index 4ad1d82eb..c6d5da3aa 100644 --- a/crates/symbolicator-service/src/config.rs +++ b/crates/symbolicator-service/src/config.rs @@ -91,6 +91,8 @@ 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. + pub platform_tag: Option, /// A map containing custom tags and their values. /// /// These tags will be appended to every metric. @@ -107,6 +109,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..036abb950 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 Some(platform) = get_platform() { + tags.insert(platform_tag, platform.to_string()); + } else { + tracing::error!("platform not available"); + } + }; + metrics::configure_statsd(&config.metrics.prefix, statsd, tags); } @@ -150,3 +164,16 @@ pub fn execute() -> Result<()> { Ok(()) } + +/// Determines a Symbolicator's platform (`"js"`, `"jvm"`, or `"native"`) +/// according to the hostname. +fn get_platform() -> Option<&'static str> { + let hostname = hostname::get().ok().and_then(|s| s.into_string().ok())?; + if hostname.contains("js") { + Some("js") + } else if hostname.contains("jvm") { + Some("jvm") + } else { + Some("native") + } +}