Skip to content

Commit

Permalink
Set project name as prefix instead of suffix in metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
aterentic-ethernal committed Oct 30, 2024
1 parent 83cf4a5 commit 8324970
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.0.4

- Fix telemetry naming, put project name as prefix instead of suffix
- Add timeouts to RPC subscriptions
- Integrate upstream `rust-libp2p` `0.54` changes to the bootstrap process

Expand Down
10 changes: 7 additions & 3 deletions core/src/telemetry/otlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ pub struct Metrics {
}

impl Metrics {
fn gauge_name(&self, name: &'static str) -> String {
format!("{project_name}.{name}", project_name = self.project_name)
}

fn map_attributes(&self, attributes: Vec<(String, String)>) -> Vec<KeyValue> {
attributes
.into_iter()
Expand All @@ -31,7 +35,7 @@ impl Metrics {
}

fn record_u64(&self, name: &'static str, value: u64, attributes: Vec<KeyValue>) -> Result<()> {
let gauge_name = format!("{}.{}", name, self.project_name);
let gauge_name = self.gauge_name(name);
let instrument = self.meter.u64_observable_gauge(gauge_name).try_init()?;
self.meter
.register_callback(&[instrument.as_any()], move |observer| {
Expand All @@ -41,7 +45,7 @@ impl Metrics {
}

fn record_f64(&self, name: &'static str, value: f64, attributes: Vec<KeyValue>) -> Result<()> {
let gauge_name = format!("{}.{}", name, self.project_name);
let gauge_name = self.gauge_name(name);
let instrument = self.meter.f64_observable_gauge(gauge_name).try_init()?;
self.meter
.register_callback(&[instrument.as_any()], move |observer| {
Expand Down Expand Up @@ -204,7 +208,7 @@ fn init_counters(
.iter()
.filter(|counter| MetricCounter::is_allowed(counter, origin))
.map(|counter| {
let otel_counter_name = format!("{}.{}", project_name, counter.name());
let otel_counter_name = format!("{project_name}.{name}", name = counter.name());
// Keep the `static str as the local buffer map key, but change the OTel counter name`
(counter.name(), meter.u64_counter(otel_counter_name).init())
})
Expand Down

0 comments on commit 8324970

Please sign in to comment.