Python

The Dash0 distribution of the OpenTelemetry Python SDK, as a DEB and RPM package.

The Dash0 distribution of the OpenTelemetry Python SDK, packaged so the OpenTelemetry injector can load it into Python processes on a host.

Compatibility

RequirementSupported
PythonCPython 3.10 or later, any minor version
Architecturesamd64 and arm64
Distribution requirementsOverview

Setup with the injector

This is the recommended setup: the injector instruments every Python process on the host when it starts, without changes to how you start your applications. There are two ways to install it.

With dash0-opentelemetry, install the metapackage. It brings the injector, the keyring and, as recommended packages, the language packages for all runtimes, Python included.

On Debian or Ubuntu:

sudo apt-get install dash0-opentelemetry

On Fedora, RHEL or Amazon Linux 2023:

sudo dnf install dash0-opentelemetry

With only the packages you need, install this package and the injector by name.

On Debian or Ubuntu:

sudo apt-get install dash0-injector dash0-python-autoinstrumentation

On Fedora, RHEL or Amazon Linux 2023:

sudo dnf install dash0-injector dash0-python-autoinstrumentation

In both cases, the package's drop-in at /etc/opentelemetry/injector/conf.d/python.conf tells the injector where the tree is. The injector then puts /usr/lib/opentelemetry/python/glibc on PYTHONPATH for every Python process that starts, where the sitecustomize.py starts the SDK, and applies default_env.conf to it. Python processes that are already running are instrumented only after they restart.

Then set the endpoint and the auth token in default_env.conf, as described under Configuration.

Setup without the injector

Install only this package.

On Debian or Ubuntu:

sudo apt-get install dash0-python-autoinstrumentation

On Fedora, RHEL or Amazon Linux 2023:

sudo dnf install dash0-python-autoinstrumentation

On its own, the package instruments nothing. It only suggests the injector, and apt and dnf do not install suggested packages. Load the instrumentation yourself when you start the process:

PYTHONPATH=/usr/lib/opentelemetry/python/glibc python3 app.py

Without the injector, default_env.conf is not applied: set the endpoint and the auth token in the environment of the process instead, as described under Configuration.

Configuration

All setups need the same settings, as environment variables:

VariableSets
OTEL_EXPORTER_OTLP_ENDPOINTThe Dash0 OTLP endpoint to send telemetry to
OTEL_EXPORTER_OTLP_HEADERSThe auth token and the dataset
OTEL_SERVICE_NAMEOptional: the service name, which otherwise is derived from the application; see How the service name is chosen

With the injector, set them in /etc/opentelemetry/injector/default_env.conf, which the injector applies to every process it instruments:

OTEL_EXPORTER_OTLP_ENDPOINT=https://ingress.eu-west-1.aws.dash0.com
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20auth_...,Dash0-Dataset=default

Without the injector, set them in the environment of the process, for example in the [Service] section of its systemd unit:

Environment=OTEL_EXPORTER_OTLP_ENDPOINT=https://ingress.eu-west-1.aws.dash0.com
Environment=OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20auth_...,Dash0-Dataset=default

In both setups, the declarative configuration file this package ships reads these variables, so they are the only settings most hosts need.

Note that white spaces in OTEL_EXPORTER_OTLP_HEADERS, like in Bearer <token>, must be written %20. Set the endpoint without a trailing slash, since the signal paths such as /v1/traces are appended to it.

A variable in default_env.conf replaces the value a process sets itself, so set OTEL_SERVICE_NAME and other per-application settings in the environment of the application, not in default_env.conf.

DASH0_OTEL_COLLECTOR_BASE_URL is the endpoint when OTEL_EXPORTER_OTLP_ENDPOINT is unset or empty, as in the other Dash0 distributions. One of the two has to be set, with or without a configuration file, or the distribution disables itself; see Conditional instrumentation.

DASH0_DISABLE=true leaves processes uninstrumented without uninstalling the package.

With the injector, the DASH0_ variables reach the process only through dash0-injector, because upstream's opentelemetry-injector forwards only OTEL_-prefixed names.

Declarative configuration

Like the upstream Python package, this package ships /etc/opentelemetry/python/otel-config.yaml, an OpenTelemetry declarative configuration file. Unlike the upstream package, the distribution reads it whenever OTEL_CONFIG_FILE is unset or empty, so it configures every instrumented Python process by default. Configuration on the overview describes how to use a file of your own, the propagators every shipped file declares, and what happens to an edited file on upgrade, on removal and when replacing the upstream package.

The file uses OpenTelemetry declarative configuration , the standard YAML configuration format of the OpenTelemetry project, whose schema is defined in open-telemetry/opentelemetry-configuration . ${VARIABLE:-default} takes the value of an environment variable, with a default for when it is unset. This excerpt of the shipped file shows the propagators, the resource detectors and the export of traces; metrics and logs are exported in the same way:

file_format: "1.0"
propagator:
  composite:
    - tracecontext: {}
    - baggage: {}
    - xray: {}
resource:
  detection/development:
    detectors:
      - dash0_distribution: {}
      - dash0_service_name: {}
      - dash0_kubernetes: {}
  attributes_list: ${OTEL_RESOURCE_ATTRIBUTES:-}
tracer_provider:
  sampler:
    always_on: {}
  processors:
    - batch:
        exporter:
          otlp_http:
            endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}/v1/traces
            headers_list: ${OTEL_EXPORTER_OTLP_HEADERS:-}
            compression: ${OTEL_EXPORTER_OTLP_COMPRESSION:-none}

Setting OTEL_CONFIG_FILE prints one warning at startup, which is expected: OTEL_CONFIG_FILE is set; ignoring configurator kwargs: ['auto_instrumentation_version']. The shipped file, read because OTEL_CONFIG_FILE is unset, prints no warning.

Supported environment variables

With a configuration file in effect, the file decides every setting it names. The shipped file interpolates these, so default_env.conf stays the one place to set them:

VariableDefault in the file
OTEL_EXPORTER_OTLP_ENDPOINThttp://localhost:4318
OTEL_EXPORTER_OTLP_HEADERSempty
OTEL_EXPORTER_OTLP_COMPRESSIONnone
OTEL_RESOURCE_ATTRIBUTESempty
OTEL_METRIC_EXPORT_INTERVAL60000 ms
OTEL_METRIC_EXPORT_TIMEOUT30000 ms
OTEL_BLRP_SCHEDULE_DELAY1000 ms
OTEL_BLRP_EXPORT_TIMEOUT30000 ms
OTEL_BLRP_MAX_QUEUE_SIZE2048
OTEL_BLRP_MAX_EXPORT_BATCH_SIZE512

A configuration file of your own has to carry the same interpolations to keep them: a file that omits the metric export interval, for example, exports metrics every 60 seconds whatever OTEL_METRIC_EXPORT_INTERVAL says.

OTEL_EXPORTER_OTLP_TIMEOUT and the four OTEL_BSP_* variables keep applying without being in the file, because the SDK reads them itself.

OTEL_SERVICE_NAME and DASH0_AUTOMATIC_SERVICE_NAME keep working through the dash0_service_name detector the file lists. DASH0_OTEL_COLLECTOR_BASE_URL keeps working too: the distribution copies it into OTEL_EXPORTER_OTLP_ENDPOINT before the file is read. DASH0_DISABLE, DASH0_BOOTSTRAP_SPAN and DASH0_FLUSH_ON_SIGTERM_SIGINT apply in either mode.

Unsupported environment variables

  • OTEL_EXPORTER_OTLP_PROTOCOL. The file exports over OTLP/HTTP only, and appends /v1/traces, /v1/metrics and /v1/logs to the endpoint. Without a configuration file, the distribution sends HTTP to port 4318 when the collector base URL names the OTLP/gRPC port 4317; with the file, it sends HTTP to port 4317, where a gRPC receiver rejects it, and the processes report nothing. Point the endpoint at the collector's OTLP/HTTP port, 4318 by default, or use a copy of the file with otlp_grpc exporters, whose endpoint takes no /v1/ path.
  • The per-signal endpoint variables, such as OTEL_EXPORTER_OTLP_TRACES_ENDPOINT. Edit an exporter's endpoint to move one signal.
  • OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG. The file pins the sampler to always_on; edit tracer_provider.sampler instead.
  • OTEL_PROPAGATORS. Edit the file's propagator list instead. Keep the list in any file meant to work with the upstream Python package too: without it, the upstream SDK breaks every instrumented HTTP request.

Resource detectors

The shipped file lists only the distribution's dash0_distribution, dash0_service_name and dash0_kubernetes detectors, so that the resource is the same as without a configuration file. Add host or process to the list to report host.* or process.* attributes. dash0_service_name already includes service, which the file therefore does not list. Resource detection describes what each detector adds.

Resource attributes

Every instrumented process reports the package it came from:

AttributeValue
dash0.package.namedash0-python-autoinstrumentation
dash0.package.versionThe installed package version, packaging revision included

The dash0.package.* attributes are added to OTEL_RESOURCE_ATTRIBUTES before the SDK starts, and are withdrawn again if the distribution stands down, so a process the package did not instrument is not labelled as though it had been.

A configuration file of your own keeps them only if it reads OTEL_RESOURCE_ATTRIBUTES through attributes_list, as the shipped file does.

The distribution adds the other resource attributes, such as service.name and telemetry.distro.*. Resource detection in the distribution docs describes them, and how the service name is chosen, with and without a configuration file.

Conditional instrumentation

The application keeps running in every case below, without telemetry. The distribution writes a JSON line to stderr saying cannot auto-instrument Python process, with the reason, and removes itself from PYTHONPATH, so the processes the application starts are not instrumented either.

  • Python older than 3.10.
  • The application already carries OpenTelemetry: an opentelemetry-* or dash0-* Python distribution installed outside this package, other than opentelemetry-api and opentelemetry-semantic-conventions, would mean double instrumentation.
  • A dependency conflict: a version the application requires conflicts with one this package ships. /usr/lib/opentelemetry/python/glibc/all-dependencies.txt lists every bundled version, including general-purpose packages such as wrapt, psutil, packaging, typing_extensions and asgiref, and a conflict on any of them stands the whole distribution down. An application pinning an older psutil than this package ships therefore goes uninstrumented. Set OTEL_INJECTOR_LOG_LEVEL=debug to see which requirement decided it.
  • A configuration file that is not valid.

In these cases the distribution disables the SDK instead, by setting OTEL_SDK_DISABLED=true, which the processes the application starts inherit, and logs the reason through Python logging:

  • No endpoint: neither OTEL_EXPORTER_OTLP_ENDPOINT nor DASH0_OTEL_COLLECTOR_BASE_URL is set, with or without a configuration file.
  • DASH0_DISABLE=true.

With OTEL_SDK_DISABLED=true set by you, the SDK exports nothing, but the instrumentations are still loaded.

The interpreter ignores PYTHONPATH when started with -E or -I, so such processes are never instrumented, and nothing is logged.

With the injector, the injector itself logs why it skipped a process on stderr with OTEL_INJECTOR_LOG_LEVEL=info. See the Injector page.

Installed files

PathPurpose
/usr/lib/opentelemetry/python/glibc/The distribution and its dependencies, which the injector puts on PYTHONPATH
/usr/lib/opentelemetry/python/glibc/sitecustomize.pyStarts the distribution when Python starts
/usr/lib/opentelemetry/python/glibc/all-dependencies.txtEvery bundled Python package, with its version
/etc/opentelemetry/injector/conf.d/python.confTells the injector where the tree is
/etc/opentelemetry/python/otel-config.yamlThe declarative configuration file, read whenever OTEL_CONFIG_FILE is unset or empty; a conffile, so an edited copy is kept on upgrade
/usr/share/man/man8/opentelemetry-python.8.gzThe manual page, for man opentelemetry-python
/usr/share/doc/dash0-python-autoinstrumentation/README.mdThe installed copy of this page
/usr/share/doc/dash0-python-autoinstrumentation/copyrightThe license statement and the notice, DEB only
/usr/share/licenses/dash0-python-autoinstrumentation/LICENSEThe license, RPM only
/usr/share/licenses/dash0-python-autoinstrumentation/NOTICEThe notice, RPM only

Local overrides belong in a conf.d file that sorts after the package-managed one. The injector reads conf.d in byte order and the last setting wins, so a digit prefix such as 99- sorts before python.conf; use a name such as zz-local-python.conf. Edits to python.conf itself are replaced on upgrade.

Dependencies

PackageRelationWhy
dash0-keyringDependsEvery Dash0 package depends on it, so the signing certificate is owned by a package that upgrades it
dash0-injectorSuggestsInstruments processes with this package; apt and dnf do not install suggested packages, so install the injector by name, as described under Setup with the injector
opentelemetry-python-autoinstrumentationConflicts, and Replaces on DEB or Obsoletes on RPMTakes the place of the upstream package; see Reverting to the upstream package

Versioning

The package version is the version of the bundled dash0-opentelemetry distribution, followed by a packaging revision: 0.4.1-1 is the first package built from distribution 0.4.1, 0.4.1-2 a later package built from the same distribution. On RPM distributions the revision is the Release field, so rpm -q shows 0.4.1-1 as version 0.4.1, release 1.

Reverting to the upstream package

On Debian and Ubuntu:

sudo apt-get install opentelemetry-python-autoinstrumentation

On RPM distributions, this package declares Obsoletes on the upstream name, so a plain dnf install of it redirects back here. Ask for the swap explicitly:

sudo dnf swap --setopt=obsoletes=0 dash0-python-autoinstrumentation opentelemetry-python-autoinstrumentation

The switch also changes:

  • The configuration file: upstream reads none by default, only one that OTEL_CONFIG_FILE names. Its SDK does not know the dash0_* detectors: remove them from a file before pointing OTEL_CONFIG_FILE at it, or the SDK raises ConfigurationError at startup and the processes report nothing.
  • The endpoint: upstream does not read DASH0_OTEL_COLLECTOR_BASE_URL, and does not disable itself without an endpoint, so processes without OTEL_EXPORTER_OTLP_ENDPOINT export to the SDK's default endpoint.
  • The protocol: upstream exports over OTLP/gRPC by default.
  • The resource: telemetry.distro.*, dash0.package.*, k8s.pod.uid and the derived service name are gone.
  • X-Ray propagation and the always_on sampler: without a configuration file, upstream uses X-Ray only when OTEL_PROPAGATORS names it, and the SDK's default sampler.
  • The DASH0_ variables: upstream reads none of them.

Source

https://github.com/dash0hq/opentelemetry-python-distribution 

The distribution is published on PyPI as dash0-opentelemetry .

Last updated: