Getting Started with OpenTelemetry Python
Snippets that will guide you through instrumenting Python applications with OpenTelemetry Python API and SDK. You'll learn how to implement both manual and automatic instrumentation to emit traces, metrics, and logs to console/OTLP backends.
OpenTelemetry Python in a nutshell
- opentelemetry-python main repository which implements and delivers the core packages:
- opentelemetry-api - Core API for creating telemetry data
- opentelemetry-sdk - Default SDK implementation
- opentelemetry-semantic-conventions - Standard attribute keys and values
- opentelemetry-proto - OTLP proto implementation for Python
- opentelemetry-exporter-otlp - OTLP protocol exporters
- opentelemetry-python-contrib contrib repository which implements and delivers auto-instrumentation, instrumentation packages and custom implementations of exporters, resource detectors and etc:
- opentelemetry-instrumentation - Auto-instrumentation utilities
- opentelemetry-distro - Default distro which configures opentelemetry
Prerequisites
Before starting with this tutorial, ensure you have the following tools installed on your system:
-
uv - Fast Python package installer and resolver (recommended alternative to pip)
- Install via curl:
curl -LsSf https://astral.sh/uv/install.sh | sh
- Or via pip:
pip install uv
- Install via curl:
-
Docker - For running OpenTelemetry Collector and observability backends
- Download from docker.com
List of snippets
Following is a list of all available OpenTelemetry Python snippets:
basics
fastapi
flask
requests
Congratulations! You now have a solid foundation for instrumenting Python applications with OpenTelemetry. Start with the simple examples and gradually add more sophisticated instrumentation as your observability needs grow.