Skip to content

Commit fe50a9d

Browse files
committed
Add Send + Sync + Debug supertraits to obs traits
1 parent a5dd8db commit fe50a9d

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

rust-runtime/aws-smithy-observability-otel/external-types.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
allowed_external_types = [
2+
"aws_smithy_observability::error::ObservabilityError",
23
"aws_smithy_observability::meter::AsyncMeasurement",
34
"aws_smithy_observability::meter::Histogram",
45
"aws_smithy_observability::meter::Meter",

rust-runtime/aws-smithy-observability-otel/src/meter.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
//! OpenTelemetry based implementations of the Smithy Observability Meter traits.
77
8+
use std::fmt::Debug;
89
use std::ops::Deref;
910

1011
use crate::attributes::kv_from_option_attr;
@@ -22,27 +23,31 @@ use opentelemetry::metrics::{
2223
};
2324
use opentelemetry_sdk::metrics::SdkMeterProvider as OtelSdkMeterProvider;
2425

26+
#[derive(Debug)]
2527
struct UpDownCounterWrap(OtelUpDownCounter<i64>);
2628
impl UpDownCounter for UpDownCounterWrap {
2729
fn add(&self, value: i64, attributes: Option<&Attributes>, _context: Option<&dyn Context>) {
2830
self.0.add(value, &kv_from_option_attr(attributes));
2931
}
3032
}
3133

34+
#[derive(Debug)]
3235
struct HistogramWrap(OtelHistogram<f64>);
3336
impl Histogram for HistogramWrap {
3437
fn record(&self, value: f64, attributes: Option<&Attributes>, _context: Option<&dyn Context>) {
3538
self.0.record(value, &kv_from_option_attr(attributes));
3639
}
3740
}
3841

42+
#[derive(Debug)]
3943
struct MonotonicCounterWrap(OtelCounter<u64>);
4044
impl MonotonicCounter for MonotonicCounterWrap {
4145
fn add(&self, value: u64, attributes: Option<&Attributes>, _context: Option<&dyn Context>) {
4246
self.0.add(value, &kv_from_option_attr(attributes));
4347
}
4448
}
4549

50+
#[derive(Debug)]
4651
struct GaugeWrap(OtelObservableGauge<f64>);
4752
impl AsyncMeasurement for GaugeWrap {
4853
type Value = f64;
@@ -61,6 +66,7 @@ impl AsyncMeasurement for GaugeWrap {
6166
fn stop(&self) {}
6267
}
6368

69+
#[derive(Debug)]
6470
struct AsyncUpDownCounterWrap(OtelObservableUpDownCounter<i64>);
6571
impl AsyncMeasurement for AsyncUpDownCounterWrap {
6672
type Value = i64;
@@ -79,6 +85,7 @@ impl AsyncMeasurement for AsyncUpDownCounterWrap {
7985
fn stop(&self) {}
8086
}
8187

88+
#[derive(Debug)]
8289
struct AsyncMonotonicCounterWrap(OtelObservableCounter<u64>);
8390
impl AsyncMeasurement for AsyncMonotonicCounterWrap {
8491
type Value = u64;
@@ -115,6 +122,15 @@ impl<T> AsyncMeasurement for AsyncInstrumentWrap<'_, T> {
115122
fn stop(&self) {}
116123
}
117124

125+
// The OtelAsyncInstrument trait does not have Debug as a supertrait, so we impl a minimal version
126+
// for our wrapper struct
127+
impl<T> Debug for AsyncInstrumentWrap<'_, T> {
128+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
129+
f.debug_tuple("AsyncInstrumentWrap").finish()
130+
}
131+
}
132+
133+
#[derive(Debug)]
118134
struct MeterWrap(OtelMeter);
119135
impl Deref for MeterWrap {
120136
type Target = OtelMeter;

rust-runtime/aws-smithy-observability/src/meter.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
//! real time.
88
99
use crate::attributes::{Attributes, Context};
10+
use std::fmt::Debug;
1011

1112
/// Provides named instances of [Meter].
12-
pub trait MeterProvider {
13+
pub trait MeterProvider: Send + Sync + Debug {
1314
/// Get or create a named [Meter].
1415
fn get_meter(&self, scope: &'static str, attributes: Option<&Attributes>) -> Box<dyn Meter>;
1516

@@ -18,7 +19,7 @@ pub trait MeterProvider {
1819
}
1920

2021
/// The entry point to creating instruments. A grouping of related metrics.
21-
pub trait Meter {
22+
pub trait Meter: Send + Sync + Debug {
2223
/// Create a new Gauge.
2324
#[allow(clippy::type_complexity)]
2425
fn create_gauge(
@@ -75,25 +76,25 @@ pub trait Meter {
7576
}
7677

7778
/// Collects a set of events with an event count and sum for all events.
78-
pub trait Histogram {
79+
pub trait Histogram: Send + Sync + Debug {
7980
/// Record a value.
8081
fn record(&self, value: f64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
8182
}
8283

8384
/// A counter that monotonically increases.
84-
pub trait MonotonicCounter {
85+
pub trait MonotonicCounter: Send + Sync + Debug {
8586
/// Increment a counter by a fixed amount.
8687
fn add(&self, value: u64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
8788
}
8889

8990
/// A counter that can increase or decrease.
90-
pub trait UpDownCounter {
91+
pub trait UpDownCounter: Send + Sync + Debug {
9192
/// Increment or decrement a counter by a fixed amount.
9293
fn add(&self, value: i64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
9394
}
9495

9596
/// A measurement that can be taken asynchronously.
96-
pub trait AsyncMeasurement {
97+
pub trait AsyncMeasurement: Send + Sync + Debug {
9798
/// The type recorded by the measurement.
9899
type Value;
99100

rust-runtime/aws-smithy-observability/src/noop.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
//! An noop implementation of the Meter traits
77
8+
use std::fmt::Debug;
89
use std::marker::PhantomData;
910

1011
use crate::{
1112
attributes::{Attributes, Context},
1213
meter::{AsyncMeasurement, Histogram, Meter, MeterProvider, MonotonicCounter, UpDownCounter},
1314
};
1415

16+
#[derive(Debug)]
1517
pub(crate) struct NoopMeterProvider;
1618
impl MeterProvider for NoopMeterProvider {
1719
fn get_meter(&self, _scope: &'static str, _attributes: Option<&Attributes>) -> Box<dyn Meter> {
@@ -23,6 +25,7 @@ impl MeterProvider for NoopMeterProvider {
2325
}
2426
}
2527

28+
#[derive(Debug)]
2629
pub(crate) struct NoopMeter;
2730
impl Meter for NoopMeter {
2831
fn create_gauge(
@@ -83,25 +86,29 @@ impl Meter for NoopMeter {
8386
}
8487
}
8588

86-
struct NoopAsyncMeasurement<T>(PhantomData<T>);
87-
impl<T> AsyncMeasurement for NoopAsyncMeasurement<T> {
89+
#[derive(Debug)]
90+
struct NoopAsyncMeasurement<T: Send + Sync + Debug>(PhantomData<T>);
91+
impl<T: Send + Sync + Debug> AsyncMeasurement for NoopAsyncMeasurement<T> {
8892
type Value = T;
8993

9094
fn record(&self, _value: T, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {}
9195

9296
fn stop(&self) {}
9397
}
9498

99+
#[derive(Debug)]
95100
struct NoopUpDownCounter;
96101
impl UpDownCounter for NoopUpDownCounter {
97102
fn add(&self, _value: i64, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {}
98103
}
99104

105+
#[derive(Debug)]
100106
struct NoopMonotonicCounter;
101107
impl MonotonicCounter for NoopMonotonicCounter {
102108
fn add(&self, _value: u64, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {}
103109
}
104110

111+
#[derive(Debug)]
105112
struct NoopHistogram;
106113
impl Histogram for NoopHistogram {
107114
fn record(

0 commit comments

Comments
 (0)