OpenTelemetry Instrumentation for Logging

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

Library
PyPI
v0.65b0
1,088stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
97/100Excellent
Development Activity100
Maintenance100
Community88
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture80
Code Quality85
Innovation72
Learning Curve75

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

No Code Platforms · Databases

5,635

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
68
Dependency
Built with
Python68%
JavaScript15%
Vue12%
Updated today
TypeScript
91%
Apache 2.0

Helicone

Monitoring · AI Development · Analytics

6,083

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
62
Repo Health
81
Technical
66
Dependency
Built with
TypeScript91%
Updated 3 days ago
TypeScript
71%
Other

highlight.io

Developer Tools · Analytics · Monitoring

9,367

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
69
Repo Health
78
Technical
66
Dependency
Built with
TypeScript71%
Go16%
Updated yesterday
Python
63%
Other

Keep

Devops · Automation · Monitoring

12,224

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
91
Repo Health
79
Technical
67
Dependency
Built with
Python63%
TypeScript36%
Updated today
Python
37%
Other

Open WebUI

AI Assistants · AI Agents

149,204

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

View details
91
Repo Health
75
Technical
66
Dependency
Built with
Python37%
Svelte33%
JavaScript22%
Updated today
Python
69%
Apache 2.0

SurfSense

Search · AI Assistants

15,960

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
Python69%
TypeScript28%
Updated today
Go
54%
AGPL 3.0

Uptrace

Monitoring · Devops

4,264

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

View details
65
Repo Health
70
Technical
69
Dependency
Built with
Go54%
Vue34%
Updated 6 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

Search