{"id":9503,"library":"autodynatrace","title":"autodynatrace: Auto Instrumentation for OneAgent SDK","description":"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.","status":"active","version":"2.1.1","language":"en","source_language":"en","source_url":"https://github.com/dynatrace-oss/OneAgent-SDK-Python-AutoInstrumentation","tags":["monitoring","apm","dynatrace","instrumentation","tracing","flask","django","fastapi","asyncio"],"install":[{"cmd":"pip install autodynatrace","lang":"bash","label":"Install autodynatrace"},{"cmd":"pip install autodynatrace oneagent-sdk","lang":"bash","label":"Install with OneAgent SDK"}],"dependencies":[{"reason":"Requires the Dynatrace OneAgent SDK for Python to be installed and available in the environment for autodynatrace to function. autodynatrace instruments calls to this SDK.","package":"oneagent-sdk","optional":false}],"imports":[{"note":"This should be the very first import statement in your application's main entry point file to ensure all supported frameworks and libraries are correctly patched before they initialize.","symbol":"autodynatrace","correct":"import autodynatrace"}],"quickstart":{"code":"# app.py\nimport os\n# Must be the first import to ensure all frameworks are patched correctly\nimport autodynatrace \n\nfrom flask import Flask\n\n# For asyncio applications (from v2.1.0+), uncomment the line below:\n# os.environ['AUTODYNATRACE_INSTRUMENT_CONCURRENT'] = 'True'\n\napp = Flask(__name__)\n\n@app.route('/')\ndef hello_world():\n    return 'Hello, Dynatrace Instrumented World!'\n\nif __name__ == '__main__':\n    # To run:\n    # 1. pip install autodynatrace flask oneagent-sdk\n    # 2. python app.py\n    # 3. Access http://localhost:5000\n    # 4. Check Dynatrace monitoring for traces in your Dynatrace tenant\n    #    (Requires OneAgent and SDK configuration)\n    app.run(debug=True, port=5000)","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `oneagent-sdk` is installed via `pip install oneagent-sdk` and that your OneAgent is running and configured correctly for your Python environment.","message":"Autodynatrace relies on the Dynatrace OneAgent SDK for Python (`oneagent-sdk` PyPI package) being installed and properly configured in the environment. Without `oneagent-sdk` present, instrumentation will fail with a `ModuleNotFoundError` or silently not capture data.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Move `import autodynatrace` to the absolute first line of your main application file, before any other imports or code execution.","message":"For complete and effective auto-instrumentation, `import autodynatrace` MUST be the very first import statement in your application's main entry point file. Importing it later may result in incomplete or failed instrumentation of certain frameworks or libraries.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set the environment variable `AUTODYNATRACE_INSTRUMENT_CONCURRENT=True` before starting your application process (e.g., `export AUTODYNATRACE_INSTRUMENT_CONCURRENT=True` or `os.environ['AUTODYNATRACE_INSTRUMENT_CONCURRENT'] = 'True'` early in your script).","message":"Version 2.1.0 introduced initial support for asyncio. For asyncio applications (e.g., FastAPI, aiohttp), you *must* explicitly set the environment variable `AUTODYNATRACE_INSTRUMENT_CONCURRENT=True` for instrumentation to be active. Asyncio code will not be traced without this setting.","severity":"breaking","affected_versions":">=2.1.0"},{"fix":"Refer to the official autodynatrace GitHub README for the list of currently supported frameworks and their versions. Consider upgrading/downgrading dependencies or implementing manual instrumentation if auto-instrumentation is not feasible.","message":"Autodynatrace supports a specific set of frameworks and database drivers (e.g., Flask, Django, FastAPI, SQLAlchemy, Psycopg2). If your application uses an unsupported framework or an unsupported version, instrumentation may not work or may be incomplete.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install the SDK using pip: `pip install oneagent-sdk`.","cause":"The Dynatrace OneAgent SDK for Python (`oneagent-sdk` PyPI package), which autodynatrace depends on at runtime, is not installed in the environment.","error":"ModuleNotFoundError: No module named 'oneagent'"},{"fix":"Ensure `import autodynatrace` is the absolute first line of code in your main application file. Also, verify that the Dynatrace OneAgent is installed and configured correctly for your environment (e.g., by ensuring the `DT_ONEAGENT_PYTHON_SDK_PATH` environment variable is set or by running your application within a OneAgent-monitored process).","cause":"This typically happens if `autodynatrace` was not imported as the very first statement in your application's entry point, or if the OneAgent itself isn't properly configured/running.","error":"My Flask/Django/FastAPI application is running, but no traces or metrics are appearing in Dynatrace."},{"fix":"Set the environment variable `AUTODYNATRACE_INSTRUMENT_CONCURRENT=True` before starting your application. For example: `export AUTODYNATRACE_INSTRUMENT_CONCURRENT=True`.","cause":"For `autodynatrace` versions 2.1.0 and higher, asyncio instrumentation requires an explicit environment variable to be set.","error":"Asynchronous code (e.g., in FastAPI, aiohttp) is not being traced by Dynatrace when using autodynatrace."}]}