[][src]Trait opentelemetry::api::trace::TraceContextExt

pub trait TraceContextExt {
    fn current_with_span<T: Span + Send + Sync>(span: T) -> Self;
fn with_span<T: Span + Send + Sync>(&self, span: T) -> Self;
fn span(&self) -> &dyn Span;
fn with_remote_span_reference(&self, span_reference: SpanReference) -> Self;
fn remote_span_reference(&self) -> Option<&SpanReference>; }

Methods for storing and retrieving trace data in a context.

Required methods

fn current_with_span<T: Span + Send + Sync>(span: T) -> Self

Returns a clone of the current context with the included span.

This is useful for building tracers.

fn with_span<T: Span + Send + Sync>(&self, span: T) -> Self

Returns a clone of this context with the included span.

This is useful for building tracers.

fn span(&self) -> &dyn Span

Returns a reference to this context's span, or the default no-op span if none has been set.

Examples

use opentelemetry::{api, api::{Context, trace::{TracerProvider, TraceContextExt, Tracer}}, sdk::trace as sdktrace};

// returns a reference to an empty span by default
assert_eq!(Context::current().span().span_reference(), api::trace::SpanReference::empty_context());

sdktrace::TracerProvider::default().get_tracer("my-component", None).in_span("my-span", |cx| {
    // Returns a reference to the current span if set
    assert_ne!(cx.span().span_reference(), api::trace::SpanReference::empty_context());
});

fn with_remote_span_reference(&self, span_reference: SpanReference) -> Self

Returns a copy of this context with the span context included.

This is useful for building propagators.

fn remote_span_reference(&self) -> Option<&SpanReference>

Returns a reference to the remote span context data stored in this context, or none if no remote span context has been set.

This is useful for building tracers.

Loading content...

Implementors

impl TraceContextExt for Context[src]

Loading content...