-
Notifications
You must be signed in to change notification settings - Fork 465
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
Global error handler cleanup - Metrics SDK #2185
Changes from 17 commits
704b848
b8cb6af
a0b6eee
acf97fa
7b48f14
ac61b79
a42d516
dbaa7f5
73fca4d
ee5c5f5
3aa97cf
de54afe
e62de04
bda9faa
4a34922
0087c24
115e73f
56682a4
7e48cbf
d81b374
4b09c92
949930e
6dcc9eb
4b42fe8
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 |
---|---|---|
|
@@ -2,12 +2,12 @@ | |
use std::{borrow::Cow, sync::Arc}; | ||
|
||
use opentelemetry::{ | ||
global, | ||
metrics::{ | ||
AsyncInstrumentBuilder, Counter, Gauge, Histogram, HistogramBuilder, InstrumentBuilder, | ||
InstrumentProvider, MetricsError, ObservableCounter, ObservableGauge, | ||
ObservableUpDownCounter, Result, UpDownCounter, | ||
}, | ||
otel_error, | ||
}; | ||
|
||
use crate::instrumentation::Scope; | ||
|
@@ -75,14 +75,18 @@ | |
{ | ||
let validation_result = validate_instrument_config(builder.name.as_ref(), &builder.unit); | ||
if let Err(err) = validation_result { | ||
global::handle_error(err); | ||
otel_error!( | ||
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. otel_error!( ^ 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 commentThe reason will be displayed to describe this comment to others. Learn more. Error vs Warning - this is debatable. We need to find some agreement to follow throughout. |
||
name: "SdkMeter.CreateCounter.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
error = format!("Measurements from the instrument will be ignored. Reason: {}", err)); | ||
lalitb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Counter::new(Arc::new(NoopSyncInstrument::new())); | ||
} | ||
|
||
match resolver | ||
.lookup( | ||
InstrumentKind::Counter, | ||
builder.name, | ||
builder.name.clone(), | ||
builder.description, | ||
builder.unit, | ||
None, | ||
|
@@ -91,7 +95,12 @@ | |
{ | ||
Ok(counter) => counter, | ||
Err(err) => { | ||
global::handle_error(err); | ||
otel_error!( | ||
name: "SdkMeter.CreateCounter.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
error = format!("Measurements from the instrument will be ignored. Reason: {}", err) | ||
); | ||
Counter::new(Arc::new(NoopSyncInstrument::new())) | ||
} | ||
} | ||
|
@@ -107,34 +116,41 @@ | |
{ | ||
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: "SdkMeter.CreateObservableCounter.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
error = format!("Measurements from the instrument will be ignored. Reason: {}", 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: "SdkMeter.CreateObservableCounter.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
message = "Measurements from the instrument will be ignored. Reason: View Configuration / Drop Aggregation" | ||
); | ||
return ObservableCounter::new(); | ||
} | ||
|
||
let observable = Arc::new(Observable::new(ms)); | ||
|
||
for callback in builder.callbacks { | ||
let cb_inst = Arc::clone(&observable); | ||
self.pipes | ||
.register_callback(move || callback(cb_inst.as_ref())); | ||
} | ||
|
||
ObservableCounter::new() | ||
} | ||
Err(err) => { | ||
global::handle_error(err); | ||
Err(_err) => { | ||
// TBD - Add error handling | ||
lalitb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ObservableCounter::new() | ||
} | ||
} | ||
|
@@ -150,34 +166,41 @@ | |
{ | ||
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: "SdkMeter.CreateObservableUpDownCounter.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
error = format!("Measurements from the instrument will be ignored. Reason: {}", 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: "SdkMeter.CreateUpDownObservableCounter.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
message = "Measurements from the instrument will be ignored. Reason: View Configuration / Drop Aggregation" | ||
); | ||
return ObservableUpDownCounter::new(); | ||
} | ||
|
||
let observable = Arc::new(Observable::new(ms)); | ||
|
||
for callback in builder.callbacks { | ||
let cb_inst = Arc::clone(&observable); | ||
self.pipes | ||
.register_callback(move || callback(cb_inst.as_ref())); | ||
} | ||
|
||
ObservableUpDownCounter::new() | ||
} | ||
Err(err) => { | ||
global::handle_error(err); | ||
Err(_err) => { | ||
// TBD - Add error handling | ||
ObservableUpDownCounter::new() | ||
} | ||
} | ||
|
@@ -193,34 +216,41 @@ | |
{ | ||
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: "SdkMeter.CreateObservableGauge.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
error = format!("Measurements from the instrument will be ignored. Reason: {}", 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: "SdkMeter.CreateObservableGauge.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
message = "Measurements from the instrument will be ignored. Reason: View Configuration / Drop Aggregation" | ||
); | ||
return ObservableGauge::new(); | ||
} | ||
|
||
let observable = Arc::new(Observable::new(ms)); | ||
|
||
for callback in builder.callbacks { | ||
let cb_inst = Arc::clone(&observable); | ||
self.pipes | ||
.register_callback(move || callback(cb_inst.as_ref())); | ||
} | ||
|
||
ObservableGauge::new() | ||
} | ||
Err(err) => { | ||
global::handle_error(err); | ||
Err(_err) => { | ||
//TBD - Add error handling | ||
ObservableGauge::new() | ||
} | ||
} | ||
|
@@ -236,14 +266,18 @@ | |
{ | ||
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: "SdkMeter.CreateUpDownCounter.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
error = format!("Measurements from the instrument will be ignored. Reason: {}", err)); | ||
return UpDownCounter::new(Arc::new(NoopSyncInstrument::new())); | ||
} | ||
|
||
match resolver | ||
.lookup( | ||
InstrumentKind::UpDownCounter, | ||
builder.name, | ||
builder.name.clone(), | ||
builder.description, | ||
builder.unit, | ||
None, | ||
|
@@ -252,7 +286,12 @@ | |
{ | ||
Ok(updown_counter) => updown_counter, | ||
Err(err) => { | ||
global::handle_error(err); | ||
otel_error!( | ||
name: "SdkMeter.CreateUpDownCounter.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
error = format!("Measurements from the instrument will be ignored. Reason: {}", err) | ||
); | ||
UpDownCounter::new(Arc::new(NoopSyncInstrument::new())) | ||
} | ||
} | ||
|
@@ -268,14 +307,18 @@ | |
{ | ||
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: "SdkMeter.CreateGauge.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
error = format!("Measurements from the instrument will be ignored. Reason: {}", err)); | ||
return Gauge::new(Arc::new(NoopSyncInstrument::new())); | ||
} | ||
|
||
match resolver | ||
.lookup( | ||
InstrumentKind::Gauge, | ||
builder.name, | ||
builder.name.clone(), | ||
builder.description, | ||
builder.unit, | ||
None, | ||
|
@@ -284,7 +327,12 @@ | |
{ | ||
Ok(gauge) => gauge, | ||
Err(err) => { | ||
global::handle_error(err); | ||
otel_error!( | ||
name: "SdkMeter.CreateGauge.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
error = format!("Measurements from the instrument will be ignored. Reason: {}", err) | ||
); | ||
Gauge::new(Arc::new(NoopSyncInstrument::new())) | ||
} | ||
} | ||
|
@@ -300,14 +348,19 @@ | |
{ | ||
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: "SdkMeter.CreateHistogram.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
error = format!("Measurements from the instrument will be ignored. Reason: {}", err)); | ||
|
||
return Histogram::new(Arc::new(NoopSyncInstrument::new())); | ||
} | ||
|
||
match resolver | ||
.lookup( | ||
InstrumentKind::Histogram, | ||
builder.name, | ||
builder.name.clone(), | ||
builder.description, | ||
builder.unit, | ||
builder.boundaries, | ||
|
@@ -316,7 +369,12 @@ | |
{ | ||
Ok(histogram) => histogram, | ||
Err(err) => { | ||
global::handle_error(err); | ||
otel_error!( | ||
name: "SdkMeter.CreateHistogram.InstrumentCreationFailed", | ||
meter_name = self.scope.name.as_ref(), | ||
instrument_name = builder.name.as_ref(), | ||
error = format!("Measurements from the instrument will be ignored. Reason: {}", err) | ||
); | ||
Histogram::new(Arc::new(NoopSyncInstrument::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.
I don't know the inner workings enough to give a strong opinion - but unless this is a auto recoverable error, this can flood the error log.
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.
As what I can understand this part of code, this error occurs with restrictive
max_size
configuration, while the application is recording measurements with values that are far apart than what allowed bymax_size
. And error would be logged whenever the faulty measurement is recorded. If these faulty measurements are not frequent, the error log won't be flooded, else it can. Again, either some kind of throttling or simply flag to log only once need to be added. Let me know what you suggest, else I can keep TODO to revisit.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.
Unless we are 100% sure this cannot cause flooding of logs, lets remove the log from here, and leave a TODO to add logging once we understand more.