opentelemetry.sdk._logs package

Warning

OpenTelemetry Python logs are in an experimental state. The APIs within opentelemetry.sdk._logs are subject to change in minor/patch releases and make no backward compatability guarantees at this time.

Once logs become stable, this package will be be renamed to opentelemetry.sdk.logs.

Submodules

class opentelemetry.sdk._logs.LogRecord(timestamp=None, trace_id=None, span_id=None, trace_flags=None, severity_text=None, severity_number=None, name=None, body=None, resource=None, attributes=None)[source]

Bases: object

A LogRecord instance represents an event being logged.

LogRecord instances are created and emitted via LogEmitter every time something is logged. They contain all the information pertinent to the event being logged.

to_json()[source]
Return type

str

class opentelemetry.sdk._logs.LogData(log_record, instrumentation_info)[source]

Bases: object

Readable LogRecord data plus associated InstrumentationLibrary.

class opentelemetry.sdk._logs.LogProcessor[source]

Bases: abc.ABC

Interface to hook the log record emitting action.

Log processors can be registered directly using LogEmitterProvider.add_log_processor() and they are invoked in the same order as they were registered.

abstract emit(log_data)[source]

Emits the LogData

abstract shutdown()[source]

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

abstract 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.

Returns

False if the timeout is exceeded, True otherwise.

class opentelemetry.sdk._logs.SynchronousMultiLogProcessor[source]

Bases: opentelemetry.sdk._logs.LogProcessor

Implementation of class:LogProcessor that forwards all received events to a list of log processors sequentially.

The underlying log processors are called in sequential order as they were added.

add_log_processor(log_processor)[source]

Adds a Logprocessor to the list of log processors handled by this instance

Return type

None

emit(log_data)[source]

Emits the LogData

Return type

None

shutdown()[source]

Shutdown the log processors one by one

Return type

None

force_flush(timeout_millis=30000)[source]

Force flush the log processors one by one

Parameters

timeout_millis (int) – The maximum amount of time to wait for logs to be exported. If the first n log processors exceeded the timeout then remaining log processors will not be flushed.

Return type

bool

Returns

True if all the log processors flushes the logs within timeout, False otherwise.

class opentelemetry.sdk._logs.ConcurrentMultiLogProcessor(max_workers=2)[source]

Bases: opentelemetry.sdk._logs.LogProcessor

Implementation of LogProcessor that forwards all received events to a list of log processors in parallel.

Calls to the underlying log processors are forwarded in parallel by submitting them to a thread pool executor and waiting until each log processor finished its work.

Parameters

max_workers (int) – The number of threads managed by the thread pool executor and thus defining how many log processors can work in parallel.

add_log_processor(log_processor)[source]
emit(log_data)[source]

Emits the LogData

shutdown()[source]

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

force_flush(timeout_millis=30000)[source]

Force flush the log processors in parallel.

Parameters

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

Return type

bool

Returns

True if all the log processors flushes the logs within timeout, False otherwise.

class opentelemetry.sdk._logs.OTLPHandler(level=0, log_emitter=None)[source]

Bases: logging.Handler

A handler class which writes logging records, in OTLP format, to a network destination or file.

emit(record)[source]

Emit a record.

The record is translated to OTLP format, and then sent across the pipeline.

Return type

None

flush()[source]

Flushes the logging output.

Return type

None

class opentelemetry.sdk._logs.LogEmitter(resource, multi_log_processor, instrumentation_info)[source]

Bases: object

property resource
emit(record)[source]

Emits the LogData by associating LogRecord and instrumentation info.

flush()[source]

Ensure all logging output has been flushed.

class opentelemetry.sdk._logs.LogEmitterProvider(resource=<opentelemetry.sdk.resources.Resource object>, shutdown_on_exit=True, multi_log_processor=None)[source]

Bases: object

property resource
get_log_emitter(instrumenting_module_name, instrumenting_module_verison='')[source]
Return type

LogEmitter

add_log_processor(log_processor)[source]

Registers a new LogProcessor for this LogEmitterProvider instance.

The log processors are invoked in the same order they are registered.

shutdown()[source]

Shuts down the log processors.

force_flush(timeout_millis=30000)[source]

Force flush the log processors.

Parameters

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

Return type

bool

Returns

True if all the log processors flushes the logs within timeout, False otherwise.

opentelemetry.sdk._logs.get_log_emitter_provider()[source]

Gets the current global LogEmitterProvider object.

Return type

LogEmitterProvider

opentelemetry.sdk._logs.set_log_emitter_provider(log_emitter_provider)[source]

Sets the current global LogEmitterProvider object.

This can only be done once, a warning will be logged if any furter attempt is made.

Return type

None

opentelemetry.sdk._logs.get_log_emitter(instrumenting_module_name, instrumenting_library_version='', log_emitter_provider=None)[source]

Returns a LogEmitter for use within a python process.

This function is a convenience wrapper for opentelemetry.sdk._logs.LogEmitterProvider.get_log_emitter.

If log_emitter_provider param is omitted the current configured one is used.

Return type

LogEmitter