Skip to content

Commit

Permalink
Rename some traits to be more verby
Browse files Browse the repository at this point in the history
Aligns with standard introduced in #3065

Update doc comments

External types updates
  • Loading branch information
landonxjames committed Nov 19, 2024
1 parent fe50a9d commit f1f5be2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
34 changes: 17 additions & 17 deletions rust-runtime/aws-smithy-observability-otel/src/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -49,7 +49,7 @@ impl MonotonicCounter for MonotonicCounterWrap {

#[derive(Debug)]
struct GaugeWrap(OtelObservableGauge<f64>);
impl AsyncMeasurement for GaugeWrap {
impl AsyncMeasure for GaugeWrap {
type Value = f64;

fn record(
Expand All @@ -68,7 +68,7 @@ impl AsyncMeasurement for GaugeWrap {

#[derive(Debug)]
struct AsyncUpDownCounterWrap(OtelObservableUpDownCounter<i64>);
impl AsyncMeasurement for AsyncUpDownCounterWrap {
impl AsyncMeasure for AsyncUpDownCounterWrap {
type Value = i64;

fn record(
Expand All @@ -87,7 +87,7 @@ impl AsyncMeasurement for AsyncUpDownCounterWrap {

#[derive(Debug)]
struct AsyncMonotonicCounterWrap(OtelObservableCounter<u64>);
impl AsyncMeasurement for AsyncMonotonicCounterWrap {
impl AsyncMeasure for AsyncMonotonicCounterWrap {
type Value = u64;

fn record(
Expand All @@ -105,7 +105,7 @@ impl AsyncMeasurement for AsyncMonotonicCounterWrap {
}

struct AsyncInstrumentWrap<'a, T>(&'a (dyn OtelAsyncInstrument<T> + Send + Sync));
impl<T> AsyncMeasurement for AsyncInstrumentWrap<'_, T> {
impl<T> AsyncMeasure for AsyncInstrumentWrap<'_, T> {
type Value = T;

fn record(
Expand Down Expand Up @@ -144,10 +144,10 @@ impl Meter for MeterWrap {
fn create_gauge(
&self,
name: String,
callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = f64>) + Send + Sync>,
callback: Box<dyn Fn(&dyn AsyncMeasure<Value = f64>) + Send + Sync>,
units: Option<String>,
description: Option<String>,
) -> Box<dyn AsyncMeasurement<Value = f64>> {
) -> Box<dyn AsyncMeasure<Value = f64>> {
let mut builder = self.f64_observable_gauge(name).with_callback(
move |input: &dyn OtelAsyncInstrument<f64>| {
callback(&AsyncInstrumentWrap(input));
Expand Down Expand Up @@ -186,10 +186,10 @@ impl Meter for MeterWrap {
fn create_async_up_down_counter(
&self,
name: String,
callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = i64>) + Send + Sync>,
callback: Box<dyn Fn(&dyn AsyncMeasure<Value = i64>) + Send + Sync>,
units: Option<String>,
description: Option<String>,
) -> Box<dyn AsyncMeasurement<Value = i64>> {
) -> Box<dyn AsyncMeasure<Value = i64>> {
let mut builder = self.i64_observable_up_down_counter(name).with_callback(
move |input: &dyn OtelAsyncInstrument<i64>| {
callback(&AsyncInstrumentWrap(input));
Expand Down Expand Up @@ -228,10 +228,10 @@ impl Meter for MeterWrap {
fn create_async_monotonic_counter(
&self,
name: String,
callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = u64>) + Send + Sync>,
callback: Box<dyn Fn(&dyn AsyncMeasure<Value = u64>) + Send + Sync>,
units: Option<String>,
description: Option<String>,
) -> Box<dyn AsyncMeasurement<Value = u64>> {
) -> Box<dyn AsyncMeasure<Value = u64>> {
let mut builder = self.u64_observable_counter(name).with_callback(
move |input: &dyn OtelAsyncInstrument<u64>| {
callback(&AsyncInstrumentWrap(input));
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<dyn Meter> {
Box::new(MeterWrap(self.meter_provider.meter(scope)))
}
Expand All @@ -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},
Expand Down Expand Up @@ -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<Value = f64>| {
Box::new(|measurement: &dyn AsyncMeasure<Value = f64>| {
let mut attrs = Attributes::new();
attrs.set(
"TestGaugeAttr",
Expand All @@ -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<Value = i64>| {
Box::new(|measurement: &dyn AsyncMeasure<Value = i64>| {
let mut attrs = Attributes::new();
attrs.set(
"TestAsyncUpDownCounterAttr",
Expand All @@ -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<Value = u64>| {
Box::new(|measurement: &dyn AsyncMeasure<Value = u64>| {
let mut attrs = Attributes::new();
attrs.set(
"TestAsyncMonoCounterAttr",
Expand Down
16 changes: 8 additions & 8 deletions rust-runtime/aws-smithy-observability/src/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Meter>;

Expand All @@ -25,10 +25,10 @@ pub trait Meter: Send + Sync + Debug {
fn create_gauge(
&self,
name: String,
callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = f64>) + Send + Sync>,
callback: Box<dyn Fn(&dyn AsyncMeasure<Value = f64>) + Send + Sync>,
units: Option<String>,
description: Option<String>,
) -> Box<dyn AsyncMeasurement<Value = f64>>;
) -> Box<dyn AsyncMeasure<Value = f64>>;

/// Create a new [UpDownCounter].
fn create_up_down_counter(
Expand All @@ -43,10 +43,10 @@ pub trait Meter: Send + Sync + Debug {
fn create_async_up_down_counter(
&self,
name: String,
callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = i64>) + Send + Sync>,
callback: Box<dyn Fn(&dyn AsyncMeasure<Value = i64>) + Send + Sync>,
units: Option<String>,
description: Option<String>,
) -> Box<dyn AsyncMeasurement<Value = i64>>;
) -> Box<dyn AsyncMeasure<Value = i64>>;

/// Create a new [MonotonicCounter].
fn create_monotonic_counter(
Expand All @@ -61,10 +61,10 @@ pub trait Meter: Send + Sync + Debug {
fn create_async_monotonic_counter(
&self,
name: String,
callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = u64>) + Send + Sync>,
callback: Box<dyn Fn(&dyn AsyncMeasure<Value = u64>) + Send + Sync>,
units: Option<String>,
description: Option<String>,
) -> Box<dyn AsyncMeasurement<Value = u64>>;
) -> Box<dyn AsyncMeasure<Value = u64>>;

/// Create a new [Histogram].
fn create_histogram(
Expand Down Expand Up @@ -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;

Expand Down
18 changes: 9 additions & 9 deletions rust-runtime/aws-smithy-observability/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Meter> {
Box::new(NoopMeter)
}
Expand All @@ -31,10 +31,10 @@ impl Meter for NoopMeter {
fn create_gauge(
&self,
_name: String,
_callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = f64>) + Send + Sync>,
_callback: Box<dyn Fn(&dyn AsyncMeasure<Value = f64>) + Send + Sync>,
_units: Option<String>,
_description: Option<String>,
) -> Box<dyn AsyncMeasurement<Value = f64>> {
) -> Box<dyn AsyncMeasure<Value = f64>> {
Box::new(NoopAsyncMeasurement(PhantomData::<f64>))
}

Expand All @@ -50,10 +50,10 @@ impl Meter for NoopMeter {
fn create_async_up_down_counter(
&self,
_name: String,
_callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = i64>) + Send + Sync>,
_callback: Box<dyn Fn(&dyn AsyncMeasure<Value = i64>) + Send + Sync>,
_units: Option<String>,
_description: Option<String>,
) -> Box<dyn AsyncMeasurement<Value = i64>> {
) -> Box<dyn AsyncMeasure<Value = i64>> {
Box::new(NoopAsyncMeasurement(PhantomData::<i64>))
}

Expand All @@ -69,10 +69,10 @@ impl Meter for NoopMeter {
fn create_async_monotonic_counter(
&self,
_name: String,
_callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = u64>) + Send + Sync>,
_callback: Box<dyn Fn(&dyn AsyncMeasure<Value = u64>) + Send + Sync>,
_units: Option<String>,
_description: Option<String>,
) -> Box<dyn AsyncMeasurement<Value = u64>> {
) -> Box<dyn AsyncMeasure<Value = u64>> {
Box::new(NoopAsyncMeasurement(PhantomData::<u64>))
}

Expand All @@ -88,7 +88,7 @@ impl Meter for NoopMeter {

#[derive(Debug)]
struct NoopAsyncMeasurement<T: Send + Sync + Debug>(PhantomData<T>);
impl<T: Send + Sync + Debug> AsyncMeasurement for NoopAsyncMeasurement<T> {
impl<T: Send + Sync + Debug> AsyncMeasure for NoopAsyncMeasurement<T> {
type Value = T;

fn record(&self, _value: T, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {}
Expand Down
17 changes: 7 additions & 10 deletions rust-runtime/aws-smithy-observability/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn MeterProvider + Send + Sync>,
meter_provider: Box<dyn ProvideMeter + Send + Sync>,
}

impl TelemetryProvider {
Expand All @@ -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()
}
}
Expand All @@ -51,15 +51,12 @@ impl Default for TelemetryProvider {
/// A builder for [TelemetryProvider].
#[non_exhaustive]
pub struct TelemetryProviderBuilder {
meter_provider: Box<dyn MeterProvider + Send + Sync>,
meter_provider: Box<dyn ProvideMeter + Send + Sync>,
}

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
}
Expand Down

0 comments on commit f1f5be2

Please sign in to comment.