Python
1. Install
Section titled “1. Install”Run this in your app’s environment, after your app’s own packages are installed. The second line adds instrumentation for the libraries it finds, such as Flask, Django, FastAPI, requests and psycopg.
pip install opentelemetry-distro opentelemetry-exporter-otlpopentelemetry-bootstrap -a install2. Configure
Section titled “2. Configure”Set these where your app runs. Replace YOUR_INGEST_KEY with your key and checkout with your service name.
export OTEL_SERVICE_NAME=checkoutexport OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=productionexport OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.siteqwality.comexport OTEL_EXPORTER_OTLP_HEADERS=Authorization=YOUR_INGEST_KEYexport OTEL_EXPORTER_OTLP_PROTOCOL=http/protobufexport OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true3. Start your app
Section titled “3. Start your app”Put opentelemetry-instrument in front of the command that starts your app, for example:
opentelemetry-instrument flask --app app run --host 0.0.0.0 --port 8080Requests to your app and the calls it makes are now traced automatically.
4. Send a log
Section titled “4. Send a log”logger = logging.getLogger("checkout")logger.setLevel(logging.INFO)
logger.info("order placed", extra={"order_id": 42})Records from the standard logging module arrive as logs, linked to the trace of the request that wrote them. Records below the logger’s level are not sent, so set it to the lowest level you want to keep.
5. Record a metric (optional)
Section titled “5. Record a metric (optional)”orders = metrics.get_meter("checkout").create_counter("orders.placed")
orders.add(1)See your data
Section titled “See your data”Open Logs, Traces or Metrics. New data usually shows up within a minute, and a page that says it is waiting for data switches to your data on its own.
The code on this page comes from a runnable example that is checked against our ingest rules every month.
Nothing arriving? Check that the key is an ingest key for this account, that your account has early access, and the status codes in Ingest routes and limits.