Skip to content

Commit 2710d6e

Browse files
authored
Merge branch 'main' into feat/otel_0.26_promo
2 parents e91f7f2 + 78a684c commit 2710d6e

File tree

10 files changed

+108
-270
lines changed

10 files changed

+108
-270
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
@@ -277,7 +277,7 @@ impl SdkMeter {
277277

278278
fn create_histogram<T>(
279279
&self,
280-
builder: HistogramBuilder<'_, T>,
280+
builder: HistogramBuilder<'_, Histogram<T>>,
281281
resolver: &InstrumentResolver<'_, T>,
282282
) -> Result<Histogram<T>>
283283
where
@@ -407,12 +407,18 @@ impl InstrumentProvider for SdkMeter {
407407
self.create_observable_gauge(builder, &resolver)
408408
}
409409

410-
fn f64_histogram(&self, builder: HistogramBuilder<'_, f64>) -> Result<Histogram<f64>> {
410+
fn f64_histogram(
411+
&self,
412+
builder: HistogramBuilder<'_, Histogram<f64>>,
413+
) -> Result<Histogram<f64>> {
411414
let resolver = InstrumentResolver::new(self, &self.f64_resolver);
412415
self.create_histogram(builder, &resolver)
413416
}
414417

415-
fn u64_histogram(&self, builder: HistogramBuilder<'_, u64>) -> Result<Histogram<u64>> {
418+
fn u64_histogram(
419+
&self,
420+
builder: HistogramBuilder<'_, Histogram<u64>>,
421+
) -> Result<Histogram<u64>> {
416422
let resolver = InstrumentResolver::new(self, &self.u64_resolver);
417423
self.create_histogram(builder, &resolver)
418424
}

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
Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
use crate::{
2-
metrics::{AsyncInstrument, AsyncInstrumentBuilder, MetricsError},
3-
KeyValue,
4-
};
1+
use crate::{metrics::AsyncInstrument, KeyValue};
52
use core::fmt;
6-
use std::any::Any;
73
use std::sync::Arc;
84

9-
use super::InstrumentBuilder;
10-
115
/// An SDK implemented instrument that records increasing values.
126
pub trait SyncCounter<T> {
137
/// Records an increment to the counter.
@@ -39,22 +33,6 @@ impl<T> Counter<T> {
3933
}
4034
}
4135

42-
impl TryFrom<InstrumentBuilder<'_, Counter<u64>>> for Counter<u64> {
43-
type Error = MetricsError;
44-
45-
fn try_from(builder: InstrumentBuilder<'_, Counter<u64>>) -> Result<Self, Self::Error> {
46-
builder.instrument_provider.u64_counter(builder)
47-
}
48-
}
49-
50-
impl TryFrom<InstrumentBuilder<'_, Counter<f64>>> for Counter<f64> {
51-
type Error = MetricsError;
52-
53-
fn try_from(builder: InstrumentBuilder<'_, Counter<f64>>) -> Result<Self, Self::Error> {
54-
builder.instrument_provider.f64_counter(builder)
55-
}
56-
}
57-
5836
/// An async instrument that records increasing values.
5937
#[derive(Clone)]
6038
pub struct ObservableCounter<T>(Arc<dyn AsyncInstrument<T>>);
@@ -75,48 +53,8 @@ impl<T> fmt::Debug for ObservableCounter<T> {
7553
}
7654
}
7755

78-
impl<T> ObservableCounter<T> {
79-
/// Records an increment to the counter.
80-
///
81-
/// It is only valid to call this within a callback. If called outside of the
82-
/// registered callback it should have no effect on the instrument, and an
83-
/// error will be reported via the error handler.
84-
pub fn observe(&self, value: T, attributes: &[KeyValue]) {
85-
self.0.observe(value, attributes)
86-
}
87-
88-
/// Used for SDKs to downcast instruments in callbacks.
89-
pub fn as_any(&self) -> Arc<dyn Any> {
90-
self.0.as_any()
91-
}
92-
}
93-
9456
impl<T> AsyncInstrument<T> for ObservableCounter<T> {
9557
fn observe(&self, measurement: T, attributes: &[KeyValue]) {
9658
self.0.observe(measurement, attributes)
9759
}
98-
99-
fn as_any(&self) -> Arc<dyn Any> {
100-
self.0.as_any()
101-
}
102-
}
103-
104-
impl TryFrom<AsyncInstrumentBuilder<'_, ObservableCounter<u64>, u64>> for ObservableCounter<u64> {
105-
type Error = MetricsError;
106-
107-
fn try_from(
108-
builder: AsyncInstrumentBuilder<'_, ObservableCounter<u64>, u64>,
109-
) -> Result<Self, Self::Error> {
110-
builder.instrument_provider.u64_observable_counter(builder)
111-
}
112-
}
113-
114-
impl TryFrom<AsyncInstrumentBuilder<'_, ObservableCounter<f64>, f64>> for ObservableCounter<f64> {
115-
type Error = MetricsError;
116-
117-
fn try_from(
118-
builder: AsyncInstrumentBuilder<'_, ObservableCounter<f64>, f64>,
119-
) -> Result<Self, Self::Error> {
120-
builder.instrument_provider.f64_observable_counter(builder)
121-
}
12260
}
Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
use crate::{
2-
metrics::{AsyncInstrument, AsyncInstrumentBuilder, InstrumentBuilder, MetricsError},
3-
KeyValue,
4-
};
1+
use crate::{metrics::AsyncInstrument, KeyValue};
52
use core::fmt;
6-
use std::any::Any;
73
use std::sync::Arc;
84

95
/// An SDK implemented instrument that records independent values
@@ -37,30 +33,6 @@ impl<T> Gauge<T> {
3733
}
3834
}
3935

40-
impl TryFrom<InstrumentBuilder<'_, Gauge<u64>>> for Gauge<u64> {
41-
type Error = MetricsError;
42-
43-
fn try_from(builder: InstrumentBuilder<'_, Gauge<u64>>) -> Result<Self, Self::Error> {
44-
builder.instrument_provider.u64_gauge(builder)
45-
}
46-
}
47-
48-
impl TryFrom<InstrumentBuilder<'_, Gauge<f64>>> for Gauge<f64> {
49-
type Error = MetricsError;
50-
51-
fn try_from(builder: InstrumentBuilder<'_, Gauge<f64>>) -> Result<Self, Self::Error> {
52-
builder.instrument_provider.f64_gauge(builder)
53-
}
54-
}
55-
56-
impl TryFrom<InstrumentBuilder<'_, Gauge<i64>>> for Gauge<i64> {
57-
type Error = MetricsError;
58-
59-
fn try_from(builder: InstrumentBuilder<'_, Gauge<i64>>) -> Result<Self, Self::Error> {
60-
builder.instrument_provider.i64_gauge(builder)
61-
}
62-
}
63-
6436
/// An async instrument that records independent readings.
6537
#[derive(Clone)]
6638
pub struct ObservableGauge<T>(Arc<dyn AsyncInstrument<T>>);
@@ -77,29 +49,9 @@ where
7749
}
7850
}
7951

80-
impl<T> ObservableGauge<T> {
81-
/// Records the state of the instrument.
82-
///
83-
/// It is only valid to call this within a callback. If called outside of the
84-
/// registered callback it should have no effect on the instrument, and an
85-
/// error will be reported via the error handler.
86-
pub fn observe(&self, measurement: T, attributes: &[KeyValue]) {
87-
self.0.observe(measurement, attributes)
88-
}
89-
90-
/// Used by SDKs to downcast instruments in callbacks.
91-
pub fn as_any(&self) -> Arc<dyn Any> {
92-
self.0.as_any()
93-
}
94-
}
95-
9652
impl<M> AsyncInstrument<M> for ObservableGauge<M> {
9753
fn observe(&self, measurement: M, attributes: &[KeyValue]) {
98-
self.observe(measurement, attributes)
99-
}
100-
101-
fn as_any(&self) -> Arc<dyn Any> {
102-
self.0.as_any()
54+
self.0.observe(measurement, attributes)
10355
}
10456
}
10557

@@ -109,33 +61,3 @@ impl<T> ObservableGauge<T> {
10961
ObservableGauge(inner)
11062
}
11163
}
112-
113-
impl TryFrom<AsyncInstrumentBuilder<'_, ObservableGauge<u64>, u64>> for ObservableGauge<u64> {
114-
type Error = MetricsError;
115-
116-
fn try_from(
117-
builder: AsyncInstrumentBuilder<'_, ObservableGauge<u64>, u64>,
118-
) -> Result<Self, Self::Error> {
119-
builder.instrument_provider.u64_observable_gauge(builder)
120-
}
121-
}
122-
123-
impl TryFrom<AsyncInstrumentBuilder<'_, ObservableGauge<f64>, f64>> for ObservableGauge<f64> {
124-
type Error = MetricsError;
125-
126-
fn try_from(
127-
builder: AsyncInstrumentBuilder<'_, ObservableGauge<f64>, f64>,
128-
) -> Result<Self, Self::Error> {
129-
builder.instrument_provider.f64_observable_gauge(builder)
130-
}
131-
}
132-
133-
impl TryFrom<AsyncInstrumentBuilder<'_, ObservableGauge<i64>, i64>> for ObservableGauge<i64> {
134-
type Error = MetricsError;
135-
136-
fn try_from(
137-
builder: AsyncInstrumentBuilder<'_, ObservableGauge<i64>, i64>,
138-
) -> Result<Self, Self::Error> {
139-
builder.instrument_provider.i64_observable_gauge(builder)
140-
}
141-
}

0 commit comments

Comments
 (0)