Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop include_trace_context parameter from Logs API/SDK #1133

Merged
merged 9 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions opentelemetry-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Removed

- Drop include_trace_context parameter from Logs API/SDK. [#1133](https://github.com/open-telemetry/opentelemetry-rust/issues/1133)
- Synchronous instruments no longer accepts `Context` while reporting
measurements. [#1076](https://github.com/open-telemetry/opentelemetry-rust/pull/1076).

Expand Down
12 changes: 3 additions & 9 deletions opentelemetry-api/src/global/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub trait ObjectSafeLoggerProvider {
fn boxed_logger(
&self,
library: Arc<InstrumentationLibrary>,
include_trace_context: bool,
) -> Box<dyn Logger + Send + Sync + 'static>;
}

Expand All @@ -36,9 +35,8 @@ where
fn boxed_logger(
&self,
library: Arc<InstrumentationLibrary>,
include_trace_context: bool,
) -> Box<dyn Logger + Send + Sync + 'static> {
Box::new(self.library_logger(library, include_trace_context))
Box::new(self.library_logger(library))
}
}

Expand Down Expand Up @@ -84,12 +82,8 @@ impl GlobalLoggerProvider {
impl LoggerProvider for GlobalLoggerProvider {
type Logger = BoxedLogger;

fn library_logger(
&self,
library: Arc<InstrumentationLibrary>,
include_trace_context: bool,
) -> Self::Logger {
BoxedLogger(self.provider.boxed_logger(library, include_trace_context))
fn library_logger(&self, library: Arc<InstrumentationLibrary>) -> Self::Logger {
BoxedLogger(self.provider.boxed_logger(library))
}
}

Expand Down
34 changes: 8 additions & 26 deletions opentelemetry-api/src/logs/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use crate::{logs::LogRecord, InstrumentationLibrary, KeyValue};

/// The interface for emitting [`LogRecord`]s.
pub trait Logger {
/// Emit a [`LogRecord`]. If this `Logger` was created with
/// `include_trace_context` set to `true`, the logger will set the record's
/// [`TraceContext`] to the active trace context, using the current thread's
/// [`Context`].
/// Emit a [`LogRecord`]. If there is active current thread's [`Context`],
/// the logger will set the record's [`TraceContext`] to the active trace context,
///
/// [`Context`]: crate::Context
/// [`TraceContext`]: crate::logs::TraceContext
Expand All @@ -24,28 +22,16 @@ pub trait LoggerProvider {
/// The `name` should be the application name or the name of the library
/// providing instrumentation. If the name is empty, then an
/// implementation-defined default name may be used instead.
///
/// If `include_trace_context` is `true`, the newly created [`Logger`]
/// should set the [`TraceContext`] associated with a record to the
/// current thread's active trace context, using [`Context`].
///
/// [`Context`]: crate::Context
/// [`TraceContext`]: crate::logs::TraceContext

fn versioned_logger(
&self,
name: impl Into<Cow<'static, str>>,
version: Option<Cow<'static, str>>,
schema_url: Option<Cow<'static, str>>,
attributes: Option<Vec<KeyValue>>,
include_trace_context: bool,
) -> Self::Logger {
self.library_logger(
Arc::new(InstrumentationLibrary::new(
name, version, schema_url, attributes,
)),
include_trace_context,
)
self.library_logger(Arc::new(InstrumentationLibrary::new(
name, version, schema_url, attributes,
)))
}

/// Returns a new versioned logger with the given instrumentation library.
Expand All @@ -66,20 +52,16 @@ pub trait LoggerProvider {
/// Some("https://opentelemetry.io/schema/1.0.0"),
/// None,
/// ));
/// let logger = provider.library_logger(library, true);
/// let logger = provider.library_logger(library);
/// ```
fn library_logger(
&self,
library: Arc<InstrumentationLibrary>,
include_trace_context: bool,
) -> Self::Logger;
fn library_logger(&self, library: Arc<InstrumentationLibrary>) -> Self::Logger;

/// Returns a new logger with the given name.
///
/// The `name` should be the application name or the name of the library
/// providing instrumentation. If the name is empty, then an
/// implementation-defined default name may be used instead.
fn logger(&self, name: impl Into<Cow<'static, str>>) -> Self::Logger {
self.versioned_logger(name, None, None, None, true)
self.versioned_logger(name, None, None, None)
}
}
7 changes: 1 addition & 6 deletions opentelemetry-api/src/logs/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ impl NoopLoggerProvider {
impl LoggerProvider for NoopLoggerProvider {
type Logger = NoopLogger;

fn library_logger(
&self,
_library: Arc<InstrumentationLibrary>,
_include_trace_context: bool,
) -> Self::Logger {
fn library_logger(&self, _library: Arc<InstrumentationLibrary>) -> Self::Logger {
NoopLogger(())
}

Expand All @@ -33,7 +29,6 @@ impl LoggerProvider for NoopLoggerProvider {
_version: Option<Cow<'static, str>>,
_schema_url: Option<Cow<'static, str>>,
_attributes: Option<Vec<KeyValue>>,
_include_trace_context: bool,
) -> Self::Logger {
NoopLogger(())
}
Expand Down
12 changes: 1 addition & 11 deletions opentelemetry-otlp/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,16 +417,12 @@ impl OtlpLogPipeline {
/// current crate version, using the configured log exporter.
///
/// [`Logger`]: opentelemetry_sdk::logs::Logger
pub fn simple(
self,
include_trace_context: bool,
) -> Result<opentelemetry_sdk::logs::Logger, LogError> {
pub fn simple(self) -> Result<opentelemetry_sdk::logs::Logger, LogError> {
Ok(build_simple_with_exporter(
self.exporter_builder
.ok_or(crate::Error::NoExporterBuilder)?
.build_log_exporter()?,
self.log_config,
include_trace_context,
))
}

Expand All @@ -438,23 +434,20 @@ impl OtlpLogPipeline {
pub fn batch<R: RuntimeChannel<BatchMessage>>(
self,
runtime: R,
include_trace_context: bool,
) -> Result<opentelemetry_sdk::logs::Logger, LogError> {
Ok(build_batch_with_exporter(
self.exporter_builder
.ok_or(crate::Error::NoExporterBuilder)?
.build_log_exporter()?,
self.log_config,
runtime,
include_trace_context,
))
}
}

fn build_simple_with_exporter(
exporter: LogExporter,
log_config: Option<opentelemetry_sdk::logs::Config>,
include_trace_context: bool,
) -> opentelemetry_sdk::logs::Logger {
let mut provider_builder =
opentelemetry_sdk::logs::LoggerProvider::builder().with_simple_exporter(exporter);
Expand All @@ -467,15 +460,13 @@ fn build_simple_with_exporter(
Some(Cow::Borrowed(env!("CARGO_PKG_VERSION"))),
None,
None,
include_trace_context,
)
}

fn build_batch_with_exporter<R: RuntimeChannel<BatchMessage>>(
exporter: LogExporter,
log_config: Option<opentelemetry_sdk::logs::Config>,
runtime: R,
include_trace_context: bool,
) -> opentelemetry_sdk::logs::Logger {
let mut provider_builder =
opentelemetry_sdk::logs::LoggerProvider::builder().with_batch_exporter(exporter, runtime);
Expand All @@ -488,6 +479,5 @@ fn build_batch_with_exporter<R: RuntimeChannel<BatchMessage>>(
Some(Cow::Borrowed("CARGO_PKG_VERSION")),
None,
None,
include_trace_context,
)
}
39 changes: 12 additions & 27 deletions opentelemetry-sdk/src/logs/log_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ impl opentelemetry_api::logs::LoggerProvider for LoggerProvider {
version: Option<Cow<'static, str>>,
schema_url: Option<Cow<'static, str>>,
attributes: Option<Vec<opentelemetry_api::KeyValue>>,
include_trace_context: bool,
) -> Logger {
let name = name.into();

Expand All @@ -43,23 +42,16 @@ impl opentelemetry_api::logs::LoggerProvider for LoggerProvider {
name
};

self.library_logger(
Arc::new(InstrumentationLibrary::new(
component_name,
version,
schema_url,
attributes,
)),
include_trace_context,
)
self.library_logger(Arc::new(InstrumentationLibrary::new(
component_name,
version,
schema_url,
attributes,
)))
}

fn library_logger(
&self,
library: Arc<InstrumentationLibrary>,
include_trace_context: bool,
) -> Self::Logger {
Logger::new(library, Arc::downgrade(&self.inner), include_trace_context)
fn library_logger(&self, library: Arc<InstrumentationLibrary>) -> Self::Logger {
Logger::new(library, Arc::downgrade(&self.inner))
}
}

Expand Down Expand Up @@ -182,7 +174,6 @@ impl Builder {
///
/// [`LogRecord`]: opentelemetry_api::logs::LogRecord
pub struct Logger {
include_trace_context: bool,
instrumentation_lib: Arc<InstrumentationLibrary>,
provider: Weak<LoggerProviderInner>,
}
Expand All @@ -191,10 +182,8 @@ impl Logger {
pub(crate) fn new(
instrumentation_lib: Arc<InstrumentationLibrary>,
provider: Weak<LoggerProviderInner>,
include_trace_context: bool,
) -> Self {
Logger {
include_trace_context,
instrumentation_lib,
provider,
}
Expand All @@ -218,14 +207,10 @@ impl opentelemetry_api::logs::Logger for Logger {
Some(provider) => provider,
None => return,
};
let trace_context = if self.include_trace_context {
Context::map_current(|cx| {
cx.has_active_span()
.then(|| TraceContext::from(cx.span().span_context()))
})
} else {
None
};
let trace_context = Context::map_current(|cx| {
cx.has_active_span()
.then(|| TraceContext::from(cx.span().span_context()))
});
let config = provider.config();
for processor in provider.log_processors() {
let mut record = record.clone();
Expand Down
Loading