Skip to content

Commit

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

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

impl
From<(
&opentelemetry_sdk::InstrumentationScope,
Option<Cow<'static, str>>,
)> for InstrumentationScope
{
fn from(
data: (
&opentelemetry_sdk::InstrumentationScope,
Option<Cow<'static, str>>,
),
) -> Self {
impl From<(&opentelemetry_sdk::Scope, Option<Cow<'static, str>>)> for InstrumentationScope {
fn from(data: (&opentelemetry_sdk::Scope, Option<Cow<'static, str>>)) -> Self {
let (library, target) = data;
if let Some(t) = target {
InstrumentationScope {
Expand Down
7 changes: 3 additions & 4 deletions opentelemetry-proto/src/transform/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +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::InstrumentationScope, Vec<&SpanData>>,
span| {
|mut scope_map: HashMap<&opentelemetry_sdk::Scope, Vec<&SpanData>>, span| {
let instrumentation = &span.instrumentation_scope;
scope_map.entry(instrumentation).or_default().push(span);
scope_map
Expand Down Expand Up @@ -202,7 +201,7 @@ mod tests {
use opentelemetry_sdk::export::trace::SpanData;
use opentelemetry_sdk::resource::Resource;
use opentelemetry_sdk::trace::{SpanEvents, SpanLinks};
use opentelemetry_sdk::InstrumentationScope;
use opentelemetry_sdk::Scope;
use std::borrow::Cow;
use std::time::{Duration, SystemTime};

Expand All @@ -227,7 +226,7 @@ mod tests {
events: SpanEvents::default(),
links: SpanLinks::default(),
status: Status::Unset,
instrumentation_scope: InstrumentationScope::builder(instrumentation_name).build(),
instrumentation_scope: Scope::builder(instrumentation_name).build(),
}
}

Expand Down
5 changes: 3 additions & 2 deletions opentelemetry-sdk/benches/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ use opentelemetry::logs::{
};
use opentelemetry::trace::Tracer;
use opentelemetry::trace::TracerProvider as _;
use opentelemetry::{InstrumentationScope, Key};
use opentelemetry::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: &InstrumentationScope) {}
fn emit(&self, _data: &mut LogRecord, _scope: &Scope) {}

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: &InstrumentationScope) {
fn emit(&self, record: &mut LogRecord, scope: &Scope) {
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: &InstrumentationScope) {
fn emit(&self, record: &mut LogRecord, scope: &Scope) {
let logs = [(record as &LogRecord, scope)];
self.exporter
.lock()
Expand Down
12 changes: 6 additions & 6 deletions opentelemetry-sdk/benches/log_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use std::{

use criterion::{criterion_group, criterion_main, Criterion};
use opentelemetry::logs::{LogRecord as _, LogResult, Logger as _, LoggerProvider as _, Severity};
use opentelemetry::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 +43,7 @@ fn create_log_record(logger: &Logger) -> LogRecord {
struct NoopProcessor;

impl LogProcessor for NoopProcessor {
fn emit(&self, _data: &mut LogRecord, _scope: &InstrumentationScope) {}
fn emit(&self, _data: &mut LogRecord, _scope: &Scope) {}

fn force_flush(&self) -> LogResult<()> {
Ok(())
Expand All @@ -58,7 +58,7 @@ impl LogProcessor for NoopProcessor {
struct CloningProcessor;

impl LogProcessor for CloningProcessor {
fn emit(&self, data: &mut LogRecord, _scope: &InstrumentationScope) {
fn emit(&self, data: &mut LogRecord, _scope: &Scope) {
let _data_cloned = data.clone();
}

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

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

impl SendToChannelProcessor {
Expand All @@ -101,7 +101,7 @@ impl SendToChannelProcessor {
}

impl LogProcessor for SendToChannelProcessor {
fn emit(&self, record: &mut LogRecord, scope: &InstrumentationScope) {
fn emit(&self, record: &mut LogRecord, scope: &Scope) {
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
20 changes: 9 additions & 11 deletions opentelemetry-sdk/src/export/logs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +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},
InstrumentationScope,
};
use opentelemetry::logs::{LogError, LogResult};
use std::fmt::Debug;

/// A batch of log records to be exported by a `LogExporter`.
Expand All @@ -22,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 `InstrumentationScope`.
data: &'a [(&'a LogRecord, &'a InstrumentationScope)],
/// a `LogRecord` and a reference to an `Scope`.
data: &'a [(&'a LogRecord, &'a Scope)],
}

impl<'a> LogBatch<'a> {
Expand All @@ -32,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 `InstrumentationScope`. These tuples represent the log records
/// and a reference to an `Scope`. These tuples represent the log records
/// and their associated instrumentation libraries to be exported.
///
/// # Returns
Expand All @@ -42,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 InstrumentationScope)]) -> LogBatch<'a> {
pub fn new(data: &'a [(&'a LogRecord, &'a Scope)]) -> LogBatch<'a> {
LogBatch { data }
}
}
Expand All @@ -51,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 `InstrumentationScope`.
/// and an `Scope`.
///
/// # Returns
///
/// An iterator that yields references to the `LogRecord` and `InstrumentationScope` in the batch.
/// An iterator that yields references to the `LogRecord` and `Scope` in the batch.
///
pub fn iter(&self) -> impl Iterator<Item = (&LogRecord, &InstrumentationScope)> {
pub fn iter(&self) -> impl Iterator<Item = (&LogRecord, &Scope)> {
self.data
.iter()
.map(|(record, library)| (*record, *library))
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/export/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ pub struct SpanData {
/// Span status
pub status: Status,
/// Instrumentation library that produced this span
pub instrumentation_scope: crate::InstrumentationScope,
pub instrumentation_scope: crate::Scope,
}
5 changes: 0 additions & 5 deletions opentelemetry-sdk/src/instrumentation.rs

This file was deleted.

5 changes: 3 additions & 2 deletions opentelemetry-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@

pub mod export;
pub(crate) mod growable_array;
mod instrumentation;

#[cfg(feature = "logs")]
#[cfg_attr(docsrs, doc(cfg(feature = "logs")))]
pub mod logs;
Expand All @@ -146,6 +146,7 @@ pub mod trace;
#[doc(hidden)]
pub mod util;

pub use instrumentation::{InstrumentationScope, Scope};
#[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};
use crate::{export::logs::LogExporter, runtime::RuntimeChannel, Resource, Scope};
use opentelemetry::{
logs::{LogError, LogResult},
otel_debug,
trace::TraceContextExt,
Context, InstrumentationScope,
Context,
};

#[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: InstrumentationScope) -> Self::Logger {
fn logger_with_scope(&self, scope: Scope) -> 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: InstrumentationScope,
scope: Scope,
provider: LoggerProvider,
}

impl Logger {
pub(crate) fn new(scope: InstrumentationScope, provider: LoggerProvider) -> Self {
pub(crate) fn new(scope: Scope, 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) -> &InstrumentationScope {
pub fn instrumentation_scope(&self) -> &Scope {
&self.scope
}
}
Expand Down Expand Up @@ -327,7 +327,7 @@ mod tests {
}

impl LogProcessor for ShutdownTestLogProcessor {
fn emit(&self, _data: &mut LogRecord, _scope: &InstrumentationScope) {
fn emit(&self, _data: &mut LogRecord, _scope: &Scope) {
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: &InstrumentationScope) {
fn emit(&self, _data: &mut LogRecord, _scope: &Scope) {
// nothing to do.
}

Expand Down Expand Up @@ -737,7 +737,7 @@ mod tests {
}

impl LogProcessor for CountingShutdownProcessor {
fn emit(&self, _data: &mut LogRecord, _scope: &InstrumentationScope) {
fn emit(&self, _data: &mut LogRecord, _scope: &Scope) {
// nothing to do
}

Expand Down
Loading

0 comments on commit 356625a

Please sign in to comment.