From 41a11f6998c3ce8f6ebf84b616d1aede81546d92 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 24 Oct 2024 15:11:19 -0700 Subject: [PATCH 1/5] initial commit --- opentelemetry-sdk/src/metrics/meter.rs | 54 +++++++++++++++++++++----- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/meter.rs b/opentelemetry-sdk/src/metrics/meter.rs index 8cab6e1b68..98b729d58d 100644 --- a/opentelemetry-sdk/src/metrics/meter.rs +++ b/opentelemetry-sdk/src/metrics/meter.rs @@ -265,14 +265,20 @@ impl SdkMeter { { let validation_result = validate_instrument_config(builder.name.as_ref(), &builder.unit); if let Err(err) = validation_result { - global::handle_error(err); + otel_error!( + name: "InstrumentCreationFailed", + meter_name = self.scope.name.as_ref(), + instrument_name = builder.name.as_ref(), + message = "Measurements from this updown counter will be ignored.", + reason = format!("{}", err) + ); return UpDownCounter::new(Arc::new(NoopSyncInstrument::new())); } match resolver .lookup( InstrumentKind::UpDownCounter, - builder.name, + builder.name.clone(), builder.description, builder.unit, None, @@ -281,7 +287,13 @@ impl SdkMeter { { Ok(updown_counter) => updown_counter, Err(err) => { - global::handle_error(err); + otel_error!( + name: "InstrumentCreationFailed", + meter_name = self.scope.name.as_ref(), + instrument_name = builder.name.as_ref(), + message = "Measurements from this updown counter will be ignored.", + reason = format!("{}", err) + ); UpDownCounter::new(Arc::new(NoopSyncInstrument::new())) } } @@ -297,14 +309,20 @@ impl SdkMeter { { let validation_result = validate_instrument_config(builder.name.as_ref(), &builder.unit); if let Err(err) = validation_result { - global::handle_error(err); + otel_error!( + name: "InstrumentCreationFailed", + meter_name = self.scope.name.as_ref(), + instrument_name = builder.name.as_ref(), + message = "Measurements from this gauge will be ignored.", + reason = format!("{}", err) + ); return Gauge::new(Arc::new(NoopSyncInstrument::new())); } match resolver .lookup( InstrumentKind::Gauge, - builder.name, + builder.name.clone(), builder.description, builder.unit, None, @@ -313,7 +331,13 @@ impl SdkMeter { { Ok(gauge) => gauge, Err(err) => { - global::handle_error(err); + otel_error!( + name: "InstrumentCreationFailed", + meter_name = self.scope.name.as_ref(), + instrument_name = builder.name.as_ref(), + message = "Measurements from this gauge will be ignored.", + reason = format!("{}", err) + ); Gauge::new(Arc::new(NoopSyncInstrument::new())) } } @@ -329,14 +353,20 @@ impl SdkMeter { { let validation_result = validate_instrument_config(builder.name.as_ref(), &builder.unit); if let Err(err) = validation_result { - global::handle_error(err); + otel_error!( + name: "InstrumentCreationFailed", + meter_name = self.scope.name.as_ref(), + instrument_name = builder.name.as_ref(), + message = "Measurements from this histogram will be ignored.", + reason = format!("{}", err) + ); return Histogram::new(Arc::new(NoopSyncInstrument::new())); } match resolver .lookup( InstrumentKind::Histogram, - builder.name, + builder.name.clone(), builder.description, builder.unit, builder.boundaries, @@ -345,7 +375,13 @@ impl SdkMeter { { Ok(histogram) => histogram, Err(err) => { - global::handle_error(err); + otel_error!( + name: "InstrumentCreationFailed", + meter_name = self.scope.name.as_ref(), + instrument_name = builder.name.as_ref(), + message = "Measurements from this hsitogram will be ignored.", + reason = format!("{}", err) + ); Histogram::new(Arc::new(NoopSyncInstrument::new())) } } From ab3fc7e90cfdc8a26718078849e7cff59f11b972 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Sat, 26 Oct 2024 22:00:10 -0700 Subject: [PATCH 2/5] Update opentelemetry-sdk/src/metrics/meter.rs Co-authored-by: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> --- opentelemetry-sdk/src/metrics/meter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/metrics/meter.rs b/opentelemetry-sdk/src/metrics/meter.rs index b14ec3ab69..ad7631e9e6 100644 --- a/opentelemetry-sdk/src/metrics/meter.rs +++ b/opentelemetry-sdk/src/metrics/meter.rs @@ -300,7 +300,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Measurements from this updown counter will be ignored.", + message = "Measurements from this UpDownCounter will be ignored.", reason = format!("{}", err) ); return UpDownCounter::new(Arc::new(NoopSyncInstrument::new())); From b19346183efbeca939bf7d5242c0d2a53dacc013 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Sat, 26 Oct 2024 22:00:17 -0700 Subject: [PATCH 3/5] Update opentelemetry-sdk/src/metrics/meter.rs Co-authored-by: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> --- opentelemetry-sdk/src/metrics/meter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-sdk/src/metrics/meter.rs b/opentelemetry-sdk/src/metrics/meter.rs index ad7631e9e6..7dea685dbe 100644 --- a/opentelemetry-sdk/src/metrics/meter.rs +++ b/opentelemetry-sdk/src/metrics/meter.rs @@ -344,7 +344,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Measurements from this gauge will be ignored.", + message = "Measurements from this Gauge will be ignored.", reason = format!("{}", err) ); return Gauge::new(Arc::new(NoopSyncInstrument::new())); From 30a5f7590d1a2ca16a23c7086b34fb50df9930e2 Mon Sep 17 00:00:00 2001 From: Lalit Date: Sat, 26 Oct 2024 22:04:06 -0700 Subject: [PATCH 4/5] instrument names fix --- opentelemetry-sdk/src/metrics/meter.rs | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/meter.rs b/opentelemetry-sdk/src/metrics/meter.rs index 7dea685dbe..e9aefaf7bc 100644 --- a/opentelemetry-sdk/src/metrics/meter.rs +++ b/opentelemetry-sdk/src/metrics/meter.rs @@ -79,7 +79,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Measurements from this counter will be ignored.", + message = "Measurements from this Counter will be ignored.", reason = format!("{}", err) ); return Counter::new(Arc::new(NoopSyncInstrument::new())); @@ -101,7 +101,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Measurements from this counter will be ignored.", + message = "Measurements from this Counter will be ignored.", reason = format!("{}", err) ); Counter::new(Arc::new(NoopSyncInstrument::new())) @@ -123,7 +123,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Callbacks for this observable counter will not be invoked.", + message = "Callbacks for this ObservableCounter will not be invoked.", reason = format!("{}", err)); return ObservableCounter::new(); } @@ -141,7 +141,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Callbacks for this observable counter will not be invoked. Check View Configuration." + message = "Callbacks for this ObservableCounter will not be invoked. Check View Configuration." ); return ObservableCounter::new(); } @@ -161,7 +161,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Callbacks for this observable counter will not be invoked.", + message = "Callbacks for this ObservableCounter will not be invoked.", reason = format!("{}", err)); ObservableCounter::new() } @@ -182,7 +182,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Callbacks for this observable updown counter will not be invoked.", + message = "Callbacks for this ObservableUpDownCounter will not be invoked.", reason = format!("{}", err)); return ObservableUpDownCounter::new(); } @@ -200,7 +200,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Callbacks for this observable updown counter will not be invoked. Check View Configuration." + message = "Callbacks for this ObservableUpDownCounter will not be invoked. Check View Configuration." ); return ObservableUpDownCounter::new(); } @@ -220,7 +220,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Callbacks for this observable updown counter will not be invoked.", + message = "Callbacks for this ObservableUpDownCounter will not be invoked.", reason = format!("{}", err)); ObservableUpDownCounter::new() } @@ -241,7 +241,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Callbacks for this observable gauge will not be invoked.", + message = "Callbacks for this ObservableGauge will not be invoked.", reason = format!("{}", err)); return ObservableGauge::new(); } @@ -259,7 +259,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Callbacks for this observable gauge will not be invoked. Check View Configuration." + message = "Callbacks for this ObservableGauge will not be invoked. Check View Configuration." ); return ObservableGauge::new(); } @@ -279,7 +279,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Callbacks for this observable gauge will not be invoked.", + message = "Callbacks for this ObservableGauge will not be invoked.", reason = format!("{}", err)); ObservableGauge::new() } @@ -322,7 +322,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Measurements from this updown counter will be ignored.", + message = "Measurements from this UpDownCounter will be ignored.", reason = format!("{}", err) ); UpDownCounter::new(Arc::new(NoopSyncInstrument::new())) @@ -366,7 +366,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Measurements from this gauge will be ignored.", + message = "Measurements from this Gauge will be ignored.", reason = format!("{}", err) ); Gauge::new(Arc::new(NoopSyncInstrument::new())) @@ -388,7 +388,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Measurements from this histogram will be ignored.", + message = "Measurements from this Histogram will be ignored.", reason = format!("{}", err) ); return Histogram::new(Arc::new(NoopSyncInstrument::new())); @@ -410,7 +410,7 @@ impl SdkMeter { name: "InstrumentCreationFailed", meter_name = self.scope.name.as_ref(), instrument_name = builder.name.as_ref(), - message = "Measurements from this hsitogram will be ignored.", + message = "Measurements from this Histogram will be ignored.", reason = format!("{}", err) ); Histogram::new(Arc::new(NoopSyncInstrument::new())) From 3b15802f44dffa42c1905f9cee32f5b7831c956f Mon Sep 17 00:00:00 2001 From: Lalit Date: Sat, 26 Oct 2024 22:06:10 -0700 Subject: [PATCH 5/5] remove global --- opentelemetry-sdk/src/metrics/meter.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/opentelemetry-sdk/src/metrics/meter.rs b/opentelemetry-sdk/src/metrics/meter.rs index e9aefaf7bc..c552109362 100644 --- a/opentelemetry-sdk/src/metrics/meter.rs +++ b/opentelemetry-sdk/src/metrics/meter.rs @@ -2,7 +2,6 @@ use core::fmt; use std::{borrow::Cow, sync::Arc}; use opentelemetry::{ - global, metrics::{ AsyncInstrumentBuilder, Counter, Gauge, Histogram, HistogramBuilder, InstrumentBuilder, InstrumentProvider, MetricError, MetricResult, ObservableCounter, ObservableGauge,