OpenTelemetry Instrumentation for Logging

Automatic OpenTelemetry trace context injection into Python's standard logging module

Library
PyPI
v0.66b1
1,119 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
95 /100 Excellent
Development Activity 100
Maintenance 100
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
78 /100 Good
Architecture 80
Code Quality 85
Innovation 72
Learning Curve 75

opentelemetry-instrumentation-logging automatically instruments Python’s standard logging module so log records carry OpenTelemetry trace context. Once installed, it patches the active log record factory to attach otelSpanID, otelTraceID, otelTraceSampled, and otelServiceName attributes to every log record emitted while a span is active.

This lets log lines be correlated with distributed traces in an observability backend without hand-wiring trace IDs into log statements. It supports both an opt-in inject_trace_context mode that adds the attributes silently, and a set_logging_format mode that also reconfigures the root logging format to print those attributes inline.

What You Get

  • A LoggingInstrumentor that patches the stdlib logging record factory
  • Opt-in injection of otelSpanID, otelTraceID, otelTraceSampled, and otelServiceName onto log records
  • Automatic logging.basicConfig() reconfiguration via set_logging_format=True
  • An auto-installed logging handler that forwards records to the OpenTelemetry SDK’s logger provider
  • Environment-variable configuration (OTEL_PYTHON_LOG_CORRELATION, OTEL_PYTHON_LOG_LEVEL, etc.) alongside code-based options

Common Use Cases

  • Correlating application log lines with distributed traces in an observability backend
  • Adding trace/span IDs to logs without changing every log call site
  • Feeding structured application logs into an OpenTelemetry Collector pipeline
  • Standardizing log correlation across microservices that share OTel instrumentation

Under The Hood

Architecture — the instrumentor subclasses BaseInstrumentor from opentelemetry-instrumentation and, on _instrument(), wraps the stdlib’s logging.getLogRecordFactory() with a closure that stamps trace/span identifiers from get_current_span() onto each new LogRecord before restoring the original factory on _uninstrument(); a separate _setup_logging_handler() (in handler.py) optionally attaches a handler that forwards records to the configured LoggerProvider. Tech Stack — pure Python, depending only on opentelemetry-api, opentelemetry-instrumentation, and opentelemetry-semantic-conventions from the same monorepo, with no external runtime dependencies; built with hatchling and versioned in lockstep with the rest of the contrib release train. Code Quality — covered by three test files (test_handler.py, test_logging.py, test_logging_handler_recursion.py) totaling over 1,400 lines, including a dedicated regression test for handler recursion, plus a benchmarks/ directory measuring the logging handler’s overhead. API Design — a single LoggingInstrumentor().instrument(...) call with clearly named boolean flags (inject_trace_context, set_logging_format) keeps adoption to one line for the common case, while environment variables mirror every code-level option for container/config-driven deployments.

Used by 7 apps in this directory

Python
68%
Other

Baserow

Databases · No Code Platforms

6,205

Open-source no-code platform to build databases, apps, automations, and AI agents — self-hosted or cloud, with full data ownership.

View details
89
Repo Health
84
Technical
65
Dependency
Built with
Python 68%
JavaScript 17%
Vue 10%
Updated yesterday
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,235

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
74
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated today
TypeScript
71%
Other

highlight.io

Analytics · Developer Tools · Monitoring

9,384

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

View details
76
Repo Health
78
Technical
65
Dependency
Built with
TypeScript 71%
Go 16%
Updated yesterday
Python
64%
Other

Keep

Automation · Devops · Monitoring

12,433

The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.

View details
88
Repo Health
79
Technical
66
Dependency
Built with
Python 64%
TypeScript 36%
Updated 2 days ago
Python
38%
Other

Open WebUI

AI Agents · AI Assistants

156,607

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
92
Repo Health
75
Technical
66
Dependency
Built with
Python 38%
Svelte 35%
JavaScript 19%
Updated today
Python
71%
Apache 2.0

SurfSense

AI Assistants · Search

16,586

The open-source, unlimited NotebookLM alternative with real-time collaboration, a desktop app, and no vendor lock-in.

View details
88
Repo Health
71
Technical
66
Dependency
Built with
Python 71%
TypeScript 27%
Updated today
Go
54%
AGPL 3.0

Uptrace

Devops · Monitoring

4,305

Unified open-source APM that collects OpenTelemetry traces, metrics, and logs into a single self-hosted platform backed by ClickHouse.

View details
71
Repo Health
70
Technical
65
Dependency
Built with
Go 54%
Vue 34%
Updated 2 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers