Elastic Distribution of OpenTelemetry Python

raw JSON →
1.12.0 verified Fri May 01 auth: no python

The Elastic Distribution of OpenTelemetry Python (EDOT Python) provides a pre-configured OpenTelemetry Python SDK and auto-instrumentation packages that are compatible with the Elastic Observability solution. It simplifies the process of instrumenting Python applications and sending telemetry data to Elastic. Currently at v1.12.0, active development with frequent minor releases.

pip install elastic-opentelemetry
error No module named 'elastic_opentelemetry'
cause The library is not installed or the import path is wrong.
fix
Run pip install elastic-opentelemetry and use from elastic_opentelemetry import ... (note the underscore in the import).
error AttributeError: module 'elastic_opentelemetry' has no attribute 'ElasticOpenTelemetry'
cause Using an older import path or misspelling the class name.
fix
Use from elastic_opentelemetry import ElasticOpenTelemetry and instantiate as ElasticOpenTelemetry().setup().
breaking Starting from v1.5.0, the default sampler changed from `always_on` to `parentbased_traceidratio`. This may result in sampling decisions that drop some traces by default. To restore previous behavior, set `OTEL_TRACES_SAMPLER=always_on` explicitly.
fix Set environment variable OTEL_TRACES_SAMPLER=always_on if you need to trace all requests.
gotcha The package `elastic-opentelemetry` is the distribution package; do not confuse it with `opentelemetry-distro` or `opentelemetry-sdk`. Installing `elastic-opentelemetry` automatically pulls in the correct OpenTelemetry SDK and instrumentation packages.
fix Install only `elastic-opentelemetry` for Elastic-optimized configuration.
gotcha Environment variables like `ELASTIC_OTEL_API_KEY` must be set before calling `ElasticOpenTelemetry().setup()`. Changing them afterward has no effect unless you reinitialize.
fix Set all environment variables before any telemetry setup code runs.

Initialize the Elastic OpenTelemetry distribution with environment variables for service name, endpoint, and API key.

import os
os.environ['ELASTIC_OTEL_SERVICE_NAME'] = 'my-app'
os.environ['ELASTIC_OTEL_ENDPOINT'] = 'https://my-elastic-cluster:443'
os.environ['ELASTIC_OTEL_API_KEY'] = 'YOUR_API_KEY'

from elastic_opentelemetry import ElasticOpenTelemetry

# Initialize the Elastic OpenTelemetry configuration
ElasticOpenTelemetry().setup()