Class BatchSpanProcessor

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

Class Documentation

class BatchSpanProcessor : public opentelemetry::sdk::trace::SpanProcessor

This is an implementation of the SpanProcessor which creates batches of finished spans and passes the export-friendly span data representations to the configured SpanExporter.

Public Functions

BatchSpanProcessor(std::unique_ptr<SpanExporter> &&exporter, const BatchSpanProcessorOptions &options)

Creates a batch span processor by configuring the specified exporter and other parameters as per the official, language-agnostic opentelemetry specs.

Parameters:
  • exporter – - The backend exporter to pass the ended spans to.

  • options – - The batch SpanProcessor options.

virtual std::unique_ptr<Recordable> MakeRecordable() noexcept override

Requests a Recordable(Span) from the configured exporter.

Returns:

A recordable generated by the backend exporter

virtual void OnStart(Recordable &span, const opentelemetry::trace::SpanContext &parent_context) noexcept override

Called when a span is started.

NOTE: This method is a no-op.

Parameters:
  • span – - The span that just started

  • parent_context – - The parent context of the span that just started

virtual void OnEnd(std::unique_ptr<Recordable> &&span) noexcept override

Called when a span ends.

Parameters:

span – - A recordable for a span that just ended

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

Export all ended spans that have not been exported yet.

NOTE: Timeout functionality not supported yet.

virtual bool Shutdown(std::chrono::microseconds timeout = (std::chrono::microseconds::max)()) noexcept override

Shuts down the processor and does any cleanup required. Completely drains the buffer/queue of all its ended spans and passes them to the exporter. Any subsequent calls to OnStart, OnEnd, ForceFlush or Shutdown will return immediately without doing anything.

NOTE: Timeout functionality not supported yet.

~BatchSpanProcessor() override

Class destructor which invokes the Shutdown() method. The Shutdown() method is supposed to be invoked when the Tracer is shutdown (as per other languages), but the C++ Tracer only takes shared ownership of the processor, and thus doesn’t call Shutdown (as the processor might be shared with other Tracers).

Protected Functions

void DoBackgroundWork()

The background routine performed by the worker thread.

virtual void Export()

Exports all ended spans to the configured exporter.

void DrainQueue()

Called when Shutdown() is invoked. Completely drains the queue of all its ended spans and passes them to the exporter.

void GetWaitAdjustedTime(std::chrono::microseconds &timeout, std::chrono::time_point<std::chrono::system_clock> &start_time)

Protected Attributes

std::unique_ptr<SpanExporter> exporter_
const size_t max_queue_size_
const std::chrono::milliseconds schedule_delay_millis_
const size_t max_export_batch_size_
opentelemetry::sdk::common::CircularBuffer<Recordable> buffer_
std::shared_ptr<SynchronizationData> synchronization_data_
std::thread worker_thread_

Protected Static Functions

static void NotifyCompletion(uint64_t notify_force_flush, const std::unique_ptr<SpanExporter> &exporter, const std::shared_ptr<SynchronizationData> &synchronization_data)

Notify completion of shutdown and force flush. This may be called from the any thread at any time.

Parameters:
  • notify_force_flush – Sequence to indicate whether to notify force flush completion.

  • synchronization_data – Synchronization data to be notified.

struct SynchronizationData

Public Functions

inline SynchronizationData()

Public Members

std::condition_variable cv
std::condition_variable force_flush_cv
std::mutex cv_m
std::mutex force_flush_cv_m
std::mutex shutdown_m
std::atomic<bool> is_force_wakeup_background_worker = {false}
std::atomic<bool> is_shutdown = {false}
std::atomic<uint64_t> force_flush_pending_sequence = {0}
std::atomic<uint64_t> force_flush_notified_sequence = {0}
std::atomic<std::chrono::microseconds::rep> force_flush_timeout_us = {0}