Skip to main content

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:

  • tracer
  • metrics
  • shutdown()
  • force_flush()
  • is_started()

The initializer is idempotent and protects against duplicate startup.

Feature precedence

For booleans, precedence is:

  1. explicit config
  2. environment variable
  3. package default

Examples:

  • OTEL_TRACES_EXPORTER=none disables traces by default
  • TracingConfig(enabled=True) overrides that default
  • OTEL_INSTR_PSYCOPG=false disables 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elven_opentelemetry_instrumentation_py-0.1.0.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file elven_opentelemetry_instrumentation_py-0.1.0.tar.gz.

File metadata

File hashes

Hashes for elven_opentelemetry_instrumentation_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b707e3f9461ca89991e57ee5ff1f006f679e77a1afeb84296043167407665e1c
MD5 d2765db6bf8757787ed75cb30161915f
BLAKE2b-256 685b16939f588b103146d4220adfde85fcc238bad972c860e97223f91f80da30

See more details on using hashes here.

File details

Details for the file elven_opentelemetry_instrumentation_py-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for elven_opentelemetry_instrumentation_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4689fe39f945c2ca8798a90523e6ef6535bfaa456e4777bbd18579e98217d0ef
MD5 9a0f8da1f9ac0ca2426ef52d4fef5a01
BLAKE2b-256 24652d9190905271246ec889442fcb07fde0d7a5881081e11ff2d1cbf3bcbc2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page