Class BatchLogRecordProcessor

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

Class Documentation

class BatchLogRecordProcessor : public opentelemetry::sdk::logs::LogRecordProcessor

This is an implementation of the LogRecordProcessor which creates batches of finished logs and passes the export-friendly log data representations to the configured LogRecordExporter.

Public Functions

explicit BatchLogRecordProcessor(std::unique_ptr<LogRecordExporter> &&exporter, const size_t max_queue_size = 2048, const std::chrono::milliseconds scheduled_delay_millis = std::chrono::milliseconds(5000), const size_t max_export_batch_size = 512)

Creates a batch log 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 logs to

  • max_queue_size – - The maximum buffer/queue size. After the size is reached, logs are dropped.

  • scheduled_delay_millis – - The time interval between two consecutive exports.

  • max_export_batch_size – - The maximum batch size of every export. It must be smaller or equal to max_queue_size

explicit BatchLogRecordProcessor(std::unique_ptr<LogRecordExporter> &&exporter, const BatchLogRecordProcessorOptions &options)

Creates a batch log 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 logs to

  • options – - The batch SpanProcessor options.

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

Makes a new recordable

virtual void OnEmit(std::unique_ptr<Recordable> &&record) noexcept override

Called when the Logger’s log method creates a log record

Parameters:

record – the log record

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

Export all log records 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 logs and passes them to the exporter. Any subsequent calls to ForceFlush or Shutdown will return immediately without doing anything.

NOTE: Timeout functionality not supported yet.

~BatchLogRecordProcessor() override

Class destructor which invokes the Shutdown() method.

Protected Functions

void DoBackgroundWork()

The background routine performed by the worker thread.

virtual void Export()

Exports all logs to the configured exporter.

void DrainQueue()

Called when Shutdown() is invoked. Completely drains the queue of all log records 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<LogRecordExporter> exporter_
const size_t max_queue_size_
const std::chrono::milliseconds scheduled_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<LogRecordExporter> &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}