Skip to content

Commit

Permalink
feat(metrics): Add platform tag
Browse files Browse the repository at this point in the history
  • Loading branch information
loewenheim committed Aug 19, 2024
1 parent a377400 commit 7c0241d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/symbolicator-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ pub struct Metrics {
pub hostname_tag: Option<String>,
/// A tag name to report the environment to, for each metric. Defaults to not sending such a tag.
pub environment_tag: Option<String>,
/// A tag name to report the platform to, for each metric. Defaults to not sending such a tag.
pub platform_tag: Option<String>,
/// A map containing custom tags and their values.
///
/// These tags will be appended to every metric.
Expand All @@ -107,6 +109,7 @@ impl Default for Metrics {
prefix: "symbolicator".into(),
hostname_tag: None,
environment_tag: None,
platform_tag: None,
custom_tags: BTreeMap::new(),
}
}
Expand Down
27 changes: 27 additions & 0 deletions crates/symbolicator/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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")
}
}

0 comments on commit 7c0241d

Please sign in to comment.