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:
LogRecordProcessorThis 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:
- shutdown()[source]
Called when a
opentelemetry.sdk._logs.Loggeris shutdown
- 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:
LogRecordExporterImplementation of
LogRecordExporterthat 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 ofReadableLogRecordobjects 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.
- class opentelemetry.sdk._logs.export.LogExporter(**kwargs)[source]
Bases:
LogRecordExporter
- class opentelemetry.sdk._logs.export.LogRecordExporter[source]
Bases:
ABCInterface 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.Loggerusing a log processor.Important
The
export()method may raise exceptions (e.g., network errors, timeouts, serialization errors). It is the responsibility of theLogRecordProcessorcalling this exporter to handle these exceptions appropriately to prevent application crashes. SeeLogRecordProcessorfor guidance on implementing proper error handling.- abstract export(batch)[source]
Exports a batch of logs.
- Parameters:
batch (
Sequence[ReadableLogRecord]) – The list ofReadableLogRecordobjects to be exported.- Return type:
- 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.
- class opentelemetry.sdk._logs.export.LogExportResult(value)[source]
Bases:
EnumAn enumeration.
- SUCCESS = 0
- FAILURE = 1
- class opentelemetry.sdk._logs.export.LogRecordExportResult(value)[source]
Bases:
EnumAn enumeration.
- SUCCESS = 0
- FAILURE = 1
- class opentelemetry.sdk._logs.export.SimpleLogRecordProcessor(exporter, *, meter_provider=None)[source]
Bases:
LogRecordProcessorImplementation of LogRecordProcessor that exports logs synchronously.
This processor passes received logs directly to the configured
LogRecordExporteras soon as they are emitted.This class serves as a reference implementation for custom log processors, demonstrating proper error handling. Note how the
on_emitmethod 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.Loggeris shutdown
- class opentelemetry.sdk._logs.export.InMemoryLogExporter(**kwargs)[source]
Bases:
InMemoryLogRecordExporter
- class opentelemetry.sdk._logs.export.InMemoryLogRecordExporter[source]
Bases:
LogRecordExporterImplementation of
LogRecordExporterthat 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.- export(batch)[source]
Exports a batch of logs.
- Parameters:
batch (
Sequence[ReadableLogRecord]) – The list ofReadableLogRecordobjects to be exported.- Return type:
- 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.