Skip to content
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 - UpDown Counter, Historgram, Gauge. #2242

Merged
merged 12 commits into from
Oct 27, 2024
77 changes: 56 additions & 21 deletions opentelemetry-sdk/src/metrics/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::{borrow::Cow, sync::Arc};

use opentelemetry::{
global,
metrics::{
AsyncInstrumentBuilder, Counter, Gauge, Histogram, HistogramBuilder, InstrumentBuilder,
InstrumentProvider, MetricError, MetricResult, ObservableCounter, ObservableGauge,
Expand Down Expand Up @@ -79,7 +78,7 @@
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.",

Check warning on line 81 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L81

Added line #L81 was not covered by tests
reason = format!("{}", err)
);
return Counter::new(Arc::new(NoopSyncInstrument::new()));
Expand All @@ -101,7 +100,7 @@
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.",

Check warning on line 103 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L103

Added line #L103 was not covered by tests
reason = format!("{}", err)
);
Counter::new(Arc::new(NoopSyncInstrument::new()))
Expand All @@ -123,7 +122,7 @@
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.",

Check warning on line 125 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L125

Added line #L125 was not covered by tests
reason = format!("{}", err));
return ObservableCounter::new();
}
Expand All @@ -141,7 +140,7 @@
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();
}
Expand All @@ -161,7 +160,7 @@
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.",

Check warning on line 163 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L163

Added line #L163 was not covered by tests
reason = format!("{}", err));
ObservableCounter::new()
}
Expand All @@ -182,7 +181,7 @@
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.",

Check warning on line 184 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L184

Added line #L184 was not covered by tests
reason = format!("{}", err));
return ObservableUpDownCounter::new();
}
Expand All @@ -200,7 +199,7 @@
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();
}
Expand All @@ -220,7 +219,7 @@
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.",

Check warning on line 222 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L222

Added line #L222 was not covered by tests
reason = format!("{}", err));
ObservableUpDownCounter::new()
}
Expand All @@ -241,7 +240,7 @@
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.",

Check warning on line 243 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L243

Added line #L243 was not covered by tests
reason = format!("{}", err));
return ObservableGauge::new();
}
Expand All @@ -259,7 +258,7 @@
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();
}
Expand All @@ -279,7 +278,7 @@
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.",

Check warning on line 281 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L281

Added line #L281 was not covered by tests
reason = format!("{}", err));
ObservableGauge::new()
}
Expand All @@ -296,14 +295,20 @@
{
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 UpDownCounter will be ignored.",
reason = format!("{}", err)

Check warning on line 303 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L300-L303

Added lines #L300 - L303 were not covered by tests
);
return UpDownCounter::new(Arc::new(NoopSyncInstrument::new()));
}

match resolver
.lookup(
InstrumentKind::UpDownCounter,
builder.name,
builder.name.clone(),
builder.description,
builder.unit,
None,
Expand All @@ -312,7 +317,13 @@
{
Ok(updown_counter) => updown_counter,
Err(err) => {
global::handle_error(err);
otel_error!(

Check warning on line 320 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L320

Added line #L320 was not covered by tests
name: "InstrumentCreationFailed",
meter_name = self.scope.name.as_ref(),
instrument_name = builder.name.as_ref(),
message = "Measurements from this UpDownCounter will be ignored.",
reason = format!("{}", err)

Check warning on line 325 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L322-L325

Added lines #L322 - L325 were not covered by tests
);
UpDownCounter::new(Arc::new(NoopSyncInstrument::new()))
}
}
Expand All @@ -328,14 +339,20 @@
{
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)

Check warning on line 347 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L344-L347

Added lines #L344 - L347 were not covered by tests
);
return Gauge::new(Arc::new(NoopSyncInstrument::new()));
}

match resolver
.lookup(
InstrumentKind::Gauge,
builder.name,
builder.name.clone(),
builder.description,
builder.unit,
None,
Expand All @@ -344,7 +361,13 @@
{
Ok(gauge) => gauge,
Err(err) => {
global::handle_error(err);
otel_error!(

Check warning on line 364 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L364

Added line #L364 was not covered by tests
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)

Check warning on line 369 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L366-L369

Added lines #L366 - L369 were not covered by tests
);
Gauge::new(Arc::new(NoopSyncInstrument::new()))
}
}
Expand All @@ -360,14 +383,20 @@
{
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)

Check warning on line 391 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L388-L391

Added lines #L388 - L391 were not covered by tests
);
return Histogram::new(Arc::new(NoopSyncInstrument::new()));
}

match resolver
.lookup(
InstrumentKind::Histogram,
builder.name,
builder.name.clone(),
builder.description,
builder.unit,
builder.boundaries,
Expand All @@ -376,7 +405,13 @@
{
Ok(histogram) => histogram,
Err(err) => {
global::handle_error(err);
otel_error!(

Check warning on line 408 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L408

Added line #L408 was not covered by tests
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)

Check warning on line 413 in opentelemetry-sdk/src/metrics/meter.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/meter.rs#L410-L413

Added lines #L410 - L413 were not covered by tests
);
Histogram::new(Arc::new(NoopSyncInstrument::new()))
}
}
Expand Down
Loading