AWS SDK

AWS SDK

rev. fe50a9dd499faa70ec4be9ad3bcc43bd13785b4c

Files changed:

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-observability/README.md

@@ -0,1 +0,7 @@
           1  +
# aws-smithy-observability
           2  +
           3  +
This crate contains traits allowing for the implementation of `TelemetryProvider`s for the AWS SDK for Rust. It also contains a `global` module for setting and interacting with the current `GlobalTelemetryProvider`.
           4  +
           5  +
<!-- anchor_start:footer -->
           6  +
This crate is part of the [AWS SDK for Rust](https://awslabs.github.io/aws-sdk-rust/) and the [smithy-rs](https://github.com/smithy-lang/smithy-rs) code generator. In most cases, it should not be used directly.
           7  +
<!-- anchor_end:footer -->

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-observability/external-types.toml

@@ -0,1 +0,3 @@
           1  +
allowed_external_types = [
           2  +
    "aws_smithy_runtime_api::box_error::BoxError",
           3  +
]

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-observability/src/attributes.rs

@@ -0,1 +0,88 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! Attributes (also referred to as tags or annotations in other telemetry systems) are structured
           7  +
//! key-value pairs that annotate a span or event. Structured data allows observability backends
           8  +
//! to index and process telemetry data in ways that simple log messages lack.
           9  +
          10  +
use std::collections::HashMap;
          11  +
          12  +
/// The valid types of values accepted by [Attributes].
          13  +
#[non_exhaustive]
          14  +
#[derive(Clone, Debug, PartialEq)]
          15  +
pub enum AttributeValue {
          16  +
    /// Holds an [i64]
          17  +
    I64(i64),
          18  +
    /// Holds an [f64]
          19  +
    F64(f64),
          20  +
    /// Holds a [String]
          21  +
    String(String),
          22  +
    /// Holds a [bool]
          23  +
    Bool(bool),
          24  +
}
          25  +
          26  +
/// Structured telemetry metadata.
          27  +
#[non_exhaustive]
          28  +
#[derive(Clone)]
          29  +
pub struct Attributes {
          30  +
    attrs: HashMap<String, AttributeValue>,
          31  +
}
          32  +
          33  +
impl Attributes {
          34  +
    /// Create a new empty instance of [Attributes].
          35  +
    pub fn new() -> Self {
          36  +
        Self {
          37  +
            attrs: HashMap::new(),
          38  +
        }
          39  +
    }
          40  +
          41  +
    /// Set an attribute.
          42  +
    pub fn set(&mut self, key: impl Into<String>, value: impl Into<AttributeValue>) {
          43  +
        self.attrs.insert(key.into(), value.into());
          44  +
    }
          45  +
          46  +
    /// Get an attribute.
          47  +
    pub fn get(&self, key: impl Into<String>) -> Option<&AttributeValue> {
          48  +
        self.attrs.get(&key.into())
          49  +
    }
          50  +
          51  +
    /// Get all of the attribute key value pairs.
          52  +
    pub fn attributes(&self) -> &HashMap<String, AttributeValue> {
          53  +
        &self.attrs
          54  +
    }
          55  +
          56  +
    /// Get an owned [Iterator] of ([String], [AttributeValue]).
          57  +
    pub fn into_attributes(self) -> impl Iterator<Item = (String, AttributeValue)> {
          58  +
        self.attrs.into_iter()
          59  +
    }
          60  +
}
          61  +
          62  +
impl Default for Attributes {
          63  +
    fn default() -> Self {
          64  +
        Self::new()
          65  +
    }
          66  +
}
          67  +
          68  +
/// Delineates a logical scope that has some beginning and end
          69  +
/// (e.g. a function or block of code).
          70  +
pub trait Scope {
          71  +
    /// invoke when the scope has ended.
          72  +
    fn end(&self);
          73  +
}
          74  +
          75  +
/// A cross cutting concern for carrying execution-scoped values across API
          76  +
/// boundaries (both in-process and distributed).
          77  +
pub trait Context {
          78  +
    /// Make this context the currently active context.
          79  +
    /// The returned handle is used to return the previous
          80  +
    /// context (if one existed) as active.
          81  +
    fn make_current(&self) -> &dyn Scope;
          82  +
}
          83  +
          84  +
/// Keeps track of the current [Context].
          85  +
pub trait ContextManager {
          86  +
    ///Get the currently active context.
          87  +
    fn current(&self) -> &dyn Context;
          88  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-observability/src/error.rs

@@ -0,1 +0,69 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! Observability Errors
           7  +
           8  +
use std::fmt;
           9  +
          10  +
use aws_smithy_runtime_api::box_error::BoxError;
          11  +
          12  +
/// An error in the SDKs Observability providers
          13  +
#[non_exhaustive]
          14  +
#[derive(Debug)]
          15  +
pub struct ObservabilityError {
          16  +
    kind: ErrorKind,
          17  +
    source: BoxError,
          18  +
}
          19  +
          20  +
/// The types of errors associated with [ObservabilityError]
          21  +
#[non_exhaustive]
          22  +
#[derive(Debug)]
          23  +
pub enum ErrorKind {
          24  +
    /// An error setting the `GlobalTelemetryProvider``
          25  +
    SettingGlobalProvider,
          26  +
    /// Error flushing metrics pipeline
          27  +
    MetricsFlush,
          28  +
    /// Error gracefully shutting down Metrics Provider
          29  +
    MetricsShutdown,
          30  +
    /// A custom error that does not fall under any other error kind
          31  +
    Other,
          32  +
}
          33  +
          34  +
impl ObservabilityError {
          35  +
    /// Create a new [`ObservabilityError`] from an [ErrorKind] and a [BoxError]
          36  +
    pub fn new<E>(kind: ErrorKind, err: E) -> Self
          37  +
    where
          38  +
        E: Into<BoxError>,
          39  +
    {
          40  +
        Self {
          41  +
            kind,
          42  +
            source: err.into(),
          43  +
        }
          44  +
    }
          45  +
          46  +
    /// Returns the corresponding [`ErrorKind`] for this error.
          47  +
    pub fn kind(&self) -> &ErrorKind {
          48  +
        &self.kind
          49  +
    }
          50  +
}
          51  +
          52  +
impl fmt::Display for ObservabilityError {
          53  +
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
          54  +
        match &self.kind {
          55  +
            ErrorKind::Other => write!(f, "unclassified error"),
          56  +
            ErrorKind::SettingGlobalProvider => {
          57  +
                write!(f, "failed to set global telemetry provider")
          58  +
            }
          59  +
            ErrorKind::MetricsFlush => write!(f, "failed to flush metrics pipeline"),
          60  +
            ErrorKind::MetricsShutdown => write!(f, "failed to shutdown metrics provider"),
          61  +
        }
          62  +
    }
          63  +
}
          64  +
          65  +
impl std::error::Error for ObservabilityError {
          66  +
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
          67  +
        Some(self.source.as_ref())
          68  +
    }
          69  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-observability/src/global.rs

@@ -0,1 +0,77 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! Utilities for interacting with the currently set `GlobalTelemetryProvider`
           7  +
           8  +
use once_cell::sync::Lazy;
           9  +
use std::{
          10  +
    mem,
          11  +
    sync::{Arc, RwLock},
          12  +
};
          13  +
          14  +
use crate::provider::{GlobalTelemetryProvider, TelemetryProvider};
          15  +
          16  +
// Statically store the global provider
          17  +
static GLOBAL_TELEMETRY_PROVIDER: Lazy<RwLock<GlobalTelemetryProvider>> =
          18  +
    Lazy::new(|| RwLock::new(GlobalTelemetryProvider::new(TelemetryProvider::default())));
          19  +
          20  +
/// Set the current global [TelemetryProvider].
          21  +
///
          22  +
/// This is meant to be run once at the beginning of an application. It will panic if two threads
          23  +
/// attempt to call it at the same time.
          24  +
pub fn set_telemetry_provider(new_provider: TelemetryProvider) {
          25  +
    // TODO(smithyObservability): would probably be nicer to return a Result here, but the Guard held by the error from
          26  +
    // .try_write is not Send so I struggled to build an ObservabilityError from it
          27  +
    let mut old_provider = GLOBAL_TELEMETRY_PROVIDER
          28  +
        .try_write()
          29  +
        .expect("GLOBAL_TELEMETRY_PROVIDER RwLock Poisoned");
          30  +
          31  +
    let new_global_provider = GlobalTelemetryProvider::new(new_provider);
          32  +
          33  +
    let _ = mem::replace(&mut *old_provider, new_global_provider);
          34  +
}
          35  +
          36  +
/// Get an [Arc] reference to the current global [TelemetryProvider].
          37  +
///
          38  +
/// This can panic if called when another thread is calling [set_telemetry_provider].
          39  +
pub fn get_telemetry_provider() -> Arc<TelemetryProvider> {
          40  +
    // TODO(smithyObservability): would probably be nicer to return a Result here, but the Guard held by the error from
          41  +
    // .try_read is not Send so I struggled to build an ObservabilityError from it
          42  +
    GLOBAL_TELEMETRY_PROVIDER
          43  +
        .try_read()
          44  +
        .expect("GLOBAL_TELEMETRY_PROVIDER RwLock Poisoned")
          45  +
        .telemetry_provider()
          46  +
        .clone()
          47  +
}
          48  +
          49  +
#[cfg(test)]
          50  +
mod tests {
          51  +
    use super::*;
          52  +
    use crate::provider::TelemetryProvider;
          53  +
    use serial_test::serial;
          54  +
          55  +
    // Note: the tests in this module are run serially to prevent them from stepping on each other and poisoning the
          56  +
    // RwLock holding the GlobalTelemetryProvider
          57  +
    #[test]
          58  +
    #[serial]
          59  +
    fn can_set_global_telemetry_provider() {
          60  +
        let my_provider = TelemetryProvider::default();
          61  +
          62  +
        // Set the new counter and get a reference to the old one
          63  +
        set_telemetry_provider(my_provider);
          64  +
    }
          65  +
          66  +
    #[test]
          67  +
    #[serial]
          68  +
    fn can_get_global_telemetry_provider() {
          69  +
        let curr_provider = get_telemetry_provider();
          70  +
          71  +
        // Use the global provider to create an instrument and record a value with it
          72  +
        let curr_mp = curr_provider.meter_provider();
          73  +
        let curr_meter = curr_mp.get_meter("TestMeter", None);
          74  +
        let instrument = curr_meter.create_monotonic_counter("TestMonoCounter".into(), None, None);
          75  +
        instrument.add(4, None, None);
          76  +
    }
          77  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-observability/src/lib.rs

@@ -0,1 +0,28 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
/* Automatically managed default lints */
           7  +
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
           8  +
/* End of automatically managed default lints */
           9  +
#![warn(
          10  +
    missing_docs,
          11  +
    rustdoc::missing_crate_level_docs,
          12  +
    unreachable_pub,
          13  +
    rust_2018_idioms
          14  +
)]
          15  +
          16  +
//! Smithy Observability
          17  +
// TODO(smithyobservability): once we have finalized everything and integrated metrics with our runtime
          18  +
// libraries update this with detailed usage docs and examples
          19  +
          20  +
pub mod attributes;
          21  +
pub use attributes::{AttributeValue, Attributes};
          22  +
pub mod error;
          23  +
pub use error::{ErrorKind, ObservabilityError};
          24  +
pub mod global;
          25  +
pub mod meter;
          26  +
mod noop;
          27  +
pub mod provider;
          28  +
pub use provider::{TelemetryProvider, TelemetryProviderBuilder};

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-observability/src/meter.rs

@@ -0,1 +0,111 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! Metrics are used to gain insight into the operational performance and health of a system in
           7  +
//! real time.
           8  +
           9  +
use crate::attributes::{Attributes, Context};
          10  +
use std::fmt::Debug;
          11  +
          12  +
/// Provides named instances of [Meter].
          13  +
pub trait MeterProvider: Send + Sync + Debug {
          14  +
    /// Get or create a named [Meter].
          15  +
    fn get_meter(&self, scope: &'static str, attributes: Option<&Attributes>) -> Box<dyn Meter>;
          16  +
          17  +
    /// Foo
          18  +
    fn as_any(&self) -> &dyn std::any::Any;
          19  +
}
          20  +
          21  +
/// The entry point to creating instruments. A grouping of related metrics.
          22  +
pub trait Meter: Send + Sync + Debug {
          23  +
    /// Create a new Gauge.
          24  +
    #[allow(clippy::type_complexity)]
          25  +
    fn create_gauge(
          26  +
        &self,
          27  +
        name: String,
          28  +
        callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = f64>) + Send + Sync>,
          29  +
        units: Option<String>,
          30  +
        description: Option<String>,
          31  +
    ) -> Box<dyn AsyncMeasurement<Value = f64>>;
          32  +
          33  +
    /// Create a new [UpDownCounter].
          34  +
    fn create_up_down_counter(
          35  +
        &self,
          36  +
        name: String,
          37  +
        units: Option<String>,
          38  +
        description: Option<String>,
          39  +
    ) -> Box<dyn UpDownCounter>;
          40  +
          41  +
    /// Create a new AsyncUpDownCounter.
          42  +
    #[allow(clippy::type_complexity)]
          43  +
    fn create_async_up_down_counter(
          44  +
        &self,
          45  +
        name: String,
          46  +
        callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = i64>) + Send + Sync>,
          47  +
        units: Option<String>,
          48  +
        description: Option<String>,
          49  +
    ) -> Box<dyn AsyncMeasurement<Value = i64>>;
          50  +
          51  +
    /// Create a new [MonotonicCounter].
          52  +
    fn create_monotonic_counter(
          53  +
        &self,
          54  +
        name: String,
          55  +
        units: Option<String>,
          56  +
        description: Option<String>,
          57  +
    ) -> Box<dyn MonotonicCounter>;
          58  +
          59  +
    /// Create a new AsyncMonotonicCounter.
          60  +
    #[allow(clippy::type_complexity)]
          61  +
    fn create_async_monotonic_counter(
          62  +
        &self,
          63  +
        name: String,
          64  +
        callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = u64>) + Send + Sync>,
          65  +
        units: Option<String>,
          66  +
        description: Option<String>,
          67  +
    ) -> Box<dyn AsyncMeasurement<Value = u64>>;
          68  +
          69  +
    /// Create a new [Histogram].
          70  +
    fn create_histogram(
          71  +
        &self,
          72  +
        name: String,
          73  +
        units: Option<String>,
          74  +
        description: Option<String>,
          75  +
    ) -> Box<dyn Histogram>;
          76  +
}
          77  +
          78  +
/// Collects a set of events with an event count and sum for all events.
          79  +
pub trait Histogram: Send + Sync + Debug {
          80  +
    /// Record a value.
          81  +
    fn record(&self, value: f64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
          82  +
}
          83  +
          84  +
/// A counter that monotonically increases.
          85  +
pub trait MonotonicCounter: Send + Sync + Debug {
          86  +
    /// Increment a counter by a fixed amount.
          87  +
    fn add(&self, value: u64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
          88  +
}
          89  +
          90  +
/// A counter that can increase or decrease.
          91  +
pub trait UpDownCounter: Send + Sync + Debug {
          92  +
    /// Increment or decrement a counter by a fixed amount.
          93  +
    fn add(&self, value: i64, attributes: Option<&Attributes>, context: Option<&dyn Context>);
          94  +
}
          95  +
          96  +
/// A measurement that can be taken asynchronously.
          97  +
pub trait AsyncMeasurement: Send + Sync + Debug {
          98  +
    /// The type recorded by the measurement.
          99  +
    type Value;
         100  +
         101  +
    /// Record a value
         102  +
    fn record(
         103  +
        &self,
         104  +
        value: Self::Value,
         105  +
        attributes: Option<&Attributes>,
         106  +
        context: Option<&dyn Context>,
         107  +
    );
         108  +
         109  +
    /// Stop recording , unregister callback.
         110  +
    fn stop(&self);
         111  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-observability/src/noop.rs

@@ -0,1 +0,121 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! An noop implementation of the Meter traits
           7  +
           8  +
use std::fmt::Debug;
           9  +
use std::marker::PhantomData;
          10  +
          11  +
use crate::{
          12  +
    attributes::{Attributes, Context},
          13  +
    meter::{AsyncMeasurement, Histogram, Meter, MeterProvider, MonotonicCounter, UpDownCounter},
          14  +
};
          15  +
          16  +
#[derive(Debug)]
          17  +
pub(crate) struct NoopMeterProvider;
          18  +
impl MeterProvider for NoopMeterProvider {
          19  +
    fn get_meter(&self, _scope: &'static str, _attributes: Option<&Attributes>) -> Box<dyn Meter> {
          20  +
        Box::new(NoopMeter)
          21  +
    }
          22  +
          23  +
    fn as_any(&self) -> &dyn std::any::Any {
          24  +
        self
          25  +
    }
          26  +
}
          27  +
          28  +
#[derive(Debug)]
          29  +
pub(crate) struct NoopMeter;
          30  +
impl Meter for NoopMeter {
          31  +
    fn create_gauge(
          32  +
        &self,
          33  +
        _name: String,
          34  +
        _callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = f64>) + Send + Sync>,
          35  +
        _units: Option<String>,
          36  +
        _description: Option<String>,
          37  +
    ) -> Box<dyn AsyncMeasurement<Value = f64>> {
          38  +
        Box::new(NoopAsyncMeasurement(PhantomData::<f64>))
          39  +
    }
          40  +
          41  +
    fn create_up_down_counter(
          42  +
        &self,
          43  +
        _name: String,
          44  +
        _units: Option<String>,
          45  +
        _description: Option<String>,
          46  +
    ) -> Box<dyn UpDownCounter> {
          47  +
        Box::new(NoopUpDownCounter)
          48  +
    }
          49  +
          50  +
    fn create_async_up_down_counter(
          51  +
        &self,
          52  +
        _name: String,
          53  +
        _callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = i64>) + Send + Sync>,
          54  +
        _units: Option<String>,
          55  +
        _description: Option<String>,
          56  +
    ) -> Box<dyn AsyncMeasurement<Value = i64>> {
          57  +
        Box::new(NoopAsyncMeasurement(PhantomData::<i64>))
          58  +
    }
          59  +
          60  +
    fn create_monotonic_counter(
          61  +
        &self,
          62  +
        _name: String,
          63  +
        _units: Option<String>,
          64  +
        _description: Option<String>,
          65  +
    ) -> Box<dyn MonotonicCounter> {
          66  +
        Box::new(NoopMonotonicCounter)
          67  +
    }
          68  +
          69  +
    fn create_async_monotonic_counter(
          70  +
        &self,
          71  +
        _name: String,
          72  +
        _callback: Box<dyn Fn(&dyn AsyncMeasurement<Value = u64>) + Send + Sync>,
          73  +
        _units: Option<String>,
          74  +
        _description: Option<String>,
          75  +
    ) -> Box<dyn AsyncMeasurement<Value = u64>> {
          76  +
        Box::new(NoopAsyncMeasurement(PhantomData::<u64>))
          77  +
    }
          78  +
          79  +
    fn create_histogram(
          80  +
        &self,
          81  +
        _name: String,
          82  +
        _units: Option<String>,
          83  +
        _description: Option<String>,
          84  +
    ) -> Box<dyn Histogram> {
          85  +
        Box::new(NoopHistogram)
          86  +
    }
          87  +
}
          88  +
          89  +
#[derive(Debug)]
          90  +
struct NoopAsyncMeasurement<T: Send + Sync + Debug>(PhantomData<T>);
          91  +
impl<T: Send + Sync + Debug> AsyncMeasurement for NoopAsyncMeasurement<T> {
          92  +
    type Value = T;
          93  +
          94  +
    fn record(&self, _value: T, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {}
          95  +
          96  +
    fn stop(&self) {}
          97  +
}
          98  +
          99  +
#[derive(Debug)]
         100  +
struct NoopUpDownCounter;
         101  +
impl UpDownCounter for NoopUpDownCounter {
         102  +
    fn add(&self, _value: i64, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {}
         103  +
}
         104  +
         105  +
#[derive(Debug)]
         106  +
struct NoopMonotonicCounter;
         107  +
impl MonotonicCounter for NoopMonotonicCounter {
         108  +
    fn add(&self, _value: u64, _attributes: Option<&Attributes>, _context: Option<&dyn Context>) {}
         109  +
}
         110  +
         111  +
#[derive(Debug)]
         112  +
struct NoopHistogram;
         113  +
impl Histogram for NoopHistogram {
         114  +
    fn record(
         115  +
        &self,
         116  +
        _value: f64,
         117  +
        _attributes: Option<&Attributes>,
         118  +
        _context: Option<&dyn Context>,
         119  +
    ) {
         120  +
    }
         121  +
}

tmp-codegen-diff/aws-sdk/sdk/aws-smithy-observability/src/provider.rs

@@ -0,1 +0,92 @@
           1  +
/*
           2  +
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
           3  +
 * SPDX-License-Identifier: Apache-2.0
           4  +
 */
           5  +
           6  +
//! Definitions of high level Telemetry Providers.
           7  +
           8  +
use std::sync::Arc;
           9  +
          10  +
use crate::{meter::MeterProvider, noop::NoopMeterProvider};
          11  +
          12  +
/// A struct to hold the various types of telemetry providers.
          13  +
#[non_exhaustive]
          14  +
pub struct TelemetryProvider {
          15  +
    meter_provider: Box<dyn MeterProvider + Send + Sync>,
          16  +
}
          17  +
          18  +
impl TelemetryProvider {
          19  +
    /// Returns a builder struct for [TelemetryProvider]
          20  +
    pub fn builder() -> TelemetryProviderBuilder {
          21  +
        TelemetryProviderBuilder {
          22  +
            meter_provider: Box::new(NoopMeterProvider),
          23  +
        }
          24  +
    }
          25  +
          26  +
    /// Returns a noop [TelemetryProvider]
          27  +
    pub fn noop() -> TelemetryProvider {
          28  +
        Self {
          29  +
            meter_provider: Box::new(NoopMeterProvider),
          30  +
        }
          31  +
    }
          32  +
          33  +
    /// Get the set [MeterProvider]
          34  +
    pub fn meter_provider(&self) -> &(dyn MeterProvider + Send + Sync) {
          35  +
        self.meter_provider.as_ref()
          36  +
    }
          37  +
}
          38  +
          39  +
// If we choose to expand our Telemetry provider and make Logging and Tracing
          40  +
// configurable at some point in the future we can do that by adding default
          41  +
// logger_provider and tracer_providers based on `tracing` to maintain backwards
          42  +
// compatibilty with what we have today.
          43  +
impl Default for TelemetryProvider {
          44  +
    fn default() -> Self {
          45  +
        Self {
          46  +
            meter_provider: Box::new(NoopMeterProvider),
          47  +
        }
          48  +
    }
          49  +
}
          50  +
          51  +
/// A builder for [TelemetryProvider].
          52  +
#[non_exhaustive]
          53  +
pub struct TelemetryProviderBuilder {
          54  +
    meter_provider: Box<dyn MeterProvider + Send + Sync>,
          55  +
}
          56  +
          57  +
impl TelemetryProviderBuilder {
          58  +
    /// Set the [MeterProvider].
          59  +
    pub fn meter_provider(
          60  +
        mut self,
          61  +
        meter_provider: impl MeterProvider + Send + Sync + 'static,
          62  +
    ) -> Self {
          63  +
        self.meter_provider = Box::new(meter_provider);
          64  +
        self
          65  +
    }
          66  +
          67  +
    /// Build the [TelemetryProvider].
          68  +
    pub fn build(self) -> TelemetryProvider {
          69  +
        TelemetryProvider {
          70  +
            meter_provider: self.meter_provider,
          71  +
        }
          72  +
    }
          73  +
}
          74  +
          75  +
/// Wrapper type to hold a implementer of TelemetryProvider in an Arc so that
          76  +
/// it can be safely used across threads.
          77  +
#[non_exhaustive]
          78  +
pub(crate) struct GlobalTelemetryProvider {
          79  +
    pub(crate) telemetry_provider: Arc<TelemetryProvider>,
          80  +
}
          81  +
          82  +
impl GlobalTelemetryProvider {
          83  +
    pub(crate) fn new(telemetry_provider: TelemetryProvider) -> Self {
          84  +
        Self {
          85  +
            telemetry_provider: Arc::new(telemetry_provider),
          86  +
        }
          87  +
    }
          88  +
          89  +
    pub(crate) fn telemetry_provider(&self) -> &Arc<TelemetryProvider> {
          90  +
        &self.telemetry_provider
          91  +
    }
          92  +
}