Python

Embed
Preview of the card
<a href="https://forumulate.com/p/watchtower/docs/instrumentation-python"><img src="https://forumulate.com/api/public/orgs/watchtower/spaces/docs/pages/0fd226ce-1494-4f5f-81c1-5bf30c6744d3/social-card.svg?v=3e7ae33eec8b" alt="Python" width="600" height="315"></a>

<!-- status: ga language: python -->

Python: zero-code instrumentation

opentelemetry-instrument wraps the interpreter and patches the libraries it finds (Django, Flask, FastAPI, requests, psycopg, ...) without a code change. Nothing Watchtower-specific is installed: it reads the standard OTEL_* variables.

  1. Create a project, then an ingestion key (wti_...) with the ingest:traces scope. The key is shown once.

  2. Point the instrumentation at the gateway and pass the key in the x-watchtower-key header:

export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.example.com
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_HEADERS=x-watchtower-key=wti_YOUR_KEY
export OTEL_SERVICE_NAME=my-service
  1. Install the distro and let it find the instrumentations for the libraries you use, then start the service through the wrapper:

pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install
opentelemetry-instrument python app.py
  1. Send one request to the service, then open the project's onboarding screen: it turns green when the first span arrives.

Updated