pub struct TraceContext { /* private fields */ }Expand description
A W3C Trace Context attached to a job, used to link a producer’s trace to the worker that processes the job.
The traceparent is validated on construction. With the opentelemetry
feature enabled, Worker and the client wire this up
automatically — you only need this type to bridge to or from an external
trace propagation system by hand.
Implementations§
Source§impl TraceContext
impl TraceContext
Sourcepub fn new(traceparent: impl Into<String>) -> Result<Self, TraceContextError>
pub fn new(traceparent: impl Into<String>) -> Result<Self, TraceContextError>
Creates a trace context from a W3C traceparent, validating its format.
The expected shape is version-trace_id-span_id-flags, e.g.
00-<32 hex>-<16 hex>-<2 hex>.
Sourcepub fn with_tracestate(self, ts: impl Into<String>) -> Self
pub fn with_tracestate(self, ts: impl Into<String>) -> Self
Attaches a W3C tracestate (vendor-specific trace data).
Sourcepub fn traceparent(&self) -> &str
pub fn traceparent(&self) -> &str
Returns the W3C traceparent.
Sourcepub fn tracestate(&self) -> Option<&str>
pub fn tracestate(&self) -> Option<&str>
Returns the W3C tracestate, if one was set.
Source§impl TraceContext
impl TraceContext
Sourcepub fn from_current_otel() -> Option<Self>
pub fn from_current_otel() -> Option<Self>
Captures the current OpenTelemetry context as a TraceContext, or
None if there is no valid active span.
Requires the opentelemetry feature.
Sourcepub fn attach_to_otel(&self) -> ContextGuard
pub fn attach_to_otel(&self) -> ContextGuard
Installs this trace context as the current OpenTelemetry context for as long as the returned guard is held.
Requires the opentelemetry feature.
Sourcepub fn otel_span_context(&self) -> Option<SpanContext>
pub fn otel_span_context(&self) -> Option<SpanContext>
Decodes this trace context into an OpenTelemetry SpanContext, or
None if it does not represent a valid span. Used to add a span link
from the worker’s process span back to the producer.
Requires the opentelemetry feature.
Trait Implementations§
Source§impl Clone for TraceContext
impl Clone for TraceContext
Source§fn clone(&self) -> TraceContext
fn clone(&self) -> TraceContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TraceContext
impl Debug for TraceContext
Source§impl PartialEq for TraceContext
impl PartialEq for TraceContext
impl StructuralPartialEq for TraceContext
Auto Trait Implementations§
impl Freeze for TraceContext
impl RefUnwindSafe for TraceContext
impl Send for TraceContext
impl Sync for TraceContext
impl Unpin for TraceContext
impl UnsafeUnpin for TraceContext
impl UnwindSafe for TraceContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request