pub trait TraceContextExt {
// Required methods
fn current_with_span<T: Span + Send + Sync + 'static>(span: T) -> Self;
fn with_span<T: Span + Send + Sync + 'static>(&self, span: T) -> Self;
fn span(&self) -> SpanRef<'_>;
fn has_active_span(&self) -> bool;
fn with_remote_span_context(&self, span_context: SpanContext) -> Self;
}
Available on crate feature
trace
only.Expand description
Methods for storing and retrieving trace data in a context.
Required Methods§
Sourcefn current_with_span<T: Span + Send + Sync + 'static>(span: T) -> Self
fn current_with_span<T: Span + Send + Sync + 'static>(span: T) -> Self
Returns a clone of the current context with the included span.
This is useful for building tracers.
Sourcefn with_span<T: Span + Send + Sync + 'static>(&self, span: T) -> Self
fn with_span<T: Span + Send + Sync + 'static>(&self, span: T) -> Self
Returns a clone of this context with the included span.
This is useful for building tracers.
Sourcefn span(&self) -> SpanRef<'_>
fn span(&self) -> SpanRef<'_>
Returns a reference to this context’s span, or the default no-op span if none has been set.
§Examples
use opentelemetry::{
sdk,
trace::{SpanContext, TraceContextExt, Tracer, TracerProvider},
Context,
};
// returns a reference to an empty span by default
assert_eq!(Context::current().span().span_context(), &SpanContext::empty_context());
let provider = sdk::trace::TracerProvider::default();
provider.tracer("my-component").in_span("my-span", |cx| {
// Returns a reference to the current span if set
assert_ne!(cx.span().span_context(), &SpanContext::empty_context());
});
Sourcefn has_active_span(&self) -> bool
fn has_active_span(&self) -> bool
Used to see if a span has been marked as active
This is useful for building tracers.
Sourcefn with_remote_span_context(&self, span_context: SpanContext) -> Self
fn with_remote_span_context(&self, span_context: SpanContext) -> Self
Returns a copy of this context with the span context included.
This is useful for building propagators.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.