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.
pip install opentelemetry-sdkVerified import paths — ran on the pinned version, not inferred.
A simple example demonstrating how to set up tracing with the OpenTelemetry Python SDK.
Install 'opentelemetry-instrumentation-logging' and update your code to use the new handler.
Ensure your code handles the new behavior appropriately.
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.
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.
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.
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`.