Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add otel_scope_info and scope labels #974

Merged
Merged
Prev Previous commit
Next Next commit
feat: add scope attr
  • Loading branch information
zengxilong committed Feb 24, 2023
commit 1b95acc78f7b43f863fce6901181e1b406e520d5
12 changes: 9 additions & 3 deletions opentelemetry-prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ use sanitize::sanitize;
/// https://github.com/open-telemetry/opentelemetry-specification/blob/v1.14.0/specification/metrics/data-model.md#sums-1
const MONOTONIC_COUNTER_SUFFIX: &str = "_total";

const OTEL_SCOPE_VERSION = "otel_scope_version";
/// metric points should have instrumentation scope name as a label in prometheus
const OTEL_SCOPE_NAME: &str = "otel_scope_name";
// Instrumentation Scope and Version as labels in Prometheus
/// metric points should have instrumentation scope version as a label in prometheus
const OTEL_SCOPE_VERSION: &str = "otel_scope_version";

/// Create a new prometheus exporter builder.
pub fn exporter(controller: BasicController) -> ExporterBuilder {
Expand Down Expand Up @@ -400,9 +404,11 @@ fn get_metric_labels(
let iter = attributes::merge_iters(record.attributes().iter(), resource.iter());
let mut labels: Vec<prometheus::proto::LabelPair> = iter.map(|(key, value)| build_label_pair(key, value))
.collect();
labels.push(build_label_pair(&Key::new("otel_scope_name"),&Value::String(StringValue::from(_library.name.to_owned().to_string()))));
labels.push(build_label_pair(&Key::new(OTEL_SCOPE_NAME),
&Value::String(StringValue::from(_library.name.to_owned().to_string()))));
if let Some(version) = _library.version.to_owned() {
labels.push(build_label_pair(&Key::new("otel_scope_version"),&Value::String(StringValue::from(version.to_string()))));
labels.push(build_label_pair(&Key::new(OTEL_SCOPE_VERSION),
&Value::String(StringValue::from(version.to_string()))));
}
labels
}
Expand Down