diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 616640e7e7..5061d12112 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -2,6 +2,10 @@ ## vNext +- **BREAKING** Public API changes: + - **Removed**: `SdkMeter` struct [#2113](https://github.com/open-telemetry/opentelemetry-rust/pull/2113). This API is only meant for internal use. + - **Removed**: `AggregationSelector` trait and `DefaultAggregationSelector` struct [#2085](https://github.com/open-telemetry/opentelemetry-rust/pull/2085). This API was unnecessary. The feature to customize aggregation for instruments should be offered by `Views` API. + - Update `async-std` dependency version to 1.13 - *Breaking* - Remove support for `MetricProducer` which allowed metrics from external sources to be sent through OpenTelemetry. diff --git a/opentelemetry-sdk/src/logs/record.rs b/opentelemetry-sdk/src/logs/record.rs index 78713598d8..f1ecfa7d7e 100644 --- a/opentelemetry-sdk/src/logs/record.rs +++ b/opentelemetry-sdk/src/logs/record.rs @@ -149,7 +149,7 @@ impl From<&SpanContext> for TraceContext { } } -#[cfg(test)] +#[cfg(all(test, feature = "testing"))] mod tests { use super::*; use opentelemetry::logs::{AnyValue, LogRecord as _, Severity}; diff --git a/opentelemetry-sdk/src/metrics/meter_provider.rs b/opentelemetry-sdk/src/metrics/meter_provider.rs index c693b2aa56..9cd798eb44 100644 --- a/opentelemetry-sdk/src/metrics/meter_provider.rs +++ b/opentelemetry-sdk/src/metrics/meter_provider.rs @@ -1,6 +1,5 @@ use core::fmt; use std::{ - borrow::Cow, collections::HashMap, sync::{ atomic::{AtomicBool, Ordering}, @@ -139,9 +138,9 @@ impl Drop for SdkMeterProviderInner { impl MeterProvider for SdkMeterProvider { fn versioned_meter( &self, - name: impl Into>, - version: Option>>, - schema_url: Option>>, + name: &'static str, + version: Option<&'static str>, + schema_url: Option<&'static str>, attributes: Option>, ) -> Meter { if self.inner.is_shutdown.load(Ordering::Relaxed) { @@ -245,7 +244,7 @@ impl fmt::Debug for MeterProviderBuilder { .finish() } } -#[cfg(test)] +#[cfg(all(test, feature = "testing"))] mod tests { use crate::resource::{ SERVICE_NAME, TELEMETRY_SDK_LANGUAGE, TELEMETRY_SDK_NAME, TELEMETRY_SDK_VERSION, diff --git a/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs b/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs index 3f85b360b7..89eec6e6b7 100644 --- a/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs +++ b/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs @@ -41,7 +41,7 @@ use std::sync::{Arc, Mutex}; /// .build(); /// /// // Create and record metrics using the MeterProvider -/// let meter = meter_provider.meter(std::borrow::Cow::Borrowed("example")); +/// let meter = meter_provider.meter("example"); /// let counter = meter.u64_counter("my_counter").init(); /// counter.add(1, &[KeyValue::new("key", "value")]); /// diff --git a/opentelemetry-sdk/src/trace/runtime_tests.rs b/opentelemetry-sdk/src/trace/runtime_tests.rs index 610d140b7a..f9f3c105f9 100644 --- a/opentelemetry-sdk/src/trace/runtime_tests.rs +++ b/opentelemetry-sdk/src/trace/runtime_tests.rs @@ -1,25 +1,32 @@ // Note that all tests here should be marked as ignore so that it won't be picked up by default We // need to run those tests one by one as the GlobalTracerProvider is a shared object between // threads Use cargo test -- --ignored --test-threads=1 to run those tests. +#[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] use crate::export::trace::{ExportResult, SpanExporter}; #[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] use crate::runtime; #[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] use crate::runtime::RuntimeChannel; +#[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] use futures_util::future::BoxFuture; #[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] use opentelemetry::global::*; #[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] use opentelemetry::trace::Tracer; +#[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] use std::fmt::Debug; +#[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] use std::sync::atomic::{AtomicUsize, Ordering}; +#[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] use std::sync::Arc; #[derive(Debug)] +#[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] struct SpanCountExporter { span_count: Arc, } +#[cfg(any(feature = "rt-tokio", feature = "rt-tokio-current-thread"))] impl SpanExporter for SpanCountExporter { fn export( &mut self, diff --git a/opentelemetry/CHANGELOG.md b/opentelemetry/CHANGELOG.md index 1f0c9be637..32a512ba7d 100644 --- a/opentelemetry/CHANGELOG.md +++ b/opentelemetry/CHANGELOG.md @@ -2,6 +2,13 @@ ## vNext +- **BREAKING** Public API changes: + - **Removed**: `Key.bool()`, `Key.i64()`, `Key.f64()`, `Key.string()`, `Key.array()` [#2090](https://github.com/open-telemetry/opentelemetry-rust/issues/2090). These APIs were redundant as they didn't offer any additional functionality. The existing `KeyValue::new()` API covers all the scenarios offered by these APIs. + + - **Removed**: `ObjectSafeMeterProvider` and `GlobalMeterProvider` [#2112](https://github.com/open-telemetry/opentelemetry-rust/pull/2112). These APIs were unnecessary and were mainly meant for internal use. + + - **Modified**: `MeterProvider.meter()` and `MeterProvider.versioned_meter()` argument types have been updated to `&'static str` instead of `impl Into>>` [#2112](https://github.com/open-telemetry/opentelemetry-rust/pull/2112). These APIs were modified to enforce the Meter `name`, `version`, and `schema_url` to be `&'static str`. + ## v0.25.0 - **BREAKING** [#1993](https://github.com/open-telemetry/opentelemetry-rust/pull/1993) Box complex types in AnyValue enum diff --git a/opentelemetry/src/global/metrics.rs b/opentelemetry/src/global/metrics.rs index 7826f9920e..630e9e2ba7 100644 --- a/opentelemetry/src/global/metrics.rs +++ b/opentelemetry/src/global/metrics.rs @@ -1,90 +1,13 @@ use crate::metrics::{self, Meter, MeterProvider}; use crate::KeyValue; -use core::fmt; use once_cell::sync::Lazy; -use std::{ - borrow::Cow, - sync::{Arc, RwLock}, -}; +use std::sync::{Arc, RwLock}; -/// The global `MeterProvider` singleton. -static GLOBAL_METER_PROVIDER: Lazy> = Lazy::new(|| { - RwLock::new(GlobalMeterProvider::new( - metrics::noop::NoopMeterProvider::new(), - )) -}); - -/// Allows a specific [MeterProvider] to be used generically by the -/// [GlobalMeterProvider] by mirroring the interface and boxing the return types. -trait ObjectSafeMeterProvider { - /// Creates a versioned named meter instance that is a trait object through the underlying - /// [MeterProvider]. - fn versioned_meter_cow( - &self, - name: Cow<'static, str>, - version: Option>, - schema_url: Option>, - attributes: Option>, - ) -> Meter; -} - -impl

ObjectSafeMeterProvider for P -where - P: MeterProvider, -{ - /// Return a versioned boxed tracer - fn versioned_meter_cow( - &self, - name: Cow<'static, str>, - version: Option>, - schema_url: Option>, - attributes: Option>, - ) -> Meter { - self.versioned_meter(name, version, schema_url, attributes) - } -} +type GlobalMeterProvider = Arc; -/// Represents the globally configured [`MeterProvider`] instance for this -/// application. -#[derive(Clone)] -pub struct GlobalMeterProvider { - provider: Arc, -} - -impl fmt::Debug for GlobalMeterProvider { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("GlobalMeterProvider").finish() - } -} - -impl MeterProvider for GlobalMeterProvider { - fn versioned_meter( - &self, - name: impl Into>, - version: Option>>, - schema_url: Option>>, - attributes: Option>, - ) -> Meter { - self.provider.versioned_meter_cow( - name.into(), - version.map(Into::into), - schema_url.map(Into::into), - attributes, - ) - } -} - -impl GlobalMeterProvider { - /// Create a new global meter provider - fn new

(provider: P) -> Self - where - P: MeterProvider + Send + Sync + 'static, - { - GlobalMeterProvider { - provider: Arc::new(provider), - } - } -} +/// The global `MeterProvider` singleton. +static GLOBAL_METER_PROVIDER: Lazy> = + Lazy::new(|| RwLock::new(Arc::new(metrics::noop::NoopMeterProvider::new()))); /// Sets the given [`MeterProvider`] instance as the current global meter /// provider. @@ -95,11 +18,10 @@ where let mut global_provider = GLOBAL_METER_PROVIDER .write() .expect("GLOBAL_METER_PROVIDER RwLock poisoned"); - *global_provider = GlobalMeterProvider::new(new_provider); + *global_provider = Arc::new(new_provider); } -/// Returns an instance of the currently configured global [`MeterProvider`] -/// through [`GlobalMeterProvider`]. +/// Returns an instance of the currently configured global [`MeterProvider`]. pub fn meter_provider() -> GlobalMeterProvider { GLOBAL_METER_PROVIDER .read() @@ -107,13 +29,13 @@ pub fn meter_provider() -> GlobalMeterProvider { .clone() } -/// Creates a named [`Meter`] via the configured [`GlobalMeterProvider`]. +/// Creates a named [`Meter`] via the currently configured global [`MeterProvider`]. /// /// If the name is an empty string, the provider will use a default name. /// /// This is a more convenient way of expressing `global::meter_provider().meter(name)`. -pub fn meter(name: impl Into>) -> Meter { - meter_provider().meter(name.into()) +pub fn meter(name: &'static str) -> Meter { + meter_provider().meter(name) } /// Creates a [`Meter`] with the name, version and schema url. @@ -138,15 +60,10 @@ pub fn meter(name: impl Into>) -> Meter { /// ); /// ``` pub fn meter_with_version( - name: impl Into>, - version: Option>>, - schema_url: Option>>, + name: &'static str, + version: Option<&'static str>, + schema_url: Option<&'static str>, attributes: Option>, ) -> Meter { - meter_provider().versioned_meter( - name.into(), - version.map(Into::into), - schema_url.map(Into::into), - attributes, - ) + meter_provider().versioned_meter(name, version, schema_url, attributes) } diff --git a/opentelemetry/src/metrics/meter.rs b/opentelemetry/src/metrics/meter.rs index 3422240b48..b70291b916 100644 --- a/opentelemetry/src/metrics/meter.rs +++ b/opentelemetry/src/metrics/meter.rs @@ -39,13 +39,8 @@ pub trait MeterProvider { /// Some(vec![KeyValue::new("key", "value")]), /// ); /// ``` - fn meter(&self, name: impl Into>) -> Meter { - self.versioned_meter( - name, - None::>, - None::>, - None, - ) + fn meter(&self, name: &'static str) -> Meter { + self.versioned_meter(name, None, None, None) } /// Returns a new versioned meter with a given name. @@ -56,9 +51,9 @@ pub trait MeterProvider { /// default name will be used instead. fn versioned_meter( &self, - name: impl Into>, - version: Option>>, - schema_url: Option>>, + name: &'static str, + version: Option<&'static str>, + schema_url: Option<&'static str>, attributes: Option>, ) -> Meter; } diff --git a/opentelemetry/src/metrics/noop.rs b/opentelemetry/src/metrics/noop.rs index 716e4ca3c8..9db39890aa 100644 --- a/opentelemetry/src/metrics/noop.rs +++ b/opentelemetry/src/metrics/noop.rs @@ -10,7 +10,7 @@ use crate::{ }, KeyValue, }; -use std::{any::Any, borrow::Cow, sync::Arc}; +use std::{any::Any, sync::Arc}; /// A no-op instance of a `MetricProvider` #[derive(Debug, Default)] @@ -28,9 +28,9 @@ impl NoopMeterProvider { impl MeterProvider for NoopMeterProvider { fn versioned_meter( &self, - _name: impl Into>, - _version: Option>>, - _schema_url: Option>>, + _name: &'static str, + _version: Option<&'static str>, + _schema_url: Option<&'static str>, _attributes: Option>, ) -> Meter { Meter::new(Arc::new(NoopMeterCore::new()))