Class TracerContext

Class Documentation

class TracerContext

A class which stores the TracerProvider context.

This class meets the following design criteria:

  • A shared reference between TracerProvider and Tracers instantiated.

  • A thread-safe class that allows updating/altering processor/exporter pipelines and sampling config.

  • The owner/destroyer of Processors/Exporters. These will remain active until this class is destroyed. I.e. Sampling, Exporting, flushing, Custom Iterator etc. are all ok if this object is alive, and they will work together. If this object is destroyed, then no shared references to Processor, Exporter, Recordable, Custom Iterator etc. should exist, and all associated pipelines will have been flushed.

Public Functions

explicit TracerContext(std::vector<std::unique_ptr<SpanProcessor>> &&processor, opentelemetry::sdk::resource::Resource resource = opentelemetry::sdk::resource::Resource::Create({}), std::unique_ptr<Sampler> sampler = std::unique_ptr<AlwaysOnSampler>(new AlwaysOnSampler), std::unique_ptr<IdGenerator> id_generator = std::unique_ptr<IdGenerator>(new RandomIdGenerator())) noexcept
void AddProcessor(std::unique_ptr<SpanProcessor> processor) noexcept

Attaches a span processor to list of configured processors to this tracer context. Processor once attached can’t be removed.

Note: This method is not thread safe.

Parameters

processor – The new span processor for this tracer. This must not be a nullptr. Ownership is given to the TracerContext.

Sampler &GetSampler() const noexcept

Obtain the sampler associated with this tracer.

Returns

The sampler for this tracer.

SpanProcessor &GetProcessor() const noexcept

Obtain the configured (composite) processor.

Note: When more than one processor is active, this will return an “aggregate” processor

const opentelemetry::sdk::resource::Resource &GetResource() const noexcept

Obtain the resource associated with this tracer context.

Returns

The resource for this tracer context.

opentelemetry::sdk::trace::IdGenerator &GetIdGenerator() const noexcept

Obtain the Id Generator associated with this tracer context.

Returns

The ID Generator for this tracer context.

bool ForceFlush(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept

Force all active SpanProcessors to flush any buffered spans within the given timeout.

bool Shutdown() noexcept

Shutdown the span processor associated with this tracer provider.