Integrations
Python
Add observability to your Python applications with OpenTelemetry.
Overview
Python applications can be instrumented with OpenTelemetry to capture traces, logs, and metrics. The Python SDK supports both automatic and manual instrumentation, giving you flexibility in how you add observability to your application.
Use Cases
- Monitor Django, Flask, and FastAPI web applications
- Trace database queries with SQLAlchemy, psycopg2, and other database libraries
- Track async operations with asyncio instrumentation
- Capture HTTP client requests with requests and urllib3
Install
Install the OpenTelemetry Python SDK with auto-instrumentation:
pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a installThe opentelemetry-bootstrap command detects your installed libraries and installs the appropriate instrumentation packages.
Configure
1. Set the service name
export OTEL_SERVICE_NAME="my-python-service"2. Configure the OTLP endpoint
export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingress.us-east-2.rocketgraph.app"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_ROCKETLOGS_API_TOKEN"Replace YOUR_ROCKETLOGS_API_TOKEN with your API token from Settings.
3. Run your application with auto-instrumentation
opentelemetry-instrument python your_app.pyOr for a web framework like Flask:
opentelemetry-instrument flask runFramework Examples
Django
opentelemetry-instrument python manage.py runserverFastAPI with uvicorn
opentelemetry-instrument uvicorn main:app --host 0.0.0.0 --port 8000Celery workers
opentelemetry-instrument celery -A tasks worker --loglevel=infoSupported libraries
The following libraries are automatically instrumented:
- Django, Flask, FastAPI, Starlette
- SQLAlchemy, psycopg2, mysql-connector, pymongo
- requests, urllib3, aiohttp, httpx
- redis, celery, asyncio
- And many more via OpenTelemetry Registry