{"id":324,"library":"opentelemetry-sdk","title":"OpenTelemetry Python SDK","description":"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.","status":"active","version":"1.40.0","language":"python","source_language":"en","source_url":"https://github.com/open-telemetry/opentelemetry-python","tags":["observability","tracing","metrics","OpenTelemetry","Python"],"install":[{"cmd":"pip install opentelemetry-sdk","lang":"bash","label":"Install OpenTelemetry SDK"}],"dependencies":[{"reason":"Provides the core API definitions for OpenTelemetry.","package":"opentelemetry-api"}],"imports":[{"note":"Ensure correct import path to access TracerProvider.","symbol":"TracerProvider","correct":"from opentelemetry.sdk.trace import TracerProvider"},{"note":"Ensure correct import path to access ConsoleSpanExporter.","symbol":"ConsoleSpanExporter","correct":"from opentelemetry.sdk.trace.export import ConsoleSpanExporter"}],"quickstart":{"code":"import os\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter\n\n# Set up the tracer provider\ntrace.set_tracer_provider(TracerProvider())\n\n# Set up the exporter\nconsole_exporter = ConsoleSpanExporter()\nspan_processor = BatchSpanProcessor(console_exporter)\ntrace.get_tracer_provider().add_span_processor(span_processor)\n\n# Get a tracer\ntracer = trace.get_tracer(__name__)\n\n# Create a span\nwith tracer.start_as_current_span(\"example-span\"):\n    print(\"Hello, OpenTelemetry!\")\n","lang":"python","description":"A simple example demonstrating how to set up tracing with the OpenTelemetry Python SDK."},"warnings":[{"fix":"Install 'opentelemetry-instrumentation-logging' and update your code to use the new handler.","message":"In version 1.40.0, the 'LoggingHandler' has been deprecated in favor of 'opentelemetry-instrumentation-logging'.","severity":"breaking","affected_versions":"1.40.0"},{"fix":"Ensure your code handles the new behavior appropriately.","message":"The 'start_span' and 'start_as_current_span' methods in 'NoOpTracer' no longer return 'INVALID_SPAN' when a valid span context is present.","severity":"breaking","affected_versions":"1.40.0"}],"env_vars":null,"last_verified":"2026-05-12T13:04:13.293Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"ModuleNotFoundError: No module named 'opentelemetry.instrumentation'"},{"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.","cause":"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.","error":"Exporter Failed: connection refused"},{"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.","cause":"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.","error":"OpenTelemetry traces/spans/metrics not appearing (silent failure)"},{"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`.","cause":"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.","error":"WARNING: Invalid type NoneType for attribute value."}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.3,"mem_mb":13,"disk_size":"22.1M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.2,"mem_mb":13,"disk_size":"23M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.49,"mem_mb":13.7,"disk_size":"24.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.37,"mem_mb":13.7,"disk_size":"25M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.67,"mem_mb":13.9,"disk_size":"16.1M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.59,"mem_mb":13.9,"disk_size":"17M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.35,"mem_mb":14,"disk_size":"15.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.34,"mem_mb":14,"disk_size":"16M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.29,"mem_mb":12.7,"disk_size":"21.6M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.26,"mem_mb":12.7,"disk_size":"22M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}