opentelemetry.sdk._logs.export

class opentelemetry.sdk._logs.export.BatchLogRecordProcessor(exporter, schedule_delay_millis=None, max_export_batch_size=None, export_timeout_millis=None, max_queue_size=None, *, meter_provider=None)[source]

Bases: LogRecordProcessor

This is an implementation of LogRecordProcessor which creates batches of received logs and sends them to the configured LogRecordExporter.

BatchLogRecordProcessor is configurable with the following environment variables which correspond to constructor parameters:

All the logic for emitting logs, shutting down etc. resides in the BatchProcessor class.

on_emit(log_record)[source]

Emits the ReadWriteLogRecord.

Implementers should handle any exceptions raised during log processing to prevent application crashes. See the class docstring for details on error handling expectations.

Return type:

None

shutdown()[source]

Called when a opentelemetry.sdk._logs.Logger is shutdown

force_flush(timeout_millis=None)[source]

Export all the received logs to the configured Exporter that have not yet been exported.

Parameters:

timeout_millis (Optional[int]) – The maximum amount of time to wait for logs to be exported.

Return type:

bool

Returns:

False if the timeout is exceeded, True otherwise.

class opentelemetry.sdk._logs.export.ConsoleLogExporter(out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, formatter=<function ConsoleLogRecordExporter.<lambda>>)[source]

Bases: ConsoleLogRecordExporter

class opentelemetry.sdk._logs.export.ConsoleLogRecordExporter(out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, formatter=<function ConsoleLogRecordExporter.<lambda>>)[source]

Bases: LogRecordExporter

Implementation of LogRecordExporter that prints log records to the console.

This class can be used for diagnostic purposes. It prints the exported log records to the console STDOUT.

export(batch)[source]

Exports a batch of logs.

Parameters:

batch (Sequence[ReadableLogRecord]) – The list of ReadableLogRecord objects to be exported.

Returns:

The result of the export.

Raises:

Exception – This method may raise exceptions on network errors, timeouts, or other failures. Callers (i.e., log processors) should handle these exceptions to comply with OpenTelemetry error handling principles.

shutdown()[source]

Shuts down the exporter.

Called when the SDK is shut down.

class opentelemetry.sdk._logs.export.LogExporter(**kwargs)[source]

Bases: LogRecordExporter

class opentelemetry.sdk._logs.export.LogRecordExporter[source]

Bases: ABC

Interface for exporting logs.

Interface to be implemented by services that want to export logs received in their own format.

To export data this MUST be registered to the opentelemetry.sdk._logs.Logger using a log processor.

Important

The export() method may raise exceptions (e.g., network errors, timeouts, serialization errors). It is the responsibility of the LogRecordProcessor calling this exporter to handle these exceptions appropriately to prevent application crashes. See LogRecordProcessor for guidance on implementing proper error handling.

abstract export(batch)[source]

Exports a batch of logs.

Parameters:

batch (Sequence[ReadableLogRecord]) – The list of ReadableLogRecord objects to be exported.

Return type:

LogRecordExportResult

Returns:

The result of the export.

Raises:

Exception – This method may raise exceptions on network errors, timeouts, or other failures. Callers (i.e., log processors) should handle these exceptions to comply with OpenTelemetry error handling principles.

abstract shutdown()[source]

Shuts down the exporter.

Called when the SDK is shut down.

class opentelemetry.sdk._logs.export.LogExportResult(value)[source]

Bases: Enum

An enumeration.

SUCCESS = 0
FAILURE = 1
class opentelemetry.sdk._logs.export.LogRecordExportResult(value)[source]

Bases: Enum

An enumeration.

SUCCESS = 0
FAILURE = 1
class opentelemetry.sdk._logs.export.SimpleLogRecordProcessor(exporter, *, meter_provider=None)[source]

Bases: LogRecordProcessor

Implementation of LogRecordProcessor that exports logs synchronously.

This processor passes received logs directly to the configured LogRecordExporter as soon as they are emitted.

This class serves as a reference implementation for custom log processors, demonstrating proper error handling. Note how the on_emit method wraps the exporter call in a try/except block to prevent exceptions from propagating to the application.

on_emit(log_record)[source]

Emits the ReadWriteLogRecord.

Implementers should handle any exceptions raised during log processing to prevent application crashes. See the class docstring for details on error handling expectations.

shutdown()[source]

Called when a opentelemetry.sdk._logs.Logger is shutdown

force_flush(timeout_millis=30000)[source]

Export all the received logs to the configured Exporter that have not yet been exported.

Parameters:

timeout_millis (int) – The maximum amount of time to wait for logs to be exported.

Return type:

bool

Returns:

False if the timeout is exceeded, True otherwise.

class opentelemetry.sdk._logs.export.InMemoryLogExporter(**kwargs)[source]

Bases: InMemoryLogRecordExporter

class opentelemetry.sdk._logs.export.InMemoryLogRecordExporter[source]

Bases: LogRecordExporter

Implementation of LogRecordExporter that stores logs in memory.

This class can be used for testing purposes. It stores the exported logs in a list in memory that can be retrieved using the get_finished_logs() method.

clear()[source]
Return type:

None

get_finished_logs()[source]
Return type:

tuple[ReadableLogRecord, ...]

export(batch)[source]

Exports a batch of logs.

Parameters:

batch (Sequence[ReadableLogRecord]) – The list of ReadableLogRecord objects to be exported.

Return type:

LogRecordExportResult

Returns:

The result of the export.

Raises:

Exception – This method may raise exceptions on network errors, timeouts, or other failures. Callers (i.e., log processors) should handle these exceptions to comply with OpenTelemetry error handling principles.

shutdown()[source]

Shuts down the exporter.

Called when the SDK is shut down.

Return type:

None