Technology
Python
Gain visibility into your Python applications and machine learning models. Dash0 integrates to monitor and analyze your systems effectively.
Overview
Overview
Instrumenting your Python application to generate traces, logs, and metrics is a powerful way to gain deep insights into its behavior and performance. By adding instrumentation, you enable your application to emit valuable data that can be used for monitoring, troubleshooting, and optimization.
Use Cases
- Understand outgoing and incoming HTTP requests through traces and metrics. Allowing drill-downs to the database level.
- You can see which database statements were executed and how long they took, which gives you valuable data to optimize your applications.
- Reveal (uncaught) errors and the context in which they happened.
- Understand the behavior of your generative-AI applications and Langchain usages through OpenLLMetry and OpenLit.
Setup
Install
The OpenTelemetry Python SDK provides a ready-made auto-instrumentation package that simplifies instrumentation:
1. Install the OpenTelemetry distribution package and OTLP exporter:
The opentelemetry-distro
package includes the necessary dependencies for auto-instrumentation. The OTLP exporter enables sending telemetry data to Dash0.
2. Run the bootstrap command:
This command detects installed libraries and installs the corresponding OpenTelemetry instrumentation packages.
The auto-instrumentation package applies tracing, metrics, and logging instrumentation to supported frameworks without modifying application code.
Configure
To send data to Dash0, configure the following settings:
1. Specify the application service name:
This helps identify your service in Dash0.
Replace my-first-observable-service
with a meaningful name for your application.
2. Set up the data export endpoint and authorization token:
Define where OpenTelemetry sends the telemetry data.
Note: You can specify which dataset to send data to by adding the Dash0-Dataset
header. For example:
For more information, see the dataset documentation.
3. Run your application with OpenTelemetry instrumentation:
Use the opentelemetry-instrument
command before running your application.
For frameworks like Flask:
Kubernetes Setup
In case you are not using the Dash0 operator for Kubernetes to deploy your application, you should extend the OpenTelemetry resource attributes to include the Pod UID. This is important to merge the resources between logs,traces and metrics. You can do this by adding the following environment variables to your deployment:
This will add the k8s.pod.name
and k8s.pod.uid
attributes to the OpenTelemetry resource attributes, which will be included in all telemetry data sent to Dash0.
To read more about resource equality and merging, please refer to the Dash0 docs.
In order to learn more about the importance of resource attributes read the blog post OpenTelemetry resource attributes: Best practices for Kubernetes
Supported Libraries and Frameworks
To see which libraries are automatically instrumented, refer to the OpenTelemetry registry.