opentelemetry._logs package
Submodules
- opentelemetry._logs.severity
SeverityNumber
SeverityNumber.UNSPECIFIED
SeverityNumber.TRACE
SeverityNumber.TRACE2
SeverityNumber.TRACE3
SeverityNumber.TRACE4
SeverityNumber.DEBUG
SeverityNumber.DEBUG2
SeverityNumber.DEBUG3
SeverityNumber.DEBUG4
SeverityNumber.INFO
SeverityNumber.INFO2
SeverityNumber.INFO3
SeverityNumber.INFO4
SeverityNumber.WARN
SeverityNumber.WARN2
SeverityNumber.WARN3
SeverityNumber.WARN4
SeverityNumber.ERROR
SeverityNumber.ERROR2
SeverityNumber.ERROR3
SeverityNumber.ERROR4
SeverityNumber.FATAL
SeverityNumber.FATAL2
SeverityNumber.FATAL3
SeverityNumber.FATAL4
std_to_otel()
Module contents
The OpenTelemetry logging API describes the classes used to generate logs and events.
The LoggerProvider
provides users access to the Logger
.
This module provides abstract (i.e. unimplemented) classes required for
logging, and a concrete no-op implementation NoOpLogger
that allows applications
to use the API package alone without a supporting implementation.
To get a logger, you need to provide the package name from which you are calling the logging APIs to OpenTelemetry by calling LoggerProvider.get_logger with the calling module name and the version of your package.
The following code shows how to obtain a logger using the global LoggerProvider
:
from opentelemetry._logs import get_logger
logger = get_logger("example-logger")
New in version 1.15.0.
- class opentelemetry._logs.Logger(name, version=None, schema_url=None, attributes=None)[source]
Bases:
ABC
Handles emitting events and logs via LogRecord.
- class opentelemetry._logs.LoggerProvider[source]
Bases:
ABC
LoggerProvider is the entry point of the API. It provides access to Logger instances.
- abstract get_logger(name, version=None, schema_url=None, attributes=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 asimportlib.metadata.version(instrumenting_library_name)
.schema_url (
Optional
[str
]) – Optional. Specifies the Schema URL of the emitted telemetry.
- Return type:
- class opentelemetry._logs.LogRecord(timestamp=None, observed_timestamp=None, trace_id=None, span_id=None, trace_flags=None, severity_text=None, severity_number=None, body=None, attributes=None)[source]
Bases:
ABC
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.
- class opentelemetry._logs.NoOpLogger(name, version=None, schema_url=None, attributes=None)[source]
Bases:
Logger
The default Logger used when no Logger implementation is available.
All operations are no-op.
- class opentelemetry._logs.NoOpLoggerProvider[source]
Bases:
LoggerProvider
The default LoggerProvider used when no LoggerProvider implementation is available.
- opentelemetry._logs.get_logger(instrumenting_module_name, instrumenting_library_version='', logger_provider=None, schema_url=None, attributes=None)[source]
Returns a Logger for use within a python process.
This function is a convenience wrapper for opentelemetry.sdk._logs.LoggerProvider.get_logger.
If logger_provider param is omitted the current configured one is used.
- Return type:
- opentelemetry._logs.get_logger_provider()[source]
Gets the current global
LoggerProvider
object.- Return type:
- opentelemetry._logs.set_logger_provider(logger_provider)[source]
Sets the current global
LoggerProvider
object.This can only be done once, a warning will be logged if any further attempt is made.
- Return type:
- class opentelemetry._logs.SeverityNumber(value)[source]
Bases:
Enum
Numerical value of severity.
Smaller numerical values correspond to less severe events (such as debug events), larger numerical values correspond to more severe events (such as errors and critical events).
See the Log Data Model spec for more info and how to map the severity from source format to OTLP Model.
- UNSPECIFIED = 0
- TRACE = 1
- TRACE2 = 2
- TRACE3 = 3
- TRACE4 = 4
- DEBUG = 5
- DEBUG2 = 6
- DEBUG3 = 7
- DEBUG4 = 8
- INFO = 9
- INFO2 = 10
- INFO3 = 11
- INFO4 = 12
- WARN = 13
- WARN2 = 14
- WARN3 = 15
- WARN4 = 16
- ERROR = 17
- ERROR2 = 18
- ERROR3 = 19
- ERROR4 = 20
- FATAL = 21
- FATAL2 = 22
- FATAL3 = 23
- FATAL4 = 24
- opentelemetry._logs.std_to_otel(levelno)[source]
Map python log levelno as defined in https://docs.python.org/3/library/logging.html#logging-levels to OTel log severity number as defined here: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitynumber
- Return type: