Skip to main content

OpenStack oslo.log instrumentation for OpenTelemetry

Project description

OpenTelemetry oslo.log Instrumentation

OpenStack oslo.log instrumentation for OpenTelemetry.

oslo.log builds on top of the standard library logging module. This instrumentor exports OpenStack service logs through the OpenTelemetry logs pipeline (and onward to an OTLP collector) while keeping them correlated with traces. On instrument() it:

  • injects the OpenTelemetry attributes otelTraceID, otelSpanID, otelTraceSampled and otelServiceName onto every log record, so they are available to oslo.log's ContextFormatter format strings;
  • installs an OsloLogHandler on oslo.log's root logger so records are exported through the configured logger_provider (disable with enable_log_auto_instrumentation=False);
  • maps oslo request context (request id, user/project ids, ...) onto exported record attributes (disable with map_oslo_context=False).

The exported log body is the raw log message; structured fields travel as attributes.

Correlation across threads/greenthreads: the trace a record is correlated to comes from the current OpenTelemetry context, which lives in a contextvars.Context that Python does not copy into worker threads or greenthreads. A record logged off the request thread would otherwise export trace_id/span_id as 0 — the common cause of "my oslo.log records have no trace id" in OpenStack. Enable opentelemetry-instrumentation-oslo-service, which carries the context across oslo.service's concurrency primitives (threading.Thread, futurist pools, and eventlet spawns).

oslo_log.log.setup rebuilds the root logger's handlers from oslo.config, dropping every existing handler. The instrumentor wraps setup so the exporting handler is re-attached afterwards, and keeps working even when setup runs (or runs again) after instrument().

Note: the handler is attached to oslo.log's root logger, not the stdlib root logger. Records from non-oslo libraries that log straight to the stdlib root are handled by opentelemetry-instrumentation-logging, not this package.

Usage

from opentelemetry.instrumentation.oslo_log import OsloLogInstrumentor

OsloLogInstrumentor().instrument(logger_provider=logger_provider)

To surface the injected trace context in oslo.log output, reference the fields from logging_context_format_string / logging_default_format_string in your oslo.config:

[DEFAULT]
logging_default_format_string = %(asctime)s %(levelname)s %(name)s [trace_id=%(otelTraceID)s span_id=%(otelSpanID)s] %(message)s
logging_context_format_string = %(asctime)s %(levelname)s %(name)s [%(request_id)s trace_id=%(otelTraceID)s span_id=%(otelSpanID)s] %(message)s

Exported context attributes

When map_oslo_context is enabled (the default), the following oslo request context fields are mapped onto exported log record attributes:

oslo context value exported attribute
request_id openstack.request_id
global_request_id openstack.global_request_id
user openstack.user_id
user_name openstack.user_name
project openstack.project_id
project_name openstack.project_name
domain openstack.domain_id
user_domain openstack.user_domain_id
project_domain openstack.project_domain_id
roles openstack.roles
resource_uuid openstack.resource_uuid

Authentication tokens are never exported.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file opentelemetry_instrumentation_oslo_log-0.11.0.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_oslo_log-0.11.0.tar.gz
Algorithm Hash digest
SHA256 59614063455e1722741c2691d4f09b5df9c81f0863d8b8c3ae28fb267ac04020
MD5 6653475d493ea93f8eba58fabd99652b
BLAKE2b-256 ae36773cc5ed251a82ec85020d0cdce209bbdc25c9c6f43fae8e62c6278947de

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentelemetry_instrumentation_oslo_log-0.11.0.tar.gz:

Publisher: publish-pypi.yml on daipham3213/opentelemetry-openstack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opentelemetry_instrumentation_oslo_log-0.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_oslo_log-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a8170ff5776b80198cfe0cf4f924aacaaece0a6c0baeeb8d7677f7125dbc160
MD5 c5f03d0f4abff672be0b583994666c93
BLAKE2b-256 bb116b8858f6b7c9193bbbdb34e93dd05c1da4cd31dde551ac740ef555b7ca73

See more details on using hashes here.

Provenance

The following attestation bundles were made for opentelemetry_instrumentation_oslo_log-0.11.0-py3-none-any.whl:

Publisher: publish-pypi.yml on daipham3213/opentelemetry-openstack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page