Dynatrax is an observability solution that integrates OpenTelemetry with Dynatrace for a Python Flask application. It enables you to capture, track, and analyze traces, metrics, and logs in real-time, giving you deep insights into your application’s health and performance.
- Introduction
- Features
- Setup and Installation
- Project Structure
- Usage
- OpenTelemetry Configuration
- Troubleshooting
- Contributing
- License
Dynatrax provides an easy way to instrument a Flask application using OpenTelemetry and Dynatrace. By automatically exporting traces, metrics, and logs, Dynatrax enables in-depth observability for debugging and performance monitoring.
- Tracing: Tracks and visualizes the flow of requests through your application, giving insights into request paths and latencies.
- Metrics: Monitors and records key metrics to assess application health and performance.
- Logging: Provides structured logging, sent directly to Dynatrace, to support diagnostics and troubleshooting.
Follow these steps to set up Dynatrax in your environment.
- Python 3.7+
- Dynatrace account, with access to create API tokens.
- Recommended: A virtual environment to isolate dependencies.
Dynatrax requires the following environment variables to communicate with Dynatrace:
DT_API_URL
: The base URL for Dynatrace API (e.g.,https://your-dynatrace-domain/api/v2/otlp
)DT_API_TOKEN
: Your Dynatrace API token with the necessary scopes (ingest traces, metrics, logs).
-
Clone the repository:
git clone cd Dynatrax
-
Setup virtualenv:
python3 -m venv .venv source .venv\bin\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Configure your environment variables by creating a
.env
file or exporting them directly in the terminal..env
example:DT_API_URL=https://your-dynatrace-domain/api/v2/otlp DT_API_TOKEN=your_dynatrace_api_token
-
Initialize OpenTelemetry components:
- Dynatrax uses OpenTelemetry SDKs for manual instrumentation of traces, metrics, and logs. here
- Verify your
requirements.txt
includes necessary OpenTelemetry packages:opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp-proto-http Flask
Dynatrax/
├── opentelemetry_tracer.py
├── app.py # Main application file
├── README.md # Project documentation
├── requirements.txt # Python dependencies
└── .env # Environment variables (not included in repository)
To run Dynatrax, execute the following command:
python app.py
The app should start on http://localhost:5000
. You can visit this URL to generate sample traces and metrics.
Dynatrax includes sample endpoints for testing:
/
Endpoint: The home route that triggers a simple trace./greet/<name>
Endpoint: Greets the user by name and captures a custom trace with the user’s name.
Example:
curl http://localhost:5000/greet/John
This will generate a trace in Dynatrace showing the request path, response time, and any custom attributes.
OpenTelemetry settings are configured in app.py
:
- Tracing: The
TracerProvider
andBatchSpanProcessor
are initialized, and traces are sent to Dynatrace. - Metrics: A
MeterProvider
is set up to capture basic metrics (e.g., request counts, durations). - Logging:
LoggerProvider
enables sending structured logs directly to Dynatrace.
-
No Data in Dynatrace:
- Ensure that
DT_API_URL
andDT_API_TOKEN
are correctly set and accessible. - Verify that your Dynatrace token has the necessary scopes:
metrics.ingest
,logs.ingest
,traces.ingest
.
- Ensure that
-
Connection Errors:
- Check that you’re using the correct API URL format:
https://<your_dynatrace_url>/api/v2/otlp
. - Confirm network connectivity from your application to Dynatrace.
- Check that you’re using the correct API URL format:
- It creates a service
- Send Logs to Dynatrace
Contributions are welcome! Please fork the repository and submit a pull request.
Dynatrax is open-source and available under the MIT License. See LICENSE
for details.