Skip to content

Commit af4527c

Browse files
authored
[Metrics API] Remove as_any methods (open-telemetry#2187)
1 parent 21e1ba5 commit af4527c

File tree

7 files changed

+3
-45
lines changed

7 files changed

+3
-45
lines changed

opentelemetry-sdk/src/metrics/instrument.rs

+1-5
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/CHANGELOG.md

+1
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

-10
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

-10
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

-5
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.

opentelemetry/src/metrics/instruments/up_down_counter.rs

-10
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/noop.rs

+1-5
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)