Skip to content

Python

View Markdown

FastAPI, Flask and Django telemetry through OpenTelemetry.

The Python package sends HTTP traces, exceptions and observed outbound services using the same ingestion format as the JavaScript SDK. Its package name is everock-sdk. It is prepared locally but not yet published to PyPI; install the built wheel with the extras your application uses.

Configure once

telemetry.py
import os
from everock import configure

telemetry = configure(
    public_key=os.environ['EVEROCK_PUBLIC_KEY'],
    endpoint=os.environ['EVEROCK_ENDPOINT'],
    component='api',
    environment='production',
    release=os.environ.get('EVEROCK_RELEASE'),
)

Initialize separately in each worker after forking. If your application already owns an OpenTelemetry SDK TracerProvider, pass it as provider; Everock adds its processor without replacing the provider. Do not install the same framework instrumentor twice.

Frameworks

FastAPI
from everock import instrument_fastapi
instrument_fastapi(app, telemetry)
Flask
from everock import instrument_flask
instrument_flask(app, telemetry)
Django
from everock import instrument_django
# Before get_wsgi_application() or get_asgi_application().
instrument_django(telemetry)

Install the corresponding fastapi, flask or django extra. The integration tests exercise real FastAPI and Flask applications, and Django's WSGI lifecycle.

Outbound services

HTTP clients
from everock import instrument_httpx, instrument_requests
instrument_httpx(telemetry)
instrument_requests(telemetry)

Install the httpx and requests extras only for clients you use. Observations describe real requests; they do not poll dependencies in the background. Arbitrary headers, request bodies and SQL statements are not exported by default.

Delivery and limits

A background OpenTelemetry processor uses a bounded queue of 2,048 spans. HTTP export batches stay within 48 KiB, with at most three attempts per batch. Permanent rejection is not retried, and redirects never forward the project key.

Call telemetry.flush() and telemetry.shutdown() during graceful application shutdown. Processor flush completion is not a delivery receipt: inspect telemetry.exporter.diagnostics() for delivered, discarded, filtered and serialization counters. Queue overflow accounting is owned by OpenTelemetry, not included in those exporter counters. By default, prolonged outages can lose telemetry after retries are exhausted.

Recover batches after a restart

Pass journal_directory to configure to keep sanitized batches in a private local directory on a persistent volume. On POSIX, the directory must be accessible only to its owner. Defaults: 8 MiB of batch payloads and 24 hours of retention per journal. Change them with journal_max_bytes and journal_ttl_seconds.

The exporter reopens the journal at startup and retries even before a new request arrives. It keeps the original event IDs for deduplication and removes batches after acknowledgement or permanent rejection. The project key is not stored. Spans still in the OpenTelemetry memory queue when the process crashes cannot be recovered. Monitor capacity_drops, expired and journal_errors for storage problems.

Python does not provide browser replay, browser sessions or Web Vitals. Add browser instrumentation to a frontend when those measurements are needed. Native mobile SDKs remain separate work.