Automatically instrument your Python application with OpenTelemetry
This walkthrough shows how to add observability to your Python application using automatic instrumentation for OpenTelemetry Python.
Get the Dynatrace access details
Determine the API base URL
For details on how to assemble the base OTLP endpoint URL, see Export with OTLP. The URL should end in
Get API access token
The access token for ingesting traces, logs, and metrics can be generated under Access Tokens.
Export with OTLP has more details on the format and the necessary access scopes.
Instrument your application
The following example uses
opentelemetry-distro to configure all available and applicable instrumentation libraries automatically. Instead, you could also skip steps 1 and 2 and selectively add instrumentation libraries by installing
opentelemetry-instrumentation and the applicable instrumentation libraries manually.
Use pip to install the following packages.1pip install opentelemetry-distro2pip install opentelemetry-exporter-otlp
Run the following command to initialize and bootstrap the automatic instrumentation.1opentelemetry-bootstrap -a install
Run your application with the
opentelemetry-instrumentagent.1opentelemetry-instrument python myapp.py
Add telemetry signals manually optional
As automatic instrumentation on Python does not provide pre-configured tracer and meter providers, you'd need to follow the initialization and instrumentation steps at Manually instrument your Python application with OpenTelemetry, if you wish to manually add custom signals (such as traces and metrics) on top of automatic instrumentation.
Ensure context propagation
Context propagation is particularly important when network calls (for example, REST) are involved.
With automatic instrumentation, this should be automatically taken care of by the instrumentation libraries. If the used network libraries are not be covered by that, you would need to switch to manual instrumentation instead and handle propagation manually.
Configure data capture to meet privacy requirements optional
While Dynatrace automatically captures all OpenTelemetry attributes, only attribute values specified in the allowlist are stored and displayed in the Dynatrace web UI. This prevents accidental storage of personal data, so you can meet your privacy requirements and control the amount of monitoring data stored.
To view your custom attributes, you need to allow them in the Dynatrace web UI first. To learn how to configure attribute storage and masking, see Attribute redaction.
Verify data ingestion into Dynatrace
Once you have finished the instrumentation of your application, perform a couple of test actions to create and send demo traces, metrics, and logs and verify that they were correctly ingested into Dynatrace.
To do that for traces, go to Distributed Traces and select the Ingested traces tab. If you use OneAgent, select PurePaths instead.
For metrics and logs, go to Metrics or Logs & Events (latest Dynatrace) or Logs (previous Dynatrace).
- Enrich ingested data with Dynatrace-specific dimensions
Learn how to automatically enrich your telemetry data with Dynatrace-specific dimensions.