Trait tracing_opentelemetry::PreSampledTracer[][src]

pub trait PreSampledTracer {
    fn sampled_context(&self, builder: &mut SpanBuilder) -> OtelContext;
fn new_trace_id(&self) -> TraceId;
fn new_span_id(&self) -> SpanId; }
Expand description

An interface for authors of OpenTelemetry SDKs to build pre-sampled tracers.

The OpenTelemetry spec does not allow trace ids to be updated after a span has been created. In order to associate extracted parent trace ids with existing tracing spans, tracing-opentelemetry builds up otel span data using a SpanBuilder instead, and creates / exports full otel spans only when the associated tracing span is closed. However, in order to properly inject otel Context information to downstream requests, the sampling state must now be known before the otel span has been created.

The logic for coming to a sampling decision and creating an injectable span context from a SpanBuilder is encapsulated in the PreSampledTracer::sampled_context method and has been implemented for the standard OpenTelemetry SDK, but this trait may be implemented by authors of alternate OpenTelemetry SDK implementations if they wish to have tracing compatibility.

See the OpenTelemetrySpanExt::set_parent and OpenTelemetrySpanExt::context methods for example usage.

Required methods

Produce an otel context containing an active and pre-sampled span for the given span builder data.

The sampling decision, span context information, and parent context values must match the values recorded when the tracing span is closed.

Generate a new trace id.

Generate a new span id.

Implementations on Foreign Types

Implementors