Skip to content

Commit

Permalink
Remove InstrumentationScope as Scope re-export in SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
stormshield-fabs committed Oct 23, 2024
1 parent 356625a commit 8140e74
Show file tree
Hide file tree
Showing 23 changed files with 143 additions and 127 deletions.
28 changes: 24 additions & 4 deletions opentelemetry-proto/src/transform/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,18 @@ pub mod tonic {
#[cfg(any(feature = "trace", feature = "logs"))]
use opentelemetry_sdk::Resource;

impl From<(opentelemetry_sdk::Scope, Option<Cow<'static, str>>)> for InstrumentationScope {
fn from(data: (opentelemetry_sdk::Scope, Option<Cow<'static, str>>)) -> Self {
impl
From<(
opentelemetry::InstrumentationScope,
Option<Cow<'static, str>>,
)> for InstrumentationScope
{
fn from(
data: (
opentelemetry::InstrumentationScope,
Option<Cow<'static, str>>,
),
) -> Self {
let (library, target) = data;
if let Some(t) = target {
InstrumentationScope {
Expand All @@ -63,8 +73,18 @@ pub mod tonic {
}
}

impl From<(&opentelemetry_sdk::Scope, Option<Cow<'static, str>>)> for InstrumentationScope {
fn from(data: (&opentelemetry_sdk::Scope, Option<Cow<'static, str>>)) -> Self {
impl
From<(
&opentelemetry::InstrumentationScope,
Option<Cow<'static, str>>,
)> for InstrumentationScope
{
fn from(
data: (
&opentelemetry::InstrumentationScope,
Option<Cow<'static, str>>,
),
) -> Self {
let (library, target) = data;
if let Some(t) = target {
InstrumentationScope {
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-proto/src/transform/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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};

Expand All @@ -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(),
}
}

Expand Down
5 changes: 2 additions & 3 deletions opentelemetry-sdk/benches/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/benches/log_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 9 additions & 7 deletions opentelemetry-sdk/benches/log_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(())
Expand All @@ -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();
}

Expand All @@ -73,8 +75,8 @@ impl LogProcessor for CloningProcessor {

#[derive(Debug)]
struct SendToChannelProcessor {
sender: std::sync::mpsc::Sender<(LogRecord, Scope)>,
receiver: Arc<Mutex<std::sync::mpsc::Receiver<(LogRecord, Scope)>>>,
sender: std::sync::mpsc::Sender<(LogRecord, InstrumentationScope)>,
receiver: Arc<Mutex<std::sync::mpsc::Receiver<(LogRecord, InstrumentationScope)>>>,
}

impl SendToChannelProcessor {
Expand All @@ -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());
Expand Down
16 changes: 8 additions & 8 deletions opentelemetry-sdk/src/export/logs/mod.rs
Original file line number Diff line number Diff line change
@@ -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`.
Expand All @@ -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> {
Expand All @@ -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
Expand All @@ -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 }
}
}
Expand All @@ -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<Item = (&LogRecord, &Scope)> {
pub fn iter(&self) -> impl Iterator<Item = (&LogRecord, &InstrumentationScope)> {
self.data
.iter()
.map(|(record, library)| (*record, *library))
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/src/export/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
}
2 changes: 0 additions & 2 deletions opentelemetry-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
18 changes: 9 additions & 9 deletions opentelemetry-sdk/src/logs/log_emitter.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 }
}

Expand All @@ -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
}
}
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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.
}

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

Expand Down
Loading

0 comments on commit 8140e74

Please sign in to comment.