From 8140e74c7b3ce1c17e6a23b2de2ff1ed3bacb92b Mon Sep 17 00:00:00 2001 From: Fabien Savy Date: Wed, 23 Oct 2024 10:21:35 +0200 Subject: [PATCH] Remove InstrumentationScope as Scope re-export in SDK --- opentelemetry-proto/src/transform/common.rs | 28 ++++++++-- opentelemetry-proto/src/transform/trace.rs | 6 +-- opentelemetry-sdk/benches/log.rs | 5 +- opentelemetry-sdk/benches/log_exporter.rs | 6 +-- opentelemetry-sdk/benches/log_processor.rs | 16 +++--- opentelemetry-sdk/src/export/logs/mod.rs | 16 +++--- opentelemetry-sdk/src/export/trace.rs | 6 +-- opentelemetry-sdk/src/lib.rs | 2 - opentelemetry-sdk/src/logs/log_emitter.rs | 18 +++---- opentelemetry-sdk/src/logs/log_processor.rs | 52 +++++++++---------- opentelemetry-sdk/src/logs/mod.rs | 6 +-- opentelemetry-sdk/src/metrics/data/mod.rs | 10 ++-- opentelemetry-sdk/src/metrics/instrument.rs | 13 ++--- opentelemetry-sdk/src/metrics/meter.rs | 6 +-- .../src/metrics/meter_provider.rs | 15 +++--- opentelemetry-sdk/src/metrics/mod.rs | 5 +- opentelemetry-sdk/src/metrics/pipeline.rs | 10 ++-- .../src/testing/logs/in_memory_exporter.rs | 9 ++-- .../src/testing/trace/span_exporters.rs | 8 +-- opentelemetry-sdk/src/trace/mod.rs | 5 +- opentelemetry-sdk/src/trace/provider.rs | 5 +- opentelemetry-sdk/src/trace/tracer.rs | 19 +++---- opentelemetry-stdout/src/common.rs | 4 +- 23 files changed, 143 insertions(+), 127 deletions(-) diff --git a/opentelemetry-proto/src/transform/common.rs b/opentelemetry-proto/src/transform/common.rs index 731da61824..0821165c89 100644 --- a/opentelemetry-proto/src/transform/common.rs +++ b/opentelemetry-proto/src/transform/common.rs @@ -42,8 +42,18 @@ pub mod tonic { #[cfg(any(feature = "trace", feature = "logs"))] use opentelemetry_sdk::Resource; - impl From<(opentelemetry_sdk::Scope, Option>)> for InstrumentationScope { - fn from(data: (opentelemetry_sdk::Scope, Option>)) -> Self { + impl + From<( + opentelemetry::InstrumentationScope, + Option>, + )> for InstrumentationScope + { + fn from( + data: ( + opentelemetry::InstrumentationScope, + Option>, + ), + ) -> Self { let (library, target) = data; if let Some(t) = target { InstrumentationScope { @@ -63,8 +73,18 @@ pub mod tonic { } } - impl From<(&opentelemetry_sdk::Scope, Option>)> for InstrumentationScope { - fn from(data: (&opentelemetry_sdk::Scope, Option>)) -> Self { + impl + From<( + &opentelemetry::InstrumentationScope, + Option>, + )> for InstrumentationScope + { + fn from( + data: ( + &opentelemetry::InstrumentationScope, + Option>, + ), + ) -> Self { let (library, target) = data; if let Some(t) = target { InstrumentationScope { diff --git a/opentelemetry-proto/src/transform/trace.rs b/opentelemetry-proto/src/transform/trace.rs index 7fef01802d..66b92646cc 100644 --- a/opentelemetry-proto/src/transform/trace.rs +++ b/opentelemetry-proto/src/transform/trace.rs @@ -158,7 +158,7 @@ pub mod tonic { // Group spans by their instrumentation library let scope_map = spans.iter().fold( HashMap::new(), - |mut scope_map: HashMap<&opentelemetry_sdk::Scope, Vec<&SpanData>>, span| { + |mut scope_map: HashMap<&opentelemetry::InstrumentationScope, Vec<&SpanData>>, span| { let instrumentation = &span.instrumentation_scope; scope_map.entry(instrumentation).or_default().push(span); scope_map @@ -197,11 +197,11 @@ mod tests { use opentelemetry::trace::{ SpanContext, SpanId, SpanKind, Status, TraceFlags, TraceId, TraceState, }; + use opentelemetry::InstrumentationScope; use opentelemetry::KeyValue; use opentelemetry_sdk::export::trace::SpanData; use opentelemetry_sdk::resource::Resource; use opentelemetry_sdk::trace::{SpanEvents, SpanLinks}; - use opentelemetry_sdk::Scope; use std::borrow::Cow; use std::time::{Duration, SystemTime}; @@ -226,7 +226,7 @@ mod tests { events: SpanEvents::default(), links: SpanLinks::default(), status: Status::Unset, - instrumentation_scope: Scope::builder(instrumentation_name).build(), + instrumentation_scope: InstrumentationScope::builder(instrumentation_name).build(), } } diff --git a/opentelemetry-sdk/benches/log.rs b/opentelemetry-sdk/benches/log.rs index 9ec8cb5d08..ca8a76a414 100644 --- a/opentelemetry-sdk/benches/log.rs +++ b/opentelemetry-sdk/benches/log.rs @@ -25,17 +25,16 @@ use opentelemetry::logs::{ }; use opentelemetry::trace::Tracer; use opentelemetry::trace::TracerProvider as _; -use opentelemetry::Key; +use opentelemetry::{InstrumentationScope, Key}; use opentelemetry_sdk::logs::{LogProcessor, LogRecord, Logger, LoggerProvider}; use opentelemetry_sdk::trace; use opentelemetry_sdk::trace::{Sampler, TracerProvider}; -use opentelemetry_sdk::Scope; #[derive(Debug)] struct NoopProcessor; impl LogProcessor for NoopProcessor { - fn emit(&self, _data: &mut LogRecord, _scope: &Scope) {} + fn emit(&self, _data: &mut LogRecord, _scope: &InstrumentationScope) {} fn force_flush(&self) -> LogResult<()> { Ok(()) diff --git a/opentelemetry-sdk/benches/log_exporter.rs b/opentelemetry-sdk/benches/log_exporter.rs index b39a4afd2a..c3c027f3e1 100644 --- a/opentelemetry-sdk/benches/log_exporter.rs +++ b/opentelemetry-sdk/benches/log_exporter.rs @@ -18,11 +18,11 @@ use criterion::{criterion_group, criterion_main, Criterion}; use opentelemetry::logs::{LogRecord as _, LogResult, Logger as _, LoggerProvider as _, Severity}; +use opentelemetry::InstrumentationScope; use opentelemetry_sdk::export::logs::LogBatch; use opentelemetry_sdk::logs::LogProcessor; use opentelemetry_sdk::logs::LogRecord; use opentelemetry_sdk::logs::LoggerProvider; -use opentelemetry_sdk::Scope; use pprof::criterion::{Output, PProfProfiler}; use std::fmt::Debug; @@ -65,7 +65,7 @@ impl ExportingProcessorWithFuture { } impl LogProcessor for ExportingProcessorWithFuture { - fn emit(&self, record: &mut LogRecord, scope: &Scope) { + fn emit(&self, record: &mut LogRecord, scope: &InstrumentationScope) { let mut exporter = self.exporter.lock().expect("lock error"); let logs = [(record as &LogRecord, scope)]; futures_executor::block_on(exporter.export(LogBatch::new(&logs))); @@ -94,7 +94,7 @@ impl ExportingProcessorWithoutFuture { } impl LogProcessor for ExportingProcessorWithoutFuture { - fn emit(&self, record: &mut LogRecord, scope: &Scope) { + fn emit(&self, record: &mut LogRecord, scope: &InstrumentationScope) { let logs = [(record as &LogRecord, scope)]; self.exporter .lock() diff --git a/opentelemetry-sdk/benches/log_processor.rs b/opentelemetry-sdk/benches/log_processor.rs index 43a09f0fab..03cd71549c 100644 --- a/opentelemetry-sdk/benches/log_processor.rs +++ b/opentelemetry-sdk/benches/log_processor.rs @@ -18,9 +18,11 @@ use std::{ }; use criterion::{criterion_group, criterion_main, Criterion}; -use opentelemetry::logs::{LogRecord as _, LogResult, Logger as _, LoggerProvider as _, Severity}; +use opentelemetry::{ + logs::{LogRecord as _, LogResult, Logger as _, LoggerProvider as _, Severity}, + InstrumentationScope, +}; use opentelemetry_sdk::logs::{LogProcessor, LogRecord, Logger, LoggerProvider}; -use opentelemetry_sdk::Scope; // Run this benchmark with: // cargo bench --bench log_processor @@ -43,7 +45,7 @@ fn create_log_record(logger: &Logger) -> LogRecord { struct NoopProcessor; impl LogProcessor for NoopProcessor { - fn emit(&self, _data: &mut LogRecord, _scope: &Scope) {} + fn emit(&self, _data: &mut LogRecord, _scope: &InstrumentationScope) {} fn force_flush(&self) -> LogResult<()> { Ok(()) @@ -58,7 +60,7 @@ impl LogProcessor for NoopProcessor { struct CloningProcessor; impl LogProcessor for CloningProcessor { - fn emit(&self, data: &mut LogRecord, _scope: &Scope) { + fn emit(&self, data: &mut LogRecord, _scope: &InstrumentationScope) { let _data_cloned = data.clone(); } @@ -73,8 +75,8 @@ impl LogProcessor for CloningProcessor { #[derive(Debug)] struct SendToChannelProcessor { - sender: std::sync::mpsc::Sender<(LogRecord, Scope)>, - receiver: Arc>>, + sender: std::sync::mpsc::Sender<(LogRecord, InstrumentationScope)>, + receiver: Arc>>, } impl SendToChannelProcessor { @@ -101,7 +103,7 @@ impl SendToChannelProcessor { } impl LogProcessor for SendToChannelProcessor { - fn emit(&self, record: &mut LogRecord, scope: &Scope) { + fn emit(&self, record: &mut LogRecord, scope: &InstrumentationScope) { let res = self.sender.send((record.clone(), scope.clone())); if res.is_err() { println!("Error sending log data to channel {0}", res.err().unwrap()); diff --git a/opentelemetry-sdk/src/export/logs/mod.rs b/opentelemetry-sdk/src/export/logs/mod.rs index 86d8ab5106..9266663fcb 100644 --- a/opentelemetry-sdk/src/export/logs/mod.rs +++ b/opentelemetry-sdk/src/export/logs/mod.rs @@ -1,11 +1,11 @@ //! Log exporters use crate::logs::LogRecord; use crate::Resource; -use crate::Scope; use async_trait::async_trait; #[cfg(feature = "logs_level_enabled")] use opentelemetry::logs::Severity; use opentelemetry::logs::{LogError, LogResult}; +use opentelemetry::InstrumentationScope; use std::fmt::Debug; /// A batch of log records to be exported by a `LogExporter`. @@ -20,8 +20,8 @@ use std::fmt::Debug; #[derive(Debug)] pub struct LogBatch<'a> { /// The data field contains a slice of tuples, where each tuple consists of a reference to - /// a `LogRecord` and a reference to an `Scope`. - data: &'a [(&'a LogRecord, &'a Scope)], + /// a `LogRecord` and a reference to an `InstrumentationScope`. + data: &'a [(&'a LogRecord, &'a InstrumentationScope)], } impl<'a> LogBatch<'a> { @@ -30,7 +30,7 @@ impl<'a> LogBatch<'a> { /// # Arguments /// /// * `data` - A slice of tuples, where each tuple consists of a reference to a `LogRecord` - /// and a reference to an `Scope`. These tuples represent the log records + /// and a reference to an `InstrumentationScope`. These tuples represent the log records /// and their associated instrumentation libraries to be exported. /// /// # Returns @@ -40,7 +40,7 @@ impl<'a> LogBatch<'a> { /// Note - this is not a public function, and should not be used directly. This would be /// made private in the future. - pub fn new(data: &'a [(&'a LogRecord, &'a Scope)]) -> LogBatch<'a> { + pub fn new(data: &'a [(&'a LogRecord, &'a InstrumentationScope)]) -> LogBatch<'a> { LogBatch { data } } } @@ -49,13 +49,13 @@ impl LogBatch<'_> { /// Returns an iterator over the log records and instrumentation libraries in the batch. /// /// Each item yielded by the iterator is a tuple containing references to a `LogRecord` - /// and an `Scope`. + /// and an `InstrumentationScope`. /// /// # Returns /// - /// An iterator that yields references to the `LogRecord` and `Scope` in the batch. + /// An iterator that yields references to the `LogRecord` and `InstrumentationScope` in the batch. /// - pub fn iter(&self) -> impl Iterator { + pub fn iter(&self) -> impl Iterator { self.data .iter() .map(|(record, library)| (*record, *library)) diff --git a/opentelemetry-sdk/src/export/trace.rs b/opentelemetry-sdk/src/export/trace.rs index 8e0b116b41..c606d85b1a 100644 --- a/opentelemetry-sdk/src/export/trace.rs +++ b/opentelemetry-sdk/src/export/trace.rs @@ -2,7 +2,7 @@ use crate::Resource; use futures_util::future::BoxFuture; use opentelemetry::trace::{SpanContext, SpanId, SpanKind, Status, TraceError}; -use opentelemetry::KeyValue; +use opentelemetry::{InstrumentationScope, KeyValue}; use std::borrow::Cow; use std::fmt::Debug; use std::time::SystemTime; @@ -95,6 +95,6 @@ pub struct SpanData { pub links: crate::trace::SpanLinks, /// Span status pub status: Status, - /// Instrumentation library that produced this span - pub instrumentation_scope: crate::Scope, + /// Instrumentation scope that produced this span + pub instrumentation_scope: InstrumentationScope, } diff --git a/opentelemetry-sdk/src/lib.rs b/opentelemetry-sdk/src/lib.rs index 09d6f34ba5..1c40acceb1 100644 --- a/opentelemetry-sdk/src/lib.rs +++ b/opentelemetry-sdk/src/lib.rs @@ -146,7 +146,5 @@ pub mod trace; #[doc(hidden)] pub mod util; -#[doc(inline)] -pub use opentelemetry::InstrumentationScope as Scope; #[doc(inline)] pub use resource::Resource; diff --git a/opentelemetry-sdk/src/logs/log_emitter.rs b/opentelemetry-sdk/src/logs/log_emitter.rs index 1bbd4a7342..a984f0a4ce 100644 --- a/opentelemetry-sdk/src/logs/log_emitter.rs +++ b/opentelemetry-sdk/src/logs/log_emitter.rs @@ -1,10 +1,10 @@ use super::{BatchLogProcessor, LogProcessor, LogRecord, SimpleLogProcessor, TraceContext}; -use crate::{export::logs::LogExporter, runtime::RuntimeChannel, Resource, Scope}; +use crate::{export::logs::LogExporter, runtime::RuntimeChannel, Resource}; use opentelemetry::{ logs::{LogError, LogResult}, otel_debug, trace::TraceContextExt, - Context, + Context, InstrumentationScope, }; #[cfg(feature = "logs_level_enabled")] @@ -48,7 +48,7 @@ pub struct LoggerProvider { impl opentelemetry::logs::LoggerProvider for LoggerProvider { type Logger = Logger; - fn logger_with_scope(&self, scope: Scope) -> Self::Logger { + fn logger_with_scope(&self, scope: InstrumentationScope) -> Self::Logger { // If the provider is shutdown, new logger will refer a no-op logger provider. if self.inner.is_shutdown.load(Ordering::Relaxed) { return Logger::new(scope, NOOP_LOGGER_PROVIDER.clone()); @@ -217,12 +217,12 @@ impl Builder { /// /// [`LogRecord`]: opentelemetry::logs::LogRecord pub struct Logger { - scope: Scope, + scope: InstrumentationScope, provider: LoggerProvider, } impl Logger { - pub(crate) fn new(scope: Scope, provider: LoggerProvider) -> Self { + pub(crate) fn new(scope: InstrumentationScope, provider: LoggerProvider) -> Self { Logger { scope, provider } } @@ -232,7 +232,7 @@ impl Logger { } /// Instrumentation library information of this logger. - pub fn instrumentation_scope(&self) -> &Scope { + pub fn instrumentation_scope(&self) -> &InstrumentationScope { &self.scope } } @@ -327,7 +327,7 @@ mod tests { } impl LogProcessor for ShutdownTestLogProcessor { - fn emit(&self, _data: &mut LogRecord, _scope: &Scope) { + fn emit(&self, _data: &mut LogRecord, _scope: &InstrumentationScope) { self.is_shutdown .lock() .map(|is_shutdown| { @@ -706,7 +706,7 @@ mod tests { } impl LogProcessor for LazyLogProcessor { - fn emit(&self, _data: &mut LogRecord, _scope: &Scope) { + fn emit(&self, _data: &mut LogRecord, _scope: &InstrumentationScope) { // nothing to do. } @@ -737,7 +737,7 @@ mod tests { } impl LogProcessor for CountingShutdownProcessor { - fn emit(&self, _data: &mut LogRecord, _scope: &Scope) { + fn emit(&self, _data: &mut LogRecord, _scope: &InstrumentationScope) { // nothing to do } diff --git a/opentelemetry-sdk/src/logs/log_processor.rs b/opentelemetry-sdk/src/logs/log_processor.rs index a50b7c85c0..5a60ff4a0f 100644 --- a/opentelemetry-sdk/src/logs/log_processor.rs +++ b/opentelemetry-sdk/src/logs/log_processor.rs @@ -2,7 +2,7 @@ use crate::{ export::logs::{ExportResult, LogBatch, LogExporter}, logs::LogRecord, runtime::{RuntimeChannel, TrySend}, - Resource, Scope, + Resource, }; use futures_channel::oneshot; use futures_util::{ @@ -13,7 +13,7 @@ use futures_util::{ use opentelemetry::logs::Severity; use opentelemetry::{ logs::{LogError, LogResult}, - otel_debug, otel_error, otel_warn, + otel_debug, otel_error, otel_warn, InstrumentationScope, }; use std::sync::atomic::AtomicBool; @@ -57,7 +57,7 @@ pub trait LogProcessor: Send + Sync + Debug { /// # Parameters /// - `record`: A mutable reference to `LogData` representing the log record. /// - `instrumentation`: The instrumentation library associated with the log record. - fn emit(&self, data: &mut LogRecord, instrumentation: &Scope); + fn emit(&self, data: &mut LogRecord, instrumentation: &InstrumentationScope); /// Force the logs lying in the cache to be exported. fn force_flush(&self) -> LogResult<()>; /// Shuts down the processor. @@ -95,7 +95,7 @@ impl SimpleLogProcessor { } impl LogProcessor for SimpleLogProcessor { - fn emit(&self, record: &mut LogRecord, instrumentation: &Scope) { + fn emit(&self, record: &mut LogRecord, instrumentation: &InstrumentationScope) { // noop after shutdown if self.is_shutdown.load(std::sync::atomic::Ordering::Relaxed) { // this is a warning, as the user is trying to log after the processor has been shutdown @@ -168,7 +168,7 @@ impl Debug for BatchLogProcessor { } impl LogProcessor for BatchLogProcessor { - fn emit(&self, record: &mut LogRecord, instrumentation: &Scope) { + fn emit(&self, record: &mut LogRecord, instrumentation: &InstrumentationScope) { let result = self.message_sender.try_send(BatchMessage::ExportLog(( record.clone(), instrumentation.clone(), @@ -320,7 +320,7 @@ async fn export_with_timeout( time_out: Duration, exporter: &mut E, runtime: &R, - batch: Vec<(LogRecord, Scope)>, + batch: Vec<(LogRecord, InstrumentationScope)>, ) -> ExportResult where R: RuntimeChannel, @@ -331,7 +331,7 @@ where } // TBD - Can we avoid this conversion as it involves heap allocation with new vector? - let log_vec: Vec<(&LogRecord, &Scope)> = batch + let log_vec: Vec<(&LogRecord, &InstrumentationScope)> = batch .iter() .map(|log_data| (&log_data.0, &log_data.1)) .collect(); @@ -515,7 +515,7 @@ where #[derive(Debug)] enum BatchMessage { /// Export logs, usually called when the log is emitted. - ExportLog((LogRecord, Scope)), + ExportLog((LogRecord, InstrumentationScope)), /// Flush the current buffer to the backend, it can be triggered by /// pre configured interval or a call to `force_push` function. Flush(Option>), @@ -544,14 +544,14 @@ mod tests { }, runtime, testing::logs::InMemoryLogsExporter, - Resource, Scope, + Resource, }; use async_trait::async_trait; use opentelemetry::logs::AnyValue; use opentelemetry::logs::LogRecord as _; use opentelemetry::logs::{Logger, LoggerProvider as _}; - use opentelemetry::Key; use opentelemetry::{logs::LogResult, KeyValue}; + use opentelemetry::{InstrumentationScope, Key}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; use std::time::Duration; @@ -793,8 +793,8 @@ mod tests { runtime::Tokio, ); - let mut record: LogRecord = Default::default(); - let instrumentation: Scope = Default::default(); + let mut record = LogRecord::default(); + let instrumentation = InstrumentationScope::default(); processor.emit(&mut record, &instrumentation); processor.force_flush().unwrap(); @@ -812,7 +812,7 @@ mod tests { let processor = SimpleLogProcessor::new(Box::new(exporter.clone())); let mut record: LogRecord = Default::default(); - let instrumentation: Scope = Default::default(); + let instrumentation: InstrumentationScope = Default::default(); processor.emit(&mut record, &instrumentation); @@ -882,11 +882,11 @@ mod tests { #[derive(Debug)] struct FirstProcessor { - pub(crate) logs: Arc>>, + pub(crate) logs: Arc>>, } impl LogProcessor for FirstProcessor { - fn emit(&self, record: &mut LogRecord, instrumentation: &Scope) { + fn emit(&self, record: &mut LogRecord, instrumentation: &InstrumentationScope) { // add attribute record.add_attribute( Key::from_static_str("processed_by"), @@ -912,11 +912,11 @@ mod tests { #[derive(Debug)] struct SecondProcessor { - pub(crate) logs: Arc>>, + pub(crate) logs: Arc>>, } impl LogProcessor for SecondProcessor { - fn emit(&self, record: &mut LogRecord, instrumentation: &Scope) { + fn emit(&self, record: &mut LogRecord, instrumentation: &InstrumentationScope) { assert!(record.attributes_contains( &Key::from_static_str("processed_by"), &AnyValue::String("FirstProcessor".into()) @@ -993,7 +993,7 @@ mod tests { let processor = SimpleLogProcessor::new(Box::new(exporter.clone())); let mut record: LogRecord = Default::default(); - let instrumentation: Scope = Default::default(); + let instrumentation: InstrumentationScope = Default::default(); processor.emit(&mut record, &instrumentation); @@ -1006,7 +1006,7 @@ mod tests { let processor = SimpleLogProcessor::new(Box::new(exporter.clone())); let mut record: LogRecord = Default::default(); - let instrumentation: Scope = Default::default(); + let instrumentation: InstrumentationScope = Default::default(); processor.emit(&mut record, &instrumentation); @@ -1023,7 +1023,7 @@ mod tests { let processor_clone = Arc::clone(&processor); let handle = tokio::spawn(async move { let mut record: LogRecord = Default::default(); - let instrumentation: Scope = Default::default(); + let instrumentation: InstrumentationScope = Default::default(); processor_clone.emit(&mut record, &instrumentation); }); handles.push(handle); @@ -1042,7 +1042,7 @@ mod tests { let processor = SimpleLogProcessor::new(Box::new(exporter.clone())); let mut record: LogRecord = Default::default(); - let instrumentation: Scope = Default::default(); + let instrumentation: InstrumentationScope = Default::default(); processor.emit(&mut record, &instrumentation); @@ -1089,7 +1089,7 @@ mod tests { let processor = SimpleLogProcessor::new(Box::new(exporter.clone())); let mut record: LogRecord = Default::default(); - let instrumentation: Scope = Default::default(); + let instrumentation: InstrumentationScope = Default::default(); // This will panic because an tokio async operation within exporter without a runtime. processor.emit(&mut record, &instrumentation); @@ -1145,7 +1145,7 @@ mod tests { let processor_clone = Arc::clone(&processor); let handle = tokio::spawn(async move { let mut record: LogRecord = Default::default(); - let instrumentation: Scope = Default::default(); + let instrumentation: InstrumentationScope = Default::default(); processor_clone.emit(&mut record, &instrumentation); }); handles.push(handle); @@ -1169,7 +1169,7 @@ mod tests { let processor = SimpleLogProcessor::new(Box::new(exporter.clone())); let mut record: LogRecord = Default::default(); - let instrumentation: Scope = Default::default(); + let instrumentation: InstrumentationScope = Default::default(); processor.emit(&mut record, &instrumentation); @@ -1188,7 +1188,7 @@ mod tests { let processor = SimpleLogProcessor::new(Box::new(exporter.clone())); let mut record: LogRecord = Default::default(); - let instrumentation: Scope = Default::default(); + let instrumentation: InstrumentationScope = Default::default(); processor.emit(&mut record, &instrumentation); @@ -1208,7 +1208,7 @@ mod tests { let processor = SimpleLogProcessor::new(Box::new(exporter.clone())); let mut record: LogRecord = Default::default(); - let instrumentation: Scope = Default::default(); + let instrumentation: InstrumentationScope = Default::default(); processor.emit(&mut record, &instrumentation); diff --git a/opentelemetry-sdk/src/logs/mod.rs b/opentelemetry-sdk/src/logs/mod.rs index baa2240c42..c01ed8c626 100644 --- a/opentelemetry-sdk/src/logs/mod.rs +++ b/opentelemetry-sdk/src/logs/mod.rs @@ -3,12 +3,12 @@ mod log_emitter; mod log_processor; pub(crate) mod record; -use crate::Scope; pub use log_emitter::{Builder, Logger, LoggerProvider}; pub use log_processor::{ BatchConfig, BatchConfigBuilder, BatchLogProcessor, BatchLogProcessorBuilder, LogProcessor, SimpleLogProcessor, }; +use opentelemetry::InstrumentationScope; pub use record::{LogRecord, TraceContext}; /// `LogData` represents a single log event without resource context. @@ -17,7 +17,7 @@ pub struct LogData { /// Log record pub record: LogRecord, /// Instrumentation details for the emitter who produced this `LogEvent`. - pub instrumentation: Scope, + pub instrumentation: InstrumentationScope, } #[cfg(all(test, feature = "testing"))] @@ -104,7 +104,7 @@ mod tests { #[test] fn logger_attributes() { let provider = LoggerProvider::builder().build(); - let scope = Scope::builder("test_logger") + let scope = InstrumentationScope::builder("test_logger") .with_schema_url("https://opentelemetry.io/schema/1.0.0") .with_attributes(vec![(KeyValue::new("test_k", "test_v"))]) .build(); diff --git a/opentelemetry-sdk/src/metrics/data/mod.rs b/opentelemetry-sdk/src/metrics/data/mod.rs index c1e4c2d535..83b8ed5e97 100644 --- a/opentelemetry-sdk/src/metrics/data/mod.rs +++ b/opentelemetry-sdk/src/metrics/data/mod.rs @@ -2,9 +2,9 @@ use std::{any, borrow::Cow, fmt, time::SystemTime}; -use opentelemetry::KeyValue; +use opentelemetry::{InstrumentationScope, KeyValue}; -use crate::{Resource, Scope}; +use crate::Resource; pub use self::temporality::Temporality; @@ -15,15 +15,15 @@ mod temporality; pub struct ResourceMetrics { /// The entity that collected the metrics. pub resource: Resource, - /// The collection of metrics with unique [Scope]s. + /// The collection of metrics with unique [InstrumentationScope]s. pub scope_metrics: Vec, } /// A collection of metrics produced by a meter. #[derive(Default, Debug)] pub struct ScopeMetrics { - /// The [Scope] that the meter was created with. - pub scope: Scope, + /// The [InstrumentationScope] that the meter was created with. + pub scope: InstrumentationScope, /// The list of aggregations created by the meter. pub metrics: Vec, } diff --git a/opentelemetry-sdk/src/metrics/instrument.rs b/opentelemetry-sdk/src/metrics/instrument.rs index 7697b957d0..c2b3ce5219 100644 --- a/opentelemetry-sdk/src/metrics/instrument.rs +++ b/opentelemetry-sdk/src/metrics/instrument.rs @@ -2,13 +2,10 @@ use std::{borrow::Cow, collections::HashSet, sync::Arc}; use opentelemetry::{ metrics::{AsyncInstrument, SyncInstrument}, - Key, KeyValue, + InstrumentationScope, Key, KeyValue, }; -use crate::{ - metrics::{aggregation::Aggregation, internal::Measure}, - Scope, -}; +use crate::metrics::{aggregation::Aggregation, internal::Measure}; use super::data::Temporality; @@ -96,7 +93,7 @@ pub struct Instrument { /// Unit is the unit of measurement recorded by the instrument. pub unit: Cow<'static, str>, /// The instrumentation that created the instrument. - pub scope: Scope, + pub scope: InstrumentationScope, } impl Instrument { @@ -124,7 +121,7 @@ impl Instrument { } /// Set the instrument scope. - pub fn scope(mut self, scope: Scope) -> Self { + pub fn scope(mut self, scope: InstrumentationScope) -> Self { self.scope = scope; self } @@ -135,7 +132,7 @@ impl Instrument { && self.description == "" && self.kind.is_none() && self.unit == "" - && self.scope == Scope::default() + && self.scope == InstrumentationScope::default() } pub(crate) fn matches(&self, other: &Instrument) -> bool { diff --git a/opentelemetry-sdk/src/metrics/meter.rs b/opentelemetry-sdk/src/metrics/meter.rs index e2b6dedd1d..9a966a2ed0 100644 --- a/opentelemetry-sdk/src/metrics/meter.rs +++ b/opentelemetry-sdk/src/metrics/meter.rs @@ -8,6 +8,7 @@ use opentelemetry::{ InstrumentProvider, MetricsError, ObservableCounter, ObservableGauge, ObservableUpDownCounter, Result, UpDownCounter, }, + InstrumentationScope, }; use crate::metrics::{ @@ -15,7 +16,6 @@ use crate::metrics::{ internal::{self, Number}, pipeline::{Pipelines, Resolver}, }; -use crate::Scope; use super::noop::NoopSyncInstrument; @@ -45,7 +45,7 @@ const INSTRUMENT_UNIT_INVALID_CHAR: &str = "characters in instrument unit must b /// /// [Meter API]: opentelemetry::metrics::Meter pub(crate) struct SdkMeter { - scope: Scope, + scope: InstrumentationScope, pipes: Arc, u64_resolver: Resolver, i64_resolver: Resolver, @@ -53,7 +53,7 @@ pub(crate) struct SdkMeter { } impl SdkMeter { - pub(crate) fn new(scope: Scope, pipes: Arc) -> Self { + pub(crate) fn new(scope: InstrumentationScope, pipes: Arc) -> Self { let view_cache = Default::default(); SdkMeter { diff --git a/opentelemetry-sdk/src/metrics/meter_provider.rs b/opentelemetry-sdk/src/metrics/meter_provider.rs index 191ce6da6a..2226ac4a7b 100644 --- a/opentelemetry-sdk/src/metrics/meter_provider.rs +++ b/opentelemetry-sdk/src/metrics/meter_provider.rs @@ -10,9 +10,10 @@ use std::{ use opentelemetry::{ global, metrics::{Meter, MeterProvider, MetricsError, Result}, + InstrumentationScope, }; -use crate::{Resource, Scope}; +use crate::Resource; use super::{ meter::SdkMeter, noop::NoopMeter, pipeline::Pipelines, reader::MetricReader, view::View, @@ -36,7 +37,7 @@ pub struct SdkMeterProvider { #[derive(Debug)] struct SdkMeterProviderInner { pipes: Arc, - meters: Mutex>>, + meters: Mutex>>, is_shutdown: AtomicBool, } @@ -144,7 +145,7 @@ impl Drop for SdkMeterProviderInner { } } impl MeterProvider for SdkMeterProvider { - fn meter_with_scope(&self, scope: Scope) -> Meter { + fn meter_with_scope(&self, scope: InstrumentationScope) -> Meter { if self.inner.is_shutdown.load(Ordering::Relaxed) { return Meter::new(Arc::new(NoopMeter::new())); } @@ -238,9 +239,9 @@ mod tests { SERVICE_NAME, TELEMETRY_SDK_LANGUAGE, TELEMETRY_SDK_NAME, TELEMETRY_SDK_VERSION, }; use crate::testing::metrics::metric_reader::TestMetricReader; - use crate::{Resource, Scope}; - use opentelemetry::global; + use crate::Resource; use opentelemetry::metrics::MeterProvider; + use opentelemetry::{global, InstrumentationScope}; use opentelemetry::{Key, KeyValue, Value}; use std::env; @@ -434,7 +435,7 @@ mod tests { let _meter2 = provider.meter("test"); assert_eq!(provider.inner.meters.lock().unwrap().len(), 1); - let scope = Scope::builder("test") + let scope = InstrumentationScope::builder("test") .with_version("1.0.0") .with_schema_url("http://example.com") .build(); @@ -445,7 +446,7 @@ mod tests { assert_eq!(provider.inner.meters.lock().unwrap().len(), 2); // these are different meters because meter names are case sensitive - let mut library = Scope::builder("ABC") + let mut library = InstrumentationScope::builder("ABC") .with_version("1.0.0") .with_schema_url("http://example.com") .build(); diff --git a/opentelemetry-sdk/src/metrics/mod.rs b/opentelemetry-sdk/src/metrics/mod.rs index 1eddfbe158..58cde6f068 100644 --- a/opentelemetry-sdk/src/metrics/mod.rs +++ b/opentelemetry-sdk/src/metrics/mod.rs @@ -132,8 +132,9 @@ mod tests { use super::*; use crate::metrics::data::{ResourceMetrics, Temporality}; use crate::testing::metrics::InMemoryMetricsExporterBuilder; - use crate::{runtime, testing::metrics::InMemoryMetricsExporter, Scope}; + use crate::{runtime, testing::metrics::InMemoryMetricsExporter}; use opentelemetry::metrics::{Counter, Meter, UpDownCounter}; + use opentelemetry::InstrumentationScope; use opentelemetry::{metrics::MeterProvider as _, KeyValue}; use rand::{rngs, Rng, SeedableRng}; use std::borrow::Cow; @@ -637,7 +638,7 @@ mod tests { // Act // Meters are identical except for scope attributes, but scope attributes are not an identifying property. // Hence there should be a single metric stream output for this test. - let mut scope = Scope::builder("test.meter") + let mut scope = InstrumentationScope::builder("test.meter") .with_version("v0.1.0") .with_schema_url("http://example.com") .with_attributes(vec![KeyValue::new("key", "value1")]) diff --git a/opentelemetry-sdk/src/metrics/pipeline.rs b/opentelemetry-sdk/src/metrics/pipeline.rs index 55cc386661..e02e35ea2c 100644 --- a/opentelemetry-sdk/src/metrics/pipeline.rs +++ b/opentelemetry-sdk/src/metrics/pipeline.rs @@ -8,7 +8,7 @@ use std::{ use opentelemetry::{ global, metrics::{MetricsError, Result}, - KeyValue, + InstrumentationScope, KeyValue, }; use crate::{ @@ -22,7 +22,7 @@ use crate::{ reader::{MetricReader, SdkProducer}, view::View, }, - Resource, Scope, + Resource, }; use super::Aggregation; @@ -54,7 +54,7 @@ type GenericCallback = Arc; #[derive(Default)] struct PipelineInner { - aggregations: HashMap>, + aggregations: HashMap>, callbacks: Vec, } @@ -73,7 +73,7 @@ impl Pipeline { /// This method is not idempotent. Duplicate calls will result in duplicate /// additions, it is the callers responsibility to ensure this is called with /// unique values. - fn add_sync(&self, scope: Scope, i_sync: InstrumentSync) { + fn add_sync(&self, scope: InstrumentationScope, i_sync: InstrumentSync) { let _ = self.inner.lock().map(|mut inner| { inner.aggregations.entry(scope).or_default().push(i_sync); }); @@ -340,7 +340,7 @@ where /// is returned. fn cached_aggregator( &self, - scope: &Scope, + scope: &InstrumentationScope, kind: InstrumentKind, mut stream: Stream, ) -> Result>>> { diff --git a/opentelemetry-sdk/src/testing/logs/in_memory_exporter.rs b/opentelemetry-sdk/src/testing/logs/in_memory_exporter.rs index ee3af86bd6..0db7913adc 100644 --- a/opentelemetry-sdk/src/testing/logs/in_memory_exporter.rs +++ b/opentelemetry-sdk/src/testing/logs/in_memory_exporter.rs @@ -1,8 +1,9 @@ use crate::export::logs::{LogBatch, LogExporter}; use crate::logs::LogRecord; -use crate::{Resource, Scope}; +use crate::Resource; use async_trait::async_trait; use opentelemetry::logs::{LogError, LogResult}; +use opentelemetry::InstrumentationScope; use std::borrow::Cow; use std::sync::{Arc, Mutex}; @@ -55,17 +56,17 @@ pub struct OwnedLogData { /// Log record, which can be borrowed or owned. pub record: LogRecord, /// Instrumentation details for the emitter who produced this `LogEvent`. - pub instrumentation: Scope, + pub instrumentation: InstrumentationScope, } /// `LogDataWithResource` associates a [`LogRecord`] with a [`Resource`] and -/// [`Scope`]. +/// [`InstrumentationScope`]. #[derive(Clone, Debug)] pub struct LogDataWithResource { /// Log record pub record: LogRecord, /// Instrumentation details for the emitter who produced this `LogData`. - pub instrumentation: Scope, + pub instrumentation: InstrumentationScope, /// Resource for the emitter who produced this `LogData`. pub resource: Cow<'static, Resource>, } diff --git a/opentelemetry-sdk/src/testing/trace/span_exporters.rs b/opentelemetry-sdk/src/testing/trace/span_exporters.rs index e2dbed700d..f8a0776318 100644 --- a/opentelemetry-sdk/src/testing/trace/span_exporters.rs +++ b/opentelemetry-sdk/src/testing/trace/span_exporters.rs @@ -4,12 +4,12 @@ use crate::{ ExportError, }, trace::{SpanEvents, SpanLinks}, - Scope, }; use futures_util::future::BoxFuture; pub use opentelemetry::testing::trace::TestSpan; -use opentelemetry::trace::{ - SpanContext, SpanId, SpanKind, Status, TraceFlags, TraceId, TraceState, +use opentelemetry::{ + trace::{SpanContext, SpanId, SpanKind, Status, TraceFlags, TraceId, TraceState}, + InstrumentationScope, }; use std::fmt::{Display, Formatter}; @@ -32,7 +32,7 @@ pub fn new_test_export_span_data() -> SpanData { events: SpanEvents::default(), links: SpanLinks::default(), status: Status::Unset, - instrumentation_scope: Scope::default(), + instrumentation_scope: InstrumentationScope::default(), } } diff --git a/opentelemetry-sdk/src/trace/mod.rs b/opentelemetry-sdk/src/trace/mod.rs index 263e1b7e79..7ce5e7b977 100644 --- a/opentelemetry-sdk/src/trace/mod.rs +++ b/opentelemetry-sdk/src/trace/mod.rs @@ -45,12 +45,11 @@ mod tests { use crate::{ testing::trace::InMemorySpanExporterBuilder, trace::span_limit::{DEFAULT_MAX_EVENT_PER_SPAN, DEFAULT_MAX_LINKS_PER_SPAN}, - Scope, }; - use opentelemetry::testing::trace::TestSpan; use opentelemetry::trace::{ SamplingDecision, SamplingResult, SpanKind, Status, TraceContextExt, TraceState, }; + use opentelemetry::{testing::trace::TestSpan, InstrumentationScope}; use opentelemetry::{ trace::{ Event, Link, Span, SpanBuilder, SpanContext, SpanId, TraceFlags, TraceId, Tracer, @@ -328,7 +327,7 @@ mod tests { #[test] fn tracer_attributes() { let provider = TracerProvider::builder().build(); - let scope = Scope::builder("basic") + let scope = InstrumentationScope::builder("basic") .with_attributes(vec![KeyValue::new("test_k", "test_v")]) .build(); diff --git a/opentelemetry-sdk/src/trace/provider.rs b/opentelemetry-sdk/src/trace/provider.rs index a5e0a71e58..18dc5224cc 100644 --- a/opentelemetry-sdk/src/trace/provider.rs +++ b/opentelemetry-sdk/src/trace/provider.rs @@ -66,10 +66,11 @@ use crate::runtime::RuntimeChannel; use crate::trace::{ BatchSpanProcessor, Config, RandomIdGenerator, Sampler, SimpleSpanProcessor, SpanLimits, Tracer, }; +use crate::Resource; use crate::{export::trace::SpanExporter, trace::SpanProcessor}; -use crate::{Resource, Scope}; use once_cell::sync::{Lazy, OnceCell}; use opentelemetry::trace::TraceError; +use opentelemetry::InstrumentationScope; use opentelemetry::{otel_debug, trace::TraceResult}; use std::borrow::Cow; use std::sync::atomic::{AtomicBool, Ordering}; @@ -250,7 +251,7 @@ impl opentelemetry::trace::TracerProvider for TracerProvider { /// This implementation of `TracerProvider` produces `Tracer` instances. type Tracer = Tracer; - fn tracer_with_scope(&self, scope: Scope) -> Self::Tracer { + fn tracer_with_scope(&self, scope: InstrumentationScope) -> Self::Tracer { if self.inner.is_shutdown.load(Ordering::Relaxed) { return Tracer::new(scope, NOOP_TRACER_PROVIDER.clone()); } diff --git a/opentelemetry-sdk/src/trace/tracer.rs b/opentelemetry-sdk/src/trace/tracer.rs index e71bed5b8a..ddb7d9ed26 100644 --- a/opentelemetry-sdk/src/trace/tracer.rs +++ b/opentelemetry-sdk/src/trace/tracer.rs @@ -7,24 +7,21 @@ //! and exposes methods for creating and activating new `Spans`. //! //! Docs: -use crate::{ - trace::{ - provider::TracerProvider, - span::{Span, SpanData}, - IdGenerator, ShouldSample, SpanEvents, SpanLimits, SpanLinks, - }, - Scope, +use crate::trace::{ + provider::TracerProvider, + span::{Span, SpanData}, + IdGenerator, ShouldSample, SpanEvents, SpanLimits, SpanLinks, }; use opentelemetry::{ trace::{SamplingDecision, SpanBuilder, SpanContext, SpanKind, TraceContextExt, TraceFlags}, - Context, KeyValue, + Context, InstrumentationScope, KeyValue, }; use std::fmt; /// `Tracer` implementation to create and manage spans #[derive(Clone)] pub struct Tracer { - scope: Scope, + scope: InstrumentationScope, provider: TracerProvider, } @@ -41,7 +38,7 @@ impl fmt::Debug for Tracer { impl Tracer { /// Create a new tracer (used internally by `TracerProvider`s). - pub(crate) fn new(scope: Scope, provider: TracerProvider) -> Self { + pub(crate) fn new(scope: InstrumentationScope, provider: TracerProvider) -> Self { Tracer { scope, provider } } @@ -51,7 +48,7 @@ impl Tracer { } /// Instrumentation library information of this tracer. - pub(crate) fn instrumentation_scope(&self) -> &Scope { + pub(crate) fn instrumentation_scope(&self) -> &InstrumentationScope { &self.scope } diff --git a/opentelemetry-stdout/src/common.rs b/opentelemetry-stdout/src/common.rs index a05c42112f..83685d3f03 100644 --- a/opentelemetry-stdout/src/common.rs +++ b/opentelemetry-stdout/src/common.rs @@ -233,8 +233,8 @@ pub(crate) struct Scope { dropped_attributes_count: u64, } -impl From for Scope { - fn from(value: opentelemetry_sdk::Scope) -> Self { +impl From for Scope { + fn from(value: opentelemetry::InstrumentationScope) -> Self { Scope { name: value.name, version: value.version,