Universal OpenTelemetry bootstrap for Python services with elite-quality defaults, privacy, auto-instrumentation, traces, and metrics.
Project description
OpenTelemetry Instrumentation Python (v1)
Python-first OpenTelemetry bootstrap for backend services, focused on:
- deterministic startup and shutdown
- explicit feature toggles for tracing, metrics and instrumentations
- strict privacy defaults for database statements and user identifiers
- zero-code startup through the official distro/configurator mechanism
- log correlation only, with no log export pipeline inside this package
Installation
pip install "elven-opentelemetry-instrumentation-py[full]"
Runtime support
v1 supports runtime="python" only.
Passing runtime="serverless" or runtime="edge" raises an explicit error.
Zero-code
export OTEL_SERVICE_NAME="my-service"
export OTEL_SERVICE_VERSION="1.0.0"
elven-otel-instrument python app.py
Disable wrapper initialization explicitly:
export OTEL_ZERO_CODE=false
Manual initialization
from opentelemetry.sdk.trace.sampling import Decision
from elven_opentelemetry_instrumentation import (
MetricsConfig,
ObservabilityConfig,
PrivacyConfig,
SamplingRule,
ServiceConfig,
TracingConfig,
init_observability,
)
handle = init_observability(
ObservabilityConfig(
service=ServiceConfig(
service_name="payment-service",
service_version="1.0.0",
deployment_environment="production",
),
tracing=TracingConfig(
enabled=True,
rules=[
SamplingRule(
attribute_key="http.route",
attribute_value="/healthz",
decision=Decision.DROP,
),
],
),
metrics=MetricsConfig(enabled=True, export_interval_millis=60_000),
privacy=PrivacyConfig(
redact_db_statement=True,
hash_user_id=True,
),
)
)
handle.tracer.with_span("startup", lambda span: span.set_attribute("boot.ready", True))
handle.metrics.increment("jobs.started", 1)
handle.force_flush()
handle.shutdown()
Public API
init_observability(config) returns an ObservabilityHandle with:
tracermetricsshutdown()force_flush()is_started()
The initializer is idempotent and protects against duplicate startup.
Feature precedence
For booleans, precedence is:
- explicit config
- environment variable
- package default
Examples:
OTEL_TRACES_EXPORTER=nonedisables traces by defaultTracingConfig(enabled=True)overrides that defaultOTEL_INSTR_PSYCOPG=falsedisables psycopg instrumentation unless explicitly enabled in config
Supported coverage
- Web: ASGI, WSGI, FastAPI, Flask, Django
- GraphQL: request-level enrichment plus operation and field spans through
graphql-core - HTTP clients: requests, httpx, urllib3, aiohttp-client
- Data: SQLAlchemy, psycopg, psycopg2, pymysql, mysqlclient, Redis, MongoDB
- Workers and queues: Celery, threading, asyncio, gRPC, Kafka, RabbitMQ/Pika, SQS via boto3
- Logging: stdlib logging correlation
Instrumentation is activated only when the target library is installed and enabled.
Development
python -m venv .venv
. .venv/bin/activate
pip install -e ".[dev]"
ruff check .
pyright
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file elven_opentelemetry_instrumentation_py-0.1.0.tar.gz.
File metadata
- Download URL: elven_opentelemetry_instrumentation_py-0.1.0.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b707e3f9461ca89991e57ee5ff1f006f679e77a1afeb84296043167407665e1c
|
|
| MD5 |
d2765db6bf8757787ed75cb30161915f
|
|
| BLAKE2b-256 |
685b16939f588b103146d4220adfde85fcc238bad972c860e97223f91f80da30
|
File details
Details for the file elven_opentelemetry_instrumentation_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: elven_opentelemetry_instrumentation_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4689fe39f945c2ca8798a90523e6ef6535bfaa456e4777bbd18579e98217d0ef
|
|
| MD5 |
9a0f8da1f9ac0ca2426ef52d4fef5a01
|
|
| BLAKE2b-256 |
24652d9190905271246ec889442fcb07fde0d7a5881081e11ff2d1cbf3bcbc2f
|