Registry / observability / opentelemetry-sdk

opentelemetry-sdk

JSON →
library1.40.0pypypi✓ verified 49d ago

The OpenTelemetry Python SDK provides APIs and implementations for collecting, processing, and exporting telemetry data such as traces and metrics. Current version: 1.40.0, released on March 4, 2026. The SDK follows a regular release cadence, with minor versions introducing new features and patch versions addressing bug fixes and improvements.

observability
pip install opentelemetry-sdk
Install & Compatibility
Where this runs
tested against v1.42.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.353s · 22.4MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.9s · import 0.314s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TracerProvider
from opentelemetry.sdk.trace import TracerProvider
Ensure correct import path to access TracerProvider.
ConsoleSpanExporter
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
Ensure correct import path to access ConsoleSpanExporter.

A simple example demonstrating how to set up tracing with the OpenTelemetry Python SDK.

import os from opentelemetry import trace from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter # Set up the tracer provider trace.set_tracer_provider(TracerProvider()) # Set up the exporter console_exporter = ConsoleSpanExporter() span_processor = BatchSpanProcessor(console_exporter) trace.get_tracer_provider().add_span_processor(span_processor) # Get a tracer tracer = trace.get_tracer(__name__) # Create a span with tracer.start_as_current_span("example-span"): print("Hello, OpenTelemetry!")
Debug
Known issues
breakingIn version 1.40.0, the 'LoggingHandler' has been deprecated in favor of 'opentelemetry-instrumentation-logging'.
fix
Install 'opentelemetry-instrumentation-logging' and update your code to use the new handler.
affects: 1.40.0
breakingThe 'start_span' and 'start_as_current_span' methods in 'NoOpTracer' no longer return 'INVALID_SPAN' when a valid span context is present.
fix
Ensure your code handles the new behavior appropriately.
affects: 1.40.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'opentelemetry.instrumentation'
This error occurs when an instrumentation package or a required OpenTelemetry package is not installed, or there's a mismatch in Python environments where packages are installed versus where the application runs, or due to namespace package conflicts.
fix
Ensure all necessary OpenTelemetry packages, especially specific instrumentations and exporters (e.g., `opentelemetry-instrumentation-flask`, `opentelemetry-exporter-otlp-proto-grpc`), are installed in the correct Python environment, often using `pip install opentelemetry-distro opentelemetry-sdk` followed by `opentelemetry-bootstrap -a install` for auto-instrumentation.
Exporter Failed: connection refused
This typically indicates that the OpenTelemetry Collector or your observability backend is not running, is inaccessible, or is listening on a different port than configured in your application's exporter settings. It can also be a network issue, an incorrect endpoint URL, or an authentication failure.
fix
Verify that the OpenTelemetry Collector or backend is running and accessible from your application's host and port (e.g., `localhost:4317` for gRPC or `localhost:4318` for HTTP). Check network connectivity, firewall rules, and ensure the exporter endpoint URL in your application configuration is correct.
OpenTelemetry traces/spans/metrics not appearing (silent failure)
This often happens when the OpenTelemetry SDK components (like the TracerProvider or MeterProvider) are initialized too late in the application lifecycle, especially in multi-process environments like Gunicorn or when using auto-instrumentation, causing early telemetry data to be dropped by 'no-op' providers or context to be lost across threads or forks.
fix
Ensure the OpenTelemetry SDK is initialized and the global providers are registered as early as possible in your application's startup, ideally before any other modules that might generate telemetry are imported or before worker processes are forked (e.g., using Gunicorn's `post_worker_init` hook). Use `force_flush()` for short-lived processes.
WARNING: Invalid type NoneType for attribute value.
OpenTelemetry attributes generally do not support `None` as a value type. This warning appears when a `None` value is passed as an attribute to a span, log, or metric, leading to the attribute being dropped or ignored.
fix
Ensure that all attribute values passed to OpenTelemetry spans, logs, or metrics are of valid types (strings, numbers, booleans, or arrays of these types). Implement checks to prevent `None` values from being passed, perhaps by providing a default value or omitting the attribute if its value is `None`.
Upgrade
Version history
1.42.1latest on PyPI
Audit
Dependencies
opentelemetry-apirequiredProvides the core API definitions for OpenTelemetry.
Agent activity
8 hits · last 30 days
seranking-bot
3
ahrefsbot
2
bytedance
1
googlebot
1
Resources