From f1f5be264353b05d604c21287da6c611a28a1071 Mon Sep 17 00:00:00 2001 From: Landon James Date: Tue, 19 Nov 2024 14:52:21 -0800 Subject: [PATCH] Rename some traits to be more verby Aligns with standard introduced in https://github.com/smithy-lang/smithy-rs/pull/3065 Update doc comments External types updates --- .../external-types.toml | 4 +-- .../src/meter.rs | 34 +++++++++---------- .../aws-smithy-observability/src/meter.rs | 16 ++++----- .../aws-smithy-observability/src/noop.rs | 18 +++++----- .../aws-smithy-observability/src/provider.rs | 17 ++++------ 5 files changed, 43 insertions(+), 46 deletions(-) diff --git a/rust-runtime/aws-smithy-observability-otel/external-types.toml b/rust-runtime/aws-smithy-observability-otel/external-types.toml index 679141bfed..99ecd8de25 100644 --- a/rust-runtime/aws-smithy-observability-otel/external-types.toml +++ b/rust-runtime/aws-smithy-observability-otel/external-types.toml @@ -1,10 +1,10 @@ allowed_external_types = [ "aws_smithy_observability::error::ObservabilityError", - "aws_smithy_observability::meter::AsyncMeasurement", + "aws_smithy_observability::meter::AsyncMeasure", "aws_smithy_observability::meter::Histogram", "aws_smithy_observability::meter::Meter", - "aws_smithy_observability::meter::MeterProvider", "aws_smithy_observability::meter::MonotonicCounter", + "aws_smithy_observability::meter::ProvideMeter", "aws_smithy_observability::meter::UpDownCounter", "aws_smithy_observability::provider::TelemetryProvider", "opentelemetry_sdk::metrics::meter_provider::SdkMeterProvider", diff --git a/rust-runtime/aws-smithy-observability-otel/src/meter.rs b/rust-runtime/aws-smithy-observability-otel/src/meter.rs index 7ba85df9b9..c31af198cd 100644 --- a/rust-runtime/aws-smithy-observability-otel/src/meter.rs +++ b/rust-runtime/aws-smithy-observability-otel/src/meter.rs @@ -12,7 +12,7 @@ use crate::attributes::kv_from_option_attr; use aws_smithy_observability::attributes::{Attributes, Context}; use aws_smithy_observability::error::{ErrorKind, ObservabilityError}; pub use aws_smithy_observability::meter::{ - AsyncMeasurement, Histogram, Meter, MeterProvider, MonotonicCounter, UpDownCounter, + AsyncMeasure, Histogram, Meter, MonotonicCounter, ProvideMeter, UpDownCounter, }; pub use aws_smithy_observability::provider::TelemetryProvider; use opentelemetry::metrics::{ @@ -49,7 +49,7 @@ impl MonotonicCounter for MonotonicCounterWrap { #[derive(Debug)] struct GaugeWrap(OtelObservableGauge); -impl AsyncMeasurement for GaugeWrap { +impl AsyncMeasure for GaugeWrap { type Value = f64; fn record( @@ -68,7 +68,7 @@ impl AsyncMeasurement for GaugeWrap { #[derive(Debug)] struct AsyncUpDownCounterWrap(OtelObservableUpDownCounter); -impl AsyncMeasurement for AsyncUpDownCounterWrap { +impl AsyncMeasure for AsyncUpDownCounterWrap { type Value = i64; fn record( @@ -87,7 +87,7 @@ impl AsyncMeasurement for AsyncUpDownCounterWrap { #[derive(Debug)] struct AsyncMonotonicCounterWrap(OtelObservableCounter); -impl AsyncMeasurement for AsyncMonotonicCounterWrap { +impl AsyncMeasure for AsyncMonotonicCounterWrap { type Value = u64; fn record( @@ -105,7 +105,7 @@ impl AsyncMeasurement for AsyncMonotonicCounterWrap { } struct AsyncInstrumentWrap<'a, T>(&'a (dyn OtelAsyncInstrument + Send + Sync)); -impl AsyncMeasurement for AsyncInstrumentWrap<'_, T> { +impl AsyncMeasure for AsyncInstrumentWrap<'_, T> { type Value = T; fn record( @@ -144,10 +144,10 @@ impl Meter for MeterWrap { fn create_gauge( &self, name: String, - callback: Box) + Send + Sync>, + callback: Box) + Send + Sync>, units: Option, description: Option, - ) -> Box> { + ) -> Box> { let mut builder = self.f64_observable_gauge(name).with_callback( move |input: &dyn OtelAsyncInstrument| { callback(&AsyncInstrumentWrap(input)); @@ -186,10 +186,10 @@ impl Meter for MeterWrap { fn create_async_up_down_counter( &self, name: String, - callback: Box) + Send + Sync>, + callback: Box) + Send + Sync>, units: Option, description: Option, - ) -> Box> { + ) -> Box> { let mut builder = self.i64_observable_up_down_counter(name).with_callback( move |input: &dyn OtelAsyncInstrument| { callback(&AsyncInstrumentWrap(input)); @@ -228,10 +228,10 @@ impl Meter for MeterWrap { fn create_async_monotonic_counter( &self, name: String, - callback: Box) + Send + Sync>, + callback: Box) + Send + Sync>, units: Option, description: Option, - ) -> Box> { + ) -> Box> { let mut builder = self.u64_observable_counter(name).with_callback( move |input: &dyn OtelAsyncInstrument| { callback(&AsyncInstrumentWrap(input)); @@ -268,7 +268,7 @@ impl Meter for MeterWrap { } } -/// An OpenTelemetry based implementation of the AWS SDK's [MeterProvider] trait +/// An OpenTelemetry based implementation of the AWS SDK's [ProvideMeter] trait #[non_exhaustive] #[derive(Debug)] pub struct AwsSdkOtelMeterProvider { @@ -300,7 +300,7 @@ impl AwsSdkOtelMeterProvider { } } -impl MeterProvider for AwsSdkOtelMeterProvider { +impl ProvideMeter for AwsSdkOtelMeterProvider { fn get_meter(&self, scope: &'static str, _attributes: Option<&Attributes>) -> Box { Box::new(MeterWrap(self.meter_provider.meter(scope))) } @@ -314,7 +314,7 @@ impl MeterProvider for AwsSdkOtelMeterProvider { mod tests { use aws_smithy_observability::attributes::{AttributeValue, Attributes}; - use aws_smithy_observability::meter::AsyncMeasurement; + use aws_smithy_observability::meter::AsyncMeasure; use aws_smithy_observability::provider::TelemetryProvider; use opentelemetry_sdk::metrics::{ data::{Gauge, Histogram, Sum}, @@ -408,7 +408,7 @@ mod tests { let gauge = dyn_sdk_meter.create_gauge( "TestGauge".to_string(), // Callback function records another value with different attributes so it is deduped - Box::new(|measurement: &dyn AsyncMeasurement| { + Box::new(|measurement: &dyn AsyncMeasure| { let mut attrs = Attributes::new(); attrs.set( "TestGaugeAttr", @@ -423,7 +423,7 @@ mod tests { let async_ud_counter = dyn_sdk_meter.create_async_up_down_counter( "TestAsyncUpDownCounter".to_string(), - Box::new(|measurement: &dyn AsyncMeasurement| { + Box::new(|measurement: &dyn AsyncMeasure| { let mut attrs = Attributes::new(); attrs.set( "TestAsyncUpDownCounterAttr", @@ -438,7 +438,7 @@ mod tests { let async_mono_counter = dyn_sdk_meter.create_async_monotonic_counter( "TestAsyncMonoCounter".to_string(), - Box::new(|measurement: &dyn AsyncMeasurement| { + Box::new(|measurement: &dyn AsyncMeasure| { let mut attrs = Attributes::new(); attrs.set( "TestAsyncMonoCounterAttr", diff --git a/rust-runtime/aws-smithy-observability/src/meter.rs b/rust-runtime/aws-smithy-observability/src/meter.rs index b193ba5b94..41a8ca570e 100644 --- a/rust-runtime/aws-smithy-observability/src/meter.rs +++ b/rust-runtime/aws-smithy-observability/src/meter.rs @@ -10,7 +10,7 @@ use crate::attributes::{Attributes, Context}; use std::fmt::Debug; /// Provides named instances of [Meter]. -pub trait MeterProvider: Send + Sync + Debug { +pub trait ProvideMeter: Send + Sync + Debug { /// Get or create a named [Meter]. fn get_meter(&self, scope: &'static str, attributes: Option<&Attributes>) -> Box; @@ -25,10 +25,10 @@ pub trait Meter: Send + Sync + Debug { fn create_gauge( &self, name: String, - callback: Box) + Send + Sync>, + callback: Box) + Send + Sync>, units: Option, description: Option, - ) -> Box>; + ) -> Box>; /// Create a new [UpDownCounter]. fn create_up_down_counter( @@ -43,10 +43,10 @@ pub trait Meter: Send + Sync + Debug { fn create_async_up_down_counter( &self, name: String, - callback: Box) + Send + Sync>, + callback: Box) + Send + Sync>, units: Option, description: Option, - ) -> Box>; + ) -> Box>; /// Create a new [MonotonicCounter]. fn create_monotonic_counter( @@ -61,10 +61,10 @@ pub trait Meter: Send + Sync + Debug { fn create_async_monotonic_counter( &self, name: String, - callback: Box) + Send + Sync>, + callback: Box) + Send + Sync>, units: Option, description: Option, - ) -> Box>; + ) -> Box>; /// Create a new [Histogram]. fn create_histogram( @@ -94,7 +94,7 @@ pub trait UpDownCounter: Send + Sync + Debug { } /// A measurement that can be taken asynchronously. -pub trait AsyncMeasurement: Send + Sync + Debug { +pub trait AsyncMeasure: 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 68777bf650..3d23c763ad 100644 --- a/rust-runtime/aws-smithy-observability/src/noop.rs +++ b/rust-runtime/aws-smithy-observability/src/noop.rs @@ -10,12 +10,12 @@ use std::marker::PhantomData; use crate::{ attributes::{Attributes, Context}, - meter::{AsyncMeasurement, Histogram, Meter, MeterProvider, MonotonicCounter, UpDownCounter}, + meter::{AsyncMeasure, Histogram, Meter, MonotonicCounter, ProvideMeter, UpDownCounter}, }; #[derive(Debug)] pub(crate) struct NoopMeterProvider; -impl MeterProvider for NoopMeterProvider { +impl ProvideMeter for NoopMeterProvider { fn get_meter(&self, _scope: &'static str, _attributes: Option<&Attributes>) -> Box { Box::new(NoopMeter) } @@ -31,10 +31,10 @@ impl Meter for NoopMeter { fn create_gauge( &self, _name: String, - _callback: Box) + Send + Sync>, + _callback: Box) + Send + Sync>, _units: Option, _description: Option, - ) -> Box> { + ) -> Box> { Box::new(NoopAsyncMeasurement(PhantomData::)) } @@ -50,10 +50,10 @@ impl Meter for NoopMeter { fn create_async_up_down_counter( &self, _name: String, - _callback: Box) + Send + Sync>, + _callback: Box) + Send + Sync>, _units: Option, _description: Option, - ) -> Box> { + ) -> Box> { Box::new(NoopAsyncMeasurement(PhantomData::)) } @@ -69,10 +69,10 @@ impl Meter for NoopMeter { fn create_async_monotonic_counter( &self, _name: String, - _callback: Box) + Send + Sync>, + _callback: Box) + Send + Sync>, _units: Option, _description: Option, - ) -> Box> { + ) -> Box> { Box::new(NoopAsyncMeasurement(PhantomData::)) } @@ -88,7 +88,7 @@ impl Meter for NoopMeter { #[derive(Debug)] struct NoopAsyncMeasurement(PhantomData); -impl AsyncMeasurement for NoopAsyncMeasurement { +impl AsyncMeasure for NoopAsyncMeasurement { type Value = T; fn record(&self, _value: T, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {} diff --git a/rust-runtime/aws-smithy-observability/src/provider.rs b/rust-runtime/aws-smithy-observability/src/provider.rs index 12fc0f91ea..43b244f8d8 100644 --- a/rust-runtime/aws-smithy-observability/src/provider.rs +++ b/rust-runtime/aws-smithy-observability/src/provider.rs @@ -7,12 +7,12 @@ use std::sync::Arc; -use crate::{meter::MeterProvider, noop::NoopMeterProvider}; +use crate::{meter::ProvideMeter, noop::NoopMeterProvider}; /// A struct to hold the various types of telemetry providers. #[non_exhaustive] pub struct TelemetryProvider { - meter_provider: Box, + meter_provider: Box, } impl TelemetryProvider { @@ -30,8 +30,8 @@ impl TelemetryProvider { } } - /// Get the set [MeterProvider] - pub fn meter_provider(&self) -> &(dyn MeterProvider + Send + Sync) { + /// Get the set [ProvideMeter] + pub fn meter_provider(&self) -> &(dyn ProvideMeter + Send + Sync) { self.meter_provider.as_ref() } } @@ -51,15 +51,12 @@ impl Default for TelemetryProvider { /// A builder for [TelemetryProvider]. #[non_exhaustive] pub struct TelemetryProviderBuilder { - meter_provider: Box, + meter_provider: Box, } impl TelemetryProviderBuilder { - /// Set the [MeterProvider]. - pub fn meter_provider( - mut self, - meter_provider: impl MeterProvider + Send + Sync + 'static, - ) -> Self { + /// Set the [ProvideMeter]. + pub fn meter_provider(mut self, meter_provider: impl ProvideMeter + 'static) -> Self { self.meter_provider = Box::new(meter_provider); self }