Skip to content

Commit ee5c5f5

Browse files
committed
Merge branch 'global-error-handler-cleanup-metrics-sdk' of github.com:lalitb/opentelemetry-rust into global-error-handler-cleanup-metrics-sdk
2 parents 73fca4d + dbaa7f5 commit ee5c5f5

File tree

10 files changed

+31
-55
lines changed

10 files changed

+31
-55
lines changed

opentelemetry-sdk/src/metrics/instrument.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{any::Any, borrow::Cow, collections::HashSet, hash::Hash, sync::Arc};
1+
use std::{borrow::Cow, collections::HashSet, sync::Arc};
22

33
use opentelemetry::{
44
metrics::{AsyncInstrument, SyncCounter, SyncGauge, SyncHistogram, SyncUpDownCounter},
@@ -301,8 +301,4 @@ impl<T: Copy + Send + Sync + 'static> AsyncInstrument<T> for Observable<T> {
301301
measure.call(measurement, attrs)
302302
}
303303
}
304-
305-
fn as_any(&self) -> Arc<dyn Any> {
306-
Arc::new(self.clone())
307-
}
308304
}

opentelemetry-sdk/src/metrics/meter.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl SdkMeter {
280280

281281
fn create_histogram<T>(
282282
&self,
283-
builder: HistogramBuilder<'_, T>,
283+
builder: HistogramBuilder<'_, Histogram<T>>,
284284
resolver: &InstrumentResolver<'_, T>,
285285
) -> Result<Histogram<T>>
286286
where
@@ -410,12 +410,18 @@ impl InstrumentProvider for SdkMeter {
410410
self.create_observable_gauge(builder, &resolver)
411411
}
412412

413-
fn f64_histogram(&self, builder: HistogramBuilder<'_, f64>) -> Result<Histogram<f64>> {
413+
fn f64_histogram(
414+
&self,
415+
builder: HistogramBuilder<'_, Histogram<f64>>,
416+
) -> Result<Histogram<f64>> {
414417
let resolver = InstrumentResolver::new(self, &self.f64_resolver);
415418
self.create_histogram(builder, &resolver)
416419
}
417420

418-
fn u64_histogram(&self, builder: HistogramBuilder<'_, u64>) -> Result<Histogram<u64>> {
421+
fn u64_histogram(
422+
&self,
423+
builder: HistogramBuilder<'_, Histogram<u64>>,
424+
) -> Result<Histogram<u64>> {
419425
let resolver = InstrumentResolver::new(self, &self.u64_resolver);
420426
self.create_histogram(builder, &resolver)
421427
}

opentelemetry/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Bump MSRV to 1.70 [#2179](https://github.com/open-telemetry/opentelemetry-rust/pull/2179)
66
- Add `LogRecord::set_trace_context`; an optional method conditional on the `trace` feature for setting trace context on a log record.
7+
- Remove unnecessary public methods named `as_any` from `AsyncInstrument` trait and the implementing instruments: `ObservableCounter`, `ObservableGauge`, and `ObservableUpDownCounter` [#2187](https://github.com/open-telemetry/opentelemetry-rust/issues/2187)
78

89
## v0.26.0
910
Released 2024-Sep-30

opentelemetry/src/metrics/instruments/counter.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{metrics::AsyncInstrument, KeyValue};
22
use core::fmt;
3-
use std::any::Any;
43
use std::sync::Arc;
54

65
/// An SDK implemented instrument that records increasing values.
@@ -63,19 +62,10 @@ impl<T> ObservableCounter<T> {
6362
pub fn observe(&self, value: T, attributes: &[KeyValue]) {
6463
self.0.observe(value, attributes)
6564
}
66-
67-
/// Used for SDKs to downcast instruments in callbacks.
68-
pub fn as_any(&self) -> Arc<dyn Any> {
69-
self.0.as_any()
70-
}
7165
}
7266

7367
impl<T> AsyncInstrument<T> for ObservableCounter<T> {
7468
fn observe(&self, measurement: T, attributes: &[KeyValue]) {
7569
self.0.observe(measurement, attributes)
7670
}
77-
78-
fn as_any(&self) -> Arc<dyn Any> {
79-
self.0.as_any()
80-
}
8171
}

opentelemetry/src/metrics/instruments/gauge.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{metrics::AsyncInstrument, KeyValue};
22
use core::fmt;
3-
use std::any::Any;
43
use std::sync::Arc;
54

65
/// An SDK implemented instrument that records independent values
@@ -59,21 +58,12 @@ impl<T> ObservableGauge<T> {
5958
pub fn observe(&self, measurement: T, attributes: &[KeyValue]) {
6059
self.0.observe(measurement, attributes)
6160
}
62-
63-
/// Used by SDKs to downcast instruments in callbacks.
64-
pub fn as_any(&self) -> Arc<dyn Any> {
65-
self.0.as_any()
66-
}
6761
}
6862

6963
impl<M> AsyncInstrument<M> for ObservableGauge<M> {
7064
fn observe(&self, measurement: M, attributes: &[KeyValue]) {
7165
self.observe(measurement, attributes)
7266
}
73-
74-
fn as_any(&self) -> Arc<dyn Any> {
75-
self.0.as_any()
76-
}
7767
}
7868

7969
impl<T> ObservableGauge<T> {

opentelemetry/src/metrics/instruments/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ use gauge::{Gauge, ObservableGauge};
33
use crate::metrics::{Meter, Result};
44
use crate::KeyValue;
55
use core::fmt;
6-
use std::any::Any;
76
use std::borrow::Cow;
87
use std::marker;
9-
use std::sync::Arc;
108

119
use super::{
1210
Counter, Histogram, InstrumentProvider, ObservableCounter, ObservableUpDownCounter,
@@ -24,9 +22,6 @@ pub trait AsyncInstrument<T>: Send + Sync {
2422
///
2523
/// It is only valid to call this within a callback.
2624
fn observe(&self, measurement: T, attributes: &[KeyValue]);
27-
28-
/// Used for SDKs to downcast instruments in callbacks.
29-
fn as_any(&self) -> Arc<dyn Any>;
3025
}
3126

3227
/// Configuration for building a Histogram.
@@ -93,7 +88,7 @@ impl<'a, T> HistogramBuilder<'a, T> {
9388
}
9489
}
9590

96-
impl<'a> HistogramBuilder<'a, f64> {
91+
impl<'a> HistogramBuilder<'a, Histogram<f64>> {
9792
/// Validate the instrument configuration and creates a new instrument.
9893
pub fn try_init(self) -> Result<Histogram<f64>> {
9994
self.instrument_provider.f64_histogram(self)
@@ -109,7 +104,7 @@ impl<'a> HistogramBuilder<'a, f64> {
109104
}
110105
}
111106

112-
impl<'a> HistogramBuilder<'a, u64> {
107+
impl<'a> HistogramBuilder<'a, Histogram<u64>> {
113108
/// Validate the instrument configuration and creates a new instrument.
114109
pub fn try_init(self) -> Result<Histogram<u64>> {
115110
self.instrument_provider.u64_histogram(self)

opentelemetry/src/metrics/instruments/up_down_counter.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::KeyValue;
22
use core::fmt;
3-
use std::any::Any;
43
use std::sync::Arc;
54

65
use super::AsyncInstrument;
@@ -69,19 +68,10 @@ impl<T> ObservableUpDownCounter<T> {
6968
pub fn observe(&self, value: T, attributes: &[KeyValue]) {
7069
self.0.observe(value, attributes)
7170
}
72-
73-
/// Used for SDKs to downcast instruments in callbacks.
74-
pub fn as_any(&self) -> Arc<dyn Any> {
75-
self.0.as_any()
76-
}
7771
}
7872

7973
impl<T> AsyncInstrument<T> for ObservableUpDownCounter<T> {
8074
fn observe(&self, measurement: T, attributes: &[KeyValue]) {
8175
self.0.observe(measurement, attributes)
8276
}
83-
84-
fn as_any(&self) -> Arc<dyn std::any::Any> {
85-
self.0.as_any()
86-
}
8777
}

opentelemetry/src/metrics/meter.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::metrics::{
88
};
99
use crate::KeyValue;
1010

11-
use super::{Counter, HistogramBuilder};
11+
use super::{Counter, Histogram, HistogramBuilder};
1212

1313
/// Provides access to named [Meter] instances, for instrumenting an application
1414
/// or crate.
@@ -416,12 +416,18 @@ impl Meter {
416416
}
417417

418418
/// creates an instrument builder for recording a distribution of values.
419-
pub fn f64_histogram(&self, name: impl Into<Cow<'static, str>>) -> HistogramBuilder<'_, f64> {
419+
pub fn f64_histogram(
420+
&self,
421+
name: impl Into<Cow<'static, str>>,
422+
) -> HistogramBuilder<'_, Histogram<f64>> {
420423
HistogramBuilder::new(self, name.into())
421424
}
422425

423426
/// creates an instrument builder for recording a distribution of values.
424-
pub fn u64_histogram(&self, name: impl Into<Cow<'static, str>>) -> HistogramBuilder<'_, u64> {
427+
pub fn u64_histogram(
428+
&self,
429+
name: impl Into<Cow<'static, str>>,
430+
) -> HistogramBuilder<'_, Histogram<u64>> {
425431
HistogramBuilder::new(self, name.into())
426432
}
427433
}

opentelemetry/src/metrics/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,18 @@ pub trait InstrumentProvider {
223223
}
224224

225225
/// creates an instrument for recording a distribution of values.
226-
fn f64_histogram(&self, _builder: HistogramBuilder<'_, f64>) -> Result<Histogram<f64>> {
226+
fn f64_histogram(
227+
&self,
228+
_builder: HistogramBuilder<'_, Histogram<f64>>,
229+
) -> Result<Histogram<f64>> {
227230
Ok(Histogram::new(Arc::new(noop::NoopSyncInstrument::new())))
228231
}
229232

230233
/// creates an instrument for recording a distribution of values.
231-
fn u64_histogram(&self, _builder: HistogramBuilder<'_, u64>) -> Result<Histogram<u64>> {
234+
fn u64_histogram(
235+
&self,
236+
_builder: HistogramBuilder<'_, Histogram<u64>>,
237+
) -> Result<Histogram<u64>> {
232238
Ok(Histogram::new(Arc::new(noop::NoopSyncInstrument::new())))
233239
}
234240
}

opentelemetry/src/metrics/noop.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
},
1111
KeyValue,
1212
};
13-
use std::{any::Any, sync::Arc};
13+
use std::sync::Arc;
1414

1515
/// A no-op instance of a `MetricProvider`
1616
#[derive(Debug, Default)]
@@ -106,8 +106,4 @@ impl<T> AsyncInstrument<T> for NoopAsyncInstrument {
106106
fn observe(&self, _value: T, _attributes: &[KeyValue]) {
107107
// Ignored
108108
}
109-
110-
fn as_any(&self) -> Arc<dyn Any> {
111-
Arc::new(())
112-
}
113109
}

0 commit comments

Comments
 (0)