opentelemetry.sdk._logs package

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

Bases: object

Readable LogRecord data plus associated InstrumentationLibrary.

class opentelemetry.sdk._logs.Logger(resource, multi_log_record_processor, instrumentation_scope)[source]

Bases: opentelemetry._logs._internal.Logger

property resource
emit(record)[source]

Emits the LogData by associating LogRecord and instrumentation info.

class opentelemetry.sdk._logs.LoggerProvider(resource=None, shutdown_on_exit=True, multi_log_record_processor=None)[source]

Bases: opentelemetry._logs._internal.LoggerProvider

property resource
get_logger(name, version=None, schema_url=None)[source]

Returns a Logger for use by the given instrumentation library.

For any two calls it is undefined whether the same or different Logger instances are returned, even for different library names.

This function may return different Logger types (e.g. a no-op logger vs. a functional logger).

Parameters
  • name (str) –

    The name of the instrumenting module. __name__ may not be used as this can result in different logger names if the loggers are in different files. It is better to use a fixed string that can be imported where needed and used consistently as the name of the logger.

    This should not be the name of the module that is instrumented but the name of the module doing the instrumentation. E.g., instead of "requests", use "opentelemetry.instrumentation.requests".

  • version (Optional[str]) – Optional. The version string of the instrumenting library. Usually this should be the same as importlib.metadata.version(instrumenting_library_name).

  • schema_url (Optional[str]) – Optional. Specifies the Schema URL of the emitted telemetry.

Return type

Logger

add_log_record_processor(log_record_processor)[source]

Registers a new LogRecordProcessor for this LoggerProvider 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.

class opentelemetry.sdk._logs.LoggingHandler(level=0, logger_provider=None)[source]

Bases: logging.Handler

A handler class which writes logging records, in OTLP format, to a network destination or file. Supports signals from the logging module. https://docs.python.org/3/library/logging.html

emit(record)[source]

Emit a record. Skip emitting if logger is NoOp.

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

Return type

None

flush()[source]

Flushes the logging output.

Return type

None

class opentelemetry.sdk._logs.LogLimits(max_attributes=None, max_attribute_length=None)[source]

Bases: object

This class is based on a SpanLimits class in the Tracing module.

This class represents the limits that should be enforced on recorded data such as events, links, attributes etc.

This class does not enforce any limits itself. It only provides a way to read limits from env, default values and from user provided arguments.

All limit arguments must be either a non-negative integer, None or LogLimits.UNSET.

  • All limit arguments are optional.

  • If a limit argument is not set, the class will try to read its value from the corresponding environment variable.

  • If the environment variable is not set, the default value, if any, will be used.

Limit precedence:

  • If a model specific limit is set, it will be used.

  • Else if the corresponding global limit is set, it will be used.

  • Else if the model specific limit has a default value, the default value will be used.

  • Else if the global limit has a default value, the default value will be used.

Parameters
  • max_attributes (Optional[int]) – Maximum number of attributes that can be added to a span, event, and link. Environment variable: OTEL_ATTRIBUTE_COUNT_LIMIT Default: {_DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT}

  • max_attribute_length (Optional[int]) – Maximum length an attribute value can have. Values longer than the specified length will be truncated.

UNSET = -1
class opentelemetry.sdk._logs.LogRecord(timestamp=None, observed_timestamp=None, trace_id=None, span_id=None, trace_flags=None, severity_text=None, severity_number=None, body=None, resource=None, attributes=None, limits=LogLimits(max_attributes=128, max_attribute_length=None))[source]

Bases: opentelemetry._logs._internal.LogRecord

A LogRecord instance represents an event being logged.

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

to_json(indent=4)[source]
Return type

str

property dropped_attributes
Return type

int

class opentelemetry.sdk._logs.LogRecordProcessor[source]

Bases: abc.ABC

Interface to hook the log record emitting action.

Log processors can be registered directly using LoggerProvider.add_log_record_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.Logger 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.