Struct tracing_opentelemetry::OpenTelemetryLayer
source · [−]pub struct OpenTelemetryLayer<S, T> { /* private fields */ }
Expand description
An OpenTelemetry propagation layer for use in a project that uses tracing.
Implementations
sourceimpl<S, T> OpenTelemetryLayer<S, T> where
S: Subscriber + for<'span> LookupSpan<'span>,
T: Tracer + PreSampledTracer + 'static,
impl<S, T> OpenTelemetryLayer<S, T> where
S: Subscriber + for<'span> LookupSpan<'span>,
T: Tracer + PreSampledTracer + 'static,
sourcepub fn new(tracer: T) -> Self
pub fn new(tracer: T) -> Self
Set the Tracer
that this layer will use to produce and track
OpenTelemetry Span
s.
Examples
use tracing_opentelemetry::OpenTelemetryLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::Registry;
// Create a jaeger exporter pipeline for a `trace_demo` service.
let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name("trace_demo")
.install_simple()
.expect("Error initializing Jaeger exporter");
// Create a layer with the configured tracer
let otel_layer = OpenTelemetryLayer::new(tracer);
// Use the tracing subscriber `Registry`, or any other subscriber
// that impls `LookupSpan`
let subscriber = Registry::default().with(otel_layer);
sourcepub fn with_tracer<Tracer>(
self,
tracer: Tracer
) -> OpenTelemetryLayer<S, Tracer> where
Tracer: Tracer + PreSampledTracer + 'static,
pub fn with_tracer<Tracer>(
self,
tracer: Tracer
) -> OpenTelemetryLayer<S, Tracer> where
Tracer: Tracer + PreSampledTracer + 'static,
Set the Tracer
that this layer will use to produce and track
OpenTelemetry Span
s.
Examples
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::Registry;
// Create a jaeger exporter pipeline for a `trace_demo` service.
let tracer = opentelemetry_jaeger::new_pipeline()
.with_service_name("trace_demo")
.install_simple()
.expect("Error initializing Jaeger exporter");
// Create a layer with the configured tracer
let otel_layer = tracing_opentelemetry::layer().with_tracer(tracer);
// Use the tracing subscriber `Registry`, or any other subscriber
// that impls `LookupSpan`
let subscriber = Registry::default().with(otel_layer);
sourcepub fn with_exception_fields(self, exception_fields: bool) -> Self
pub fn with_exception_fields(self, exception_fields: bool) -> Self
Sets whether or not span and event metadata should include OpenTelemetry
exception fields such as exception.message
and exception.backtrace
when an Error
value is recorded. If multiple error values are recorded
on the same span/event, only the most recently recorded error value will
show up under these fields.
These attributes follow the OpenTelemetry semantic conventions for exceptions.
By default, these attributes are not recorded.
sourcepub fn with_exception_field_propagation(
self,
exception_field_propagation: bool
) -> Self
pub fn with_exception_field_propagation(
self,
exception_field_propagation: bool
) -> Self
Sets whether or not reporting an Error
value on an event will
propagate the OpenTelemetry exception fields such as exception.message
and exception.backtrace
to the corresponding span. You do not need to
enable with_exception_fields
in order to enable this. If multiple
error values are recorded on the same span/event, only the most recently
recorded error value will show up under these fields.
These attributes follow the OpenTelemetry semantic conventions for exceptions.
By default, these attributes are not propagated to the span.
sourcepub fn with_location(self, location: bool) -> Self
pub fn with_location(self, location: bool) -> Self
Sets whether or not span and event metadata should include OpenTelemetry attributes with location information, such as the file, module and line number.
These attributes follow the OpenTelemetry semantic conventions for source locations.
By default, locations are enabled.
sourcepub fn with_event_location(self, event_location: bool) -> Self
👎 Deprecated since 0.17.3: renamed to OpenTelemetrySubscriber::with_location
pub fn with_event_location(self, event_location: bool) -> Self
renamed to OpenTelemetrySubscriber::with_location
Sets whether or not span and event metadata should include OpenTelemetry attributes with location information, such as the file, module and line number.
These attributes follow the OpenTelemetry semantic conventions for source locations.
By default, locations are enabled.
sourcepub fn with_tracked_inactivity(self, tracked_inactivity: bool) -> Self
pub fn with_tracked_inactivity(self, tracked_inactivity: bool) -> Self
Sets whether or not spans metadata should include the busy time (total time for which it was entered), and idle time (total time the span existed but was not entered).
sourcepub fn with_threads(self, threads: bool) -> Self
pub fn with_threads(self, threads: bool) -> Self
Sets whether or not spans record additional attributes for the thread name and thread ID of the thread they were created on, following the OpenTelemetry semantic conventions for threads.
By default, thread attributes are enabled.
Trait Implementations
sourceimpl<S> Default for OpenTelemetryLayer<S, NoopTracer> where
S: Subscriber + for<'span> LookupSpan<'span>,
impl<S> Default for OpenTelemetryLayer<S, NoopTracer> where
S: Subscriber + for<'span> LookupSpan<'span>,
sourceimpl<S, T> Layer<S> for OpenTelemetryLayer<S, T> where
S: Subscriber + for<'span> LookupSpan<'span>,
T: Tracer + PreSampledTracer + 'static,
impl<S, T> Layer<S> for OpenTelemetryLayer<S, T> where
S: Subscriber + for<'span> LookupSpan<'span>,
T: Tracer + PreSampledTracer + 'static,
sourcefn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>)
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>)
Creates an OpenTelemetry Span
for the corresponding tracing Span
.
sourcefn on_record(&self, id: &Id, values: &Record<'_>, ctx: Context<'_, S>)
fn on_record(&self, id: &Id, values: &Record<'_>, ctx: Context<'_, S>)
Record OpenTelemetry attributes
for the given values.
sourcefn on_enter(&self, id: &Id, ctx: Context<'_, S>)
fn on_enter(&self, id: &Id, ctx: Context<'_, S>)
Notifies this layer that a span with the given ID was entered.
sourcefn on_exit(&self, id: &Id, ctx: Context<'_, S>)
fn on_exit(&self, id: &Id, ctx: Context<'_, S>)
Notifies this layer that the span with the given ID was exited.
sourcefn on_follows_from(&self, id: &Id, follows: &Id, ctx: Context<'_, S>)
fn on_follows_from(&self, id: &Id, follows: &Id, ctx: Context<'_, S>)
Notifies this layer that a span with the ID span
recorded that it
follows from the span with the ID follows
. Read more
sourcefn on_layer(&mut self, subscriber: &mut S)
fn on_layer(&mut self, subscriber: &mut S)
Performs late initialization when attaching a Layer
to a
Subscriber
. Read more
sourcefn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest
Registers a new callsite with this layer, returning whether or not
the layer is interested in being notified about the callsite, similarly
to Subscriber::register_callsite
. Read more
sourcefn enabled(&self, metadata: &Metadata<'_>, ctx: Context<'_, S>) -> bool
fn enabled(&self, metadata: &Metadata<'_>, ctx: Context<'_, S>) -> bool
Returns true
if this layer is interested in a span or event with the
given metadata
in the current Context
, similarly to
Subscriber::enabled
. Read more
sourcefn event_enabled(&self, _event: &Event<'_>, _ctx: Context<'_, S>) -> bool
fn event_enabled(&self, _event: &Event<'_>, _ctx: Context<'_, S>) -> bool
sourcefn on_id_change(&self, _old: &Id, _new: &Id, _ctx: Context<'_, S>)
fn on_id_change(&self, _old: &Id, _new: &Id, _ctx: Context<'_, S>)
Notifies this layer that a span ID has been cloned, and that the subscriber returned a different ID. Read more
sourcefn and_then<L>(self, layer: L) -> Layered<L, Self, S> where
L: Layer<S>,
fn and_then<L>(self, layer: L) -> Layered<L, Self, S> where
L: Layer<S>,
Composes this layer around the given Layer
, returning a Layered
struct implementing Layer
. Read more
sourcefn with_subscriber(self, inner: S) -> Layered<Self, S, S>
fn with_subscriber(self, inner: S) -> Layered<Self, S, S>
Composes this Layer
with the given Subscriber
, returning a
Layered
struct that implements Subscriber
. Read more
sourcefn with_filter<F>(self, filter: F) -> Filtered<Self, F, S> where
F: Filter<S>,
fn with_filter<F>(self, filter: F) -> Filtered<Self, F, S> where
F: Filter<S>,
Auto Trait Implementations
impl<S, T> RefUnwindSafe for OpenTelemetryLayer<S, T> where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<S, T> Send for OpenTelemetryLayer<S, T> where
S: Send,
T: Send,
impl<S, T> Sync for OpenTelemetryLayer<S, T> where
S: Sync,
T: Sync,
impl<S, T> Unpin for OpenTelemetryLayer<S, T> where
S: Unpin,
T: Unpin,
impl<S, T> UnwindSafe for OpenTelemetryLayer<S, T> where
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> FutureExt for T
impl<T> FutureExt for T
sourcefn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
sourcefn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more