From 4c7bf582e56eddc5b4eca197d7a9f7e7866b8fff Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 24 Oct 2024 23:49:46 -0700 Subject: [PATCH] Global error handler cleanup - ObservableUpDownCounter, ObservableGauge (#2240) Co-authored-by: Cijo Thomas --- opentelemetry-sdk/src/metrics/meter.rs | 44 ++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/opentelemetry-sdk/src/metrics/meter.rs b/opentelemetry-sdk/src/metrics/meter.rs index 0772c80107..1a5432f000 100644 --- a/opentelemetry-sdk/src/metrics/meter.rs +++ b/opentelemetry-sdk/src/metrics/meter.rs @@ -178,19 +178,30 @@ 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 = "Callbacks for this observable updown counter will not be invoked.", + reason = format!("{}", err)); return ObservableUpDownCounter::new(); } match resolver.measures( InstrumentKind::ObservableUpDownCounter, - builder.name, + builder.name.clone(), builder.description, builder.unit, None, ) { Ok(ms) => { if ms.is_empty() { + otel_error!( + 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." + ); return ObservableUpDownCounter::new(); } @@ -205,7 +216,12 @@ impl SdkMeter { ObservableUpDownCounter::new() } Err(err) => { - global::handle_error(err); + otel_error!( + 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.", + reason = format!("{}", err)); ObservableUpDownCounter::new() } } @@ -221,19 +237,30 @@ 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 = "Callbacks for this observable gauge will not be invoked.", + reason = format!("{}", err)); return ObservableGauge::new(); } match resolver.measures( InstrumentKind::ObservableGauge, - builder.name, + builder.name.clone(), builder.description, builder.unit, None, ) { Ok(ms) => { if ms.is_empty() { + otel_error!( + 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." + ); return ObservableGauge::new(); } @@ -248,7 +275,12 @@ impl SdkMeter { ObservableGauge::new() } Err(err) => { - global::handle_error(err); + otel_error!( + 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.", + reason = format!("{}", err)); ObservableGauge::new() } }