Skip to content

Commit 49944e0

Browse files
authored
Merge branch 'main' into simple-log-exporter-test
2 parents b307c27 + e6965bd commit 49944e0

File tree

11 files changed

+53
-152
lines changed

11 files changed

+53
-152
lines changed

opentelemetry-otlp/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
//! * `grpc-tonic`: Use `tonic` as grpc layer. This is enabled by default.
101101
//! * `gzip-tonic`: Use gzip compression for `tonic` grpc layer.
102102
//! * `zstd-tonic`: Use zstd compression for `tonic` grpc layer.
103-
//! * `tls-tonic`: Enable TLS.
104103
//! * `tls-roots`: Adds system trust roots to rustls-based gRPC clients using the rustls-native-certs crate
105104
//! * `tls-webkpi-roots`: Embeds Mozilla's trust roots to rustls-based gRPC clients using the webkpi-roots crate
106105
//!

opentelemetry-sdk/src/metrics/meter.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::metrics::{
1717
pipeline::{Pipelines, Resolver},
1818
};
1919

20-
use super::noop::{NoopAsyncInstrument, NoopSyncInstrument};
20+
use super::noop::NoopSyncInstrument;
2121

2222
// maximum length of instrument name
2323
const INSTRUMENT_NAME_MAX_LENGTH: usize = 255;
@@ -108,7 +108,7 @@ impl SdkMeter {
108108
let validation_result = validate_instrument_config(builder.name.as_ref(), &builder.unit);
109109
if let Err(err) = validation_result {
110110
global::handle_error(err);
111-
return Ok(ObservableCounter::new(Arc::new(NoopAsyncInstrument::new())));
111+
return Ok(ObservableCounter::new());
112112
}
113113

114114
let ms = resolver.measures(
@@ -120,7 +120,7 @@ impl SdkMeter {
120120
)?;
121121

122122
if ms.is_empty() {
123-
return Ok(ObservableCounter::new(Arc::new(NoopAsyncInstrument::new())));
123+
return Ok(ObservableCounter::new());
124124
}
125125

126126
let observable = Arc::new(Observable::new(ms));
@@ -131,7 +131,7 @@ impl SdkMeter {
131131
.register_callback(move || callback(cb_inst.as_ref()));
132132
}
133133

134-
Ok(ObservableCounter::new(observable))
134+
Ok(ObservableCounter::new())
135135
}
136136

137137
fn create_observable_updown_counter<T>(
@@ -145,9 +145,7 @@ impl SdkMeter {
145145
let validation_result = validate_instrument_config(builder.name.as_ref(), &builder.unit);
146146
if let Err(err) = validation_result {
147147
global::handle_error(err);
148-
return Ok(ObservableUpDownCounter::new(Arc::new(
149-
NoopAsyncInstrument::new(),
150-
)));
148+
return Ok(ObservableUpDownCounter::new());
151149
}
152150

153151
let ms = resolver.measures(
@@ -159,9 +157,7 @@ impl SdkMeter {
159157
)?;
160158

161159
if ms.is_empty() {
162-
return Ok(ObservableUpDownCounter::new(Arc::new(
163-
NoopAsyncInstrument::new(),
164-
)));
160+
return Ok(ObservableUpDownCounter::new());
165161
}
166162

167163
let observable = Arc::new(Observable::new(ms));
@@ -172,7 +168,7 @@ impl SdkMeter {
172168
.register_callback(move || callback(cb_inst.as_ref()));
173169
}
174170

175-
Ok(ObservableUpDownCounter::new(observable))
171+
Ok(ObservableUpDownCounter::new())
176172
}
177173

178174
fn create_observable_gauge<T>(
@@ -186,7 +182,7 @@ impl SdkMeter {
186182
let validation_result = validate_instrument_config(builder.name.as_ref(), &builder.unit);
187183
if let Err(err) = validation_result {
188184
global::handle_error(err);
189-
return Ok(ObservableGauge::new(Arc::new(NoopAsyncInstrument::new())));
185+
return Ok(ObservableGauge::new());
190186
}
191187

192188
let ms = resolver.measures(
@@ -198,7 +194,7 @@ impl SdkMeter {
198194
)?;
199195

200196
if ms.is_empty() {
201-
return Ok(ObservableGauge::new(Arc::new(NoopAsyncInstrument::new())));
197+
return Ok(ObservableGauge::new());
202198
}
203199

204200
let observable = Arc::new(Observable::new(ms));
@@ -209,7 +205,7 @@ impl SdkMeter {
209205
.register_callback(move || callback(cb_inst.as_ref()));
210206
}
211207

212-
Ok(ObservableGauge::new(observable))
208+
Ok(ObservableGauge::new())
213209
}
214210

215211
fn create_updown_counter<T>(

opentelemetry-sdk/src/metrics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn calculate_hash(values: &[KeyValue]) -> u64 {
104104

105105
impl AttributeSet {
106106
fn new(mut values: Vec<KeyValue>) -> Self {
107-
values.sort_unstable();
107+
values.sort_unstable_by(|a, b| a.key.cmp(&b.key));
108108
let hash = calculate_hash(&values);
109109
AttributeSet(values, hash)
110110
}

opentelemetry-sdk/src/metrics/noop.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use opentelemetry::{
2-
metrics::{AsyncInstrument, InstrumentProvider, SyncInstrument},
2+
metrics::{InstrumentProvider, SyncInstrument},
33
KeyValue,
44
};
55

@@ -36,22 +36,3 @@ impl<T> SyncInstrument<T> for NoopSyncInstrument {
3636
// Ignored
3737
}
3838
}
39-
40-
/// A no-op async instrument.
41-
#[derive(Debug, Default)]
42-
pub(crate) struct NoopAsyncInstrument {
43-
_private: (),
44-
}
45-
46-
impl NoopAsyncInstrument {
47-
/// Create a new no-op async instrument
48-
pub(crate) fn new() -> Self {
49-
NoopAsyncInstrument { _private: () }
50-
}
51-
}
52-
53-
impl<T> AsyncInstrument<T> for NoopAsyncInstrument {
54-
fn observe(&self, _value: T, _attributes: &[KeyValue]) {
55-
// Ignored
56-
}
57-
}

opentelemetry/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
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-
- Removed 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)
8-
- Introduced `SyncInstrument` trait to replace the individual synchronous instrument traits (`SyncCounter`, `SyncGauge`, `SyncHistogram`, `SyncUpDownCounter`) which are meant for SDK implementation. [#2207](https://github.com/open-telemetry/opentelemetry-rust/issues/2207)
7+
- Removed 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/pull/2187)
8+
- Introduced `SyncInstrument` trait to replace the individual synchronous instrument traits (`SyncCounter`, `SyncGauge`, `SyncHistogram`, `SyncUpDownCounter`) which are meant for SDK implementation. [#2207](https://github.com/open-telemetry/opentelemetry-rust/pull/2207)
9+
- Ensured that `observe` method on asynchronous instruments can only be called inside a callback. This was done by removing the implementation of `AsyncInstrument` trait for each of the asynchronous instruments. [#2210](https://github.com/open-telemetry/opentelemetry-rust/pull/2210)
10+
- Removed `PartialOrd` and `Ord` implementations for `KeyValue`. [#2215](https://github.com/open-telemetry/opentelemetry-rust/pull/2215)
911

1012
## v0.26.0
1113
Released 2024-Sep-30

opentelemetry/src/metrics/instruments/counter.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{metrics::AsyncInstrument, KeyValue};
1+
use crate::KeyValue;
22
use core::fmt;
33
use std::sync::Arc;
44

@@ -33,12 +33,17 @@ impl<T> Counter<T> {
3333
/// An async instrument that records increasing values.
3434
#[derive(Clone)]
3535
#[non_exhaustive]
36-
pub struct ObservableCounter<T>(Arc<dyn AsyncInstrument<T>>);
36+
pub struct ObservableCounter<T> {
37+
_marker: std::marker::PhantomData<T>,
38+
}
3739

3840
impl<T> ObservableCounter<T> {
3941
/// Create a new observable counter.
40-
pub fn new(inner: Arc<dyn AsyncInstrument<T>>) -> Self {
41-
ObservableCounter(inner)
42+
#[allow(clippy::new_without_default)]
43+
pub fn new() -> Self {
44+
ObservableCounter {
45+
_marker: std::marker::PhantomData,
46+
}
4247
}
4348
}
4449

@@ -50,9 +55,3 @@ impl<T> fmt::Debug for ObservableCounter<T> {
5055
))
5156
}
5257
}
53-
54-
impl<T> AsyncInstrument<T> for ObservableCounter<T> {
55-
fn observe(&self, measurement: T, attributes: &[KeyValue]) {
56-
self.0.observe(measurement, attributes)
57-
}
58-
}

opentelemetry/src/metrics/instruments/gauge.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{metrics::AsyncInstrument, KeyValue};
1+
use crate::KeyValue;
22
use core::fmt;
33
use std::sync::Arc;
44

@@ -33,7 +33,9 @@ impl<T> Gauge<T> {
3333
/// An async instrument that records independent readings.
3434
#[derive(Clone)]
3535
#[non_exhaustive]
36-
pub struct ObservableGauge<T>(Arc<dyn AsyncInstrument<T>>);
36+
pub struct ObservableGauge<T> {
37+
_marker: std::marker::PhantomData<T>,
38+
}
3739

3840
impl<T> fmt::Debug for ObservableGauge<T>
3941
where
@@ -47,15 +49,12 @@ where
4749
}
4850
}
4951

50-
impl<M> AsyncInstrument<M> for ObservableGauge<M> {
51-
fn observe(&self, measurement: M, attributes: &[KeyValue]) {
52-
self.0.observe(measurement, attributes)
53-
}
54-
}
55-
5652
impl<T> ObservableGauge<T> {
5753
/// Create a new gauge
58-
pub fn new(inner: Arc<dyn AsyncInstrument<T>>) -> Self {
59-
ObservableGauge(inner)
54+
#[allow(clippy::new_without_default)]
55+
pub fn new() -> Self {
56+
ObservableGauge {
57+
_marker: std::marker::PhantomData,
58+
}
6059
}
6160
}

opentelemetry/src/metrics/instruments/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,7 @@ pub type Callback<T> = Box<dyn Fn(&dyn AsyncInstrument<T>) + Send + Sync>;
241241

242242
/// Configuration for building an async instrument.
243243
#[non_exhaustive] // We expect to add more configuration fields in the future
244-
pub struct AsyncInstrumentBuilder<'a, I, M>
245-
where
246-
I: AsyncInstrument<M>,
247-
{
244+
pub struct AsyncInstrumentBuilder<'a, I, M> {
248245
/// Instrument provider is used to create the instrument.
249246
pub instrument_provider: &'a dyn InstrumentProvider,
250247

@@ -263,10 +260,7 @@ where
263260
_inst: marker::PhantomData<I>,
264261
}
265262

266-
impl<'a, I, M> AsyncInstrumentBuilder<'a, I, M>
267-
where
268-
I: AsyncInstrument<M>,
269-
{
263+
impl<'a, I, M> AsyncInstrumentBuilder<'a, I, M> {
270264
/// Create a new instrument builder
271265
pub(crate) fn new(meter: &'a Meter, name: Cow<'static, str>) -> Self {
272266
AsyncInstrumentBuilder {

opentelemetry/src/metrics/instruments/up_down_counter.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::KeyValue;
22
use core::fmt;
33
use std::sync::Arc;
44

5-
use super::{AsyncInstrument, SyncInstrument};
5+
use super::SyncInstrument;
66

77
/// An instrument that records increasing or decreasing values.
88
#[derive(Clone)]
@@ -36,7 +36,9 @@ impl<T> UpDownCounter<T> {
3636
/// An async instrument that records increasing or decreasing values.
3737
#[derive(Clone)]
3838
#[non_exhaustive]
39-
pub struct ObservableUpDownCounter<T>(Arc<dyn AsyncInstrument<T>>);
39+
pub struct ObservableUpDownCounter<T> {
40+
_marker: std::marker::PhantomData<T>,
41+
}
4042

4143
impl<T> fmt::Debug for ObservableUpDownCounter<T>
4244
where
@@ -52,13 +54,10 @@ where
5254

5355
impl<T> ObservableUpDownCounter<T> {
5456
/// Create a new observable up down counter.
55-
pub fn new(inner: Arc<dyn AsyncInstrument<T>>) -> Self {
56-
ObservableUpDownCounter(inner)
57-
}
58-
}
59-
60-
impl<T> AsyncInstrument<T> for ObservableUpDownCounter<T> {
61-
fn observe(&self, measurement: T, attributes: &[KeyValue]) {
62-
self.0.observe(measurement, attributes)
57+
#[allow(clippy::new_without_default)]
58+
pub fn new() -> Self {
59+
ObservableUpDownCounter {
60+
_marker: std::marker::PhantomData,
61+
}
6362
}
6463
}

0 commit comments

Comments
 (0)