From fe50a9dd499faa70ec4be9ad3bcc43bd13785b4c Mon Sep 17 00:00:00 2001 From: Landon James Date: Mon, 18 Nov 2024 14:19:34 -0800 Subject: [PATCH] Add Send + Sync + Debug supertraits to obs traits --- .../external-types.toml | 1 + .../aws-smithy-observability-otel/src/meter.rs | 16 ++++++++++++++++ .../aws-smithy-observability/src/meter.rs | 13 +++++++------ .../aws-smithy-observability/src/noop.rs | 11 +++++++++-- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/rust-runtime/aws-smithy-observability-otel/external-types.toml b/rust-runtime/aws-smithy-observability-otel/external-types.toml index bcdda1485e..679141bfed 100644 --- a/rust-runtime/aws-smithy-observability-otel/external-types.toml +++ b/rust-runtime/aws-smithy-observability-otel/external-types.toml @@ -1,4 +1,5 @@ allowed_external_types = [ + "aws_smithy_observability::error::ObservabilityError", "aws_smithy_observability::meter::AsyncMeasurement", "aws_smithy_observability::meter::Histogram", "aws_smithy_observability::meter::Meter", diff --git a/rust-runtime/aws-smithy-observability-otel/src/meter.rs b/rust-runtime/aws-smithy-observability-otel/src/meter.rs index 1270b075a0..7ba85df9b9 100644 --- a/rust-runtime/aws-smithy-observability-otel/src/meter.rs +++ b/rust-runtime/aws-smithy-observability-otel/src/meter.rs @@ -5,6 +5,7 @@ //! OpenTelemetry based implementations of the Smithy Observability Meter traits. +use std::fmt::Debug; use std::ops::Deref; use crate::attributes::kv_from_option_attr; @@ -22,6 +23,7 @@ use opentelemetry::metrics::{ }; use opentelemetry_sdk::metrics::SdkMeterProvider as OtelSdkMeterProvider; +#[derive(Debug)] struct UpDownCounterWrap(OtelUpDownCounter); impl UpDownCounter for UpDownCounterWrap { fn add(&self, value: i64, attributes: Option<&Attributes>, _context: Option<&dyn Context>) { @@ -29,6 +31,7 @@ impl UpDownCounter for UpDownCounterWrap { } } +#[derive(Debug)] struct HistogramWrap(OtelHistogram); impl Histogram for HistogramWrap { fn record(&self, value: f64, attributes: Option<&Attributes>, _context: Option<&dyn Context>) { @@ -36,6 +39,7 @@ impl Histogram for HistogramWrap { } } +#[derive(Debug)] struct MonotonicCounterWrap(OtelCounter); impl MonotonicCounter for MonotonicCounterWrap { fn add(&self, value: u64, attributes: Option<&Attributes>, _context: Option<&dyn Context>) { @@ -43,6 +47,7 @@ impl MonotonicCounter for MonotonicCounterWrap { } } +#[derive(Debug)] struct GaugeWrap(OtelObservableGauge); impl AsyncMeasurement for GaugeWrap { type Value = f64; @@ -61,6 +66,7 @@ impl AsyncMeasurement for GaugeWrap { fn stop(&self) {} } +#[derive(Debug)] struct AsyncUpDownCounterWrap(OtelObservableUpDownCounter); impl AsyncMeasurement for AsyncUpDownCounterWrap { type Value = i64; @@ -79,6 +85,7 @@ impl AsyncMeasurement for AsyncUpDownCounterWrap { fn stop(&self) {} } +#[derive(Debug)] struct AsyncMonotonicCounterWrap(OtelObservableCounter); impl AsyncMeasurement for AsyncMonotonicCounterWrap { type Value = u64; @@ -115,6 +122,15 @@ impl AsyncMeasurement for AsyncInstrumentWrap<'_, T> { fn stop(&self) {} } +// The OtelAsyncInstrument trait does not have Debug as a supertrait, so we impl a minimal version +// for our wrapper struct +impl Debug for AsyncInstrumentWrap<'_, T> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("AsyncInstrumentWrap").finish() + } +} + +#[derive(Debug)] struct MeterWrap(OtelMeter); impl Deref for MeterWrap { type Target = OtelMeter; diff --git a/rust-runtime/aws-smithy-observability/src/meter.rs b/rust-runtime/aws-smithy-observability/src/meter.rs index 3464fa21cf..b193ba5b94 100644 --- a/rust-runtime/aws-smithy-observability/src/meter.rs +++ b/rust-runtime/aws-smithy-observability/src/meter.rs @@ -7,9 +7,10 @@ //! real time. use crate::attributes::{Attributes, Context}; +use std::fmt::Debug; /// Provides named instances of [Meter]. -pub trait MeterProvider { +pub trait MeterProvider: Send + Sync + Debug { /// Get or create a named [Meter]. fn get_meter(&self, scope: &'static str, attributes: Option<&Attributes>) -> Box; @@ -18,7 +19,7 @@ pub trait MeterProvider { } /// The entry point to creating instruments. A grouping of related metrics. -pub trait Meter { +pub trait Meter: Send + Sync + Debug { /// Create a new Gauge. #[allow(clippy::type_complexity)] fn create_gauge( @@ -75,25 +76,25 @@ pub trait Meter { } /// Collects a set of events with an event count and sum for all events. -pub trait Histogram { +pub trait Histogram: Send + Sync + Debug { /// Record a value. fn record(&self, value: f64, attributes: Option<&Attributes>, context: Option<&dyn Context>); } /// A counter that monotonically increases. -pub trait MonotonicCounter { +pub trait MonotonicCounter: Send + Sync + Debug { /// Increment a counter by a fixed amount. fn add(&self, value: u64, attributes: Option<&Attributes>, context: Option<&dyn Context>); } /// A counter that can increase or decrease. -pub trait UpDownCounter { +pub trait UpDownCounter: Send + Sync + Debug { /// Increment or decrement a counter by a fixed amount. fn add(&self, value: i64, attributes: Option<&Attributes>, context: Option<&dyn Context>); } /// A measurement that can be taken asynchronously. -pub trait AsyncMeasurement { +pub trait AsyncMeasurement: Send + Sync + Debug { /// The type recorded by the measurement. type Value; diff --git a/rust-runtime/aws-smithy-observability/src/noop.rs b/rust-runtime/aws-smithy-observability/src/noop.rs index 291826a1c9..68777bf650 100644 --- a/rust-runtime/aws-smithy-observability/src/noop.rs +++ b/rust-runtime/aws-smithy-observability/src/noop.rs @@ -5,6 +5,7 @@ //! An noop implementation of the Meter traits +use std::fmt::Debug; use std::marker::PhantomData; use crate::{ @@ -12,6 +13,7 @@ use crate::{ meter::{AsyncMeasurement, Histogram, Meter, MeterProvider, MonotonicCounter, UpDownCounter}, }; +#[derive(Debug)] pub(crate) struct NoopMeterProvider; impl MeterProvider for NoopMeterProvider { fn get_meter(&self, _scope: &'static str, _attributes: Option<&Attributes>) -> Box { @@ -23,6 +25,7 @@ impl MeterProvider for NoopMeterProvider { } } +#[derive(Debug)] pub(crate) struct NoopMeter; impl Meter for NoopMeter { fn create_gauge( @@ -83,8 +86,9 @@ impl Meter for NoopMeter { } } -struct NoopAsyncMeasurement(PhantomData); -impl AsyncMeasurement for NoopAsyncMeasurement { +#[derive(Debug)] +struct NoopAsyncMeasurement(PhantomData); +impl AsyncMeasurement for NoopAsyncMeasurement { type Value = T; fn record(&self, _value: T, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {} @@ -92,16 +96,19 @@ impl AsyncMeasurement for NoopAsyncMeasurement { fn stop(&self) {} } +#[derive(Debug)] struct NoopUpDownCounter; impl UpDownCounter for NoopUpDownCounter { fn add(&self, _value: i64, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {} } +#[derive(Debug)] struct NoopMonotonicCounter; impl MonotonicCounter for NoopMonotonicCounter { fn add(&self, _value: u64, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {} } +#[derive(Debug)] struct NoopHistogram; impl Histogram for NoopHistogram { fn record(