autodynatrace: Auto Instrumentation for OneAgent SDK

2.1.1 · active · verified Fri Apr 17

autodynatrace is a Python library that provides automatic instrumentation for applications using the Dynatrace OneAgent SDK. It enables monitoring and tracing for various popular frameworks and libraries like Flask, Django, FastAPI, SQLAlchemy, and aiohttp, typically requiring only a single import at the start of an application. The current version is 2.1.1, with releases occurring as new framework versions or features are supported, often focusing on stability and broader compatibility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a minimal Flask application instrumented with autodynatrace. Ensure the `oneagent-sdk` is also installed. The `import autodynatrace` statement must be the first line of your main application file to ensure proper patching. For asyncio applications, an environment variable is required.

# app.py
import os
# Must be the first import to ensure all frameworks are patched correctly
import autodynatrace 

from flask import Flask

# For asyncio applications (from v2.1.0+), uncomment the line below:
# os.environ['AUTODYNATRACE_INSTRUMENT_CONCURRENT'] = 'True'

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, Dynatrace Instrumented World!'

if __name__ == '__main__':
    # To run:
    # 1. pip install autodynatrace flask oneagent-sdk
    # 2. python app.py
    # 3. Access http://localhost:5000
    # 4. Check Dynatrace monitoring for traces in your Dynatrace tenant
    #    (Requires OneAgent and SDK configuration)
    app.run(debug=True, port=5000)

view raw JSON →