-
Notifications
You must be signed in to change notification settings - Fork 598
Global error handler cleanup - Counter and Observable counter creation #2234
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
Changes from 3 commits
8a0e56c
47266ef
6c6d2d5
35e62fb
2b71415
ed5bedf
d2d462f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ use opentelemetry::{ | |
| InstrumentProvider, MetricsError, ObservableCounter, ObservableGauge, | ||
| ObservableUpDownCounter, Result, UpDownCounter, | ||
| }, | ||
| otel_error, | ||
| }; | ||
|
|
||
| use crate::instrumentation::Scope; | ||
|
|
@@ -75,14 +76,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 counter will be ignored.", | ||
| reason = format!("{}", err) | ||
| ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2024-10-24T05:32:23.524520Z ERROR main opentelemetry_sdk meter_name="mylibraryname" instrument_name="-my_counter" Measurements from this counter will be ignored. reason="Invalid instrument configuration: instrument name must start with an alphabetic character" ^ This is what we get when I used fmt module. The reason is a slightly extra verbose: This is a minor thing we can change in the future. |
||
| return Counter::new(Arc::new(NoopSyncInstrument::new())); | ||
| } | ||
|
|
||
| match resolver | ||
| .lookup( | ||
| InstrumentKind::Counter, | ||
| builder.name, | ||
| builder.name.clone(), | ||
| builder.description, | ||
| builder.unit, | ||
| None, | ||
|
|
@@ -91,7 +98,13 @@ impl SdkMeter { | |
| { | ||
| Ok(counter) => 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 counter will be ignored.", | ||
| reason = format!("{}", err) | ||
| ); | ||
| Counter::new(Arc::new(NoopSyncInstrument::new())) | ||
| } | ||
| } | ||
|
|
@@ -107,19 +120,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 = "Measurements from this observable counter will be ignored.", | ||
|
||
| reason = format!("{}", err)); | ||
| return ObservableCounter::new(); | ||
| } | ||
|
|
||
| match resolver.measures( | ||
| InstrumentKind::ObservableCounter, | ||
| 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 = "Measurements from this observable counter will be ignored. Check View Configuration." | ||
| ); | ||
| return ObservableCounter::new(); | ||
| } | ||
|
|
||
|
|
@@ -134,7 +158,12 @@ impl SdkMeter { | |
| ObservableCounter::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 = "Measurements from the observable counter will be ignored.", | ||
| reason = format!("{}", err)); | ||
| ObservableCounter::new() | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cijo's comment:
otel_error!(
name: "InstrumentCreationFailed",
meter_name = self.scope.name.as_ref(),
instrument_name = builder.name.as_ref(),
message = "Measurements from this instrument will be ignored."
reason = fmt(err))
^ I prefer this version. Please see if this is better for end users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Utkarsh comment:
change
"Measurements from this instrument will be ignored."to""Measurements from this counter will be ignored.",