{"id":8836,"library":"appdynamics","title":"AppDynamics Python Agent","description":"The AppDynamics Python Agent is an Application Performance Monitoring (APM) tool that instruments Python applications to collect performance metrics, trace transactions, and identify bottlenecks. It provides deep visibility into web applications, background tasks, and database interactions. The current version is 26.4.0.8689, with frequent releases often aligning with major AppDynamics platform updates.","status":"active","version":"26.4.0.8689","language":"en","source_language":"en","source_url":"https://www.appdynamics.com/products/application-performance-management","tags":["APM","observability","monitoring","performance"],"install":[{"cmd":"pip install appdynamics","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Contains platform-specific binary dependencies for the agent.","package":"appdynamics-bindeps-*","optional":false},{"reason":"Provides the Java-based proxy component for agent communication.","package":"appdynamics-proxysupport-*","optional":false}],"imports":[{"note":"The primary way to start a Python application with the AppDynamics agent is by wrapping the application's entry point with the `pyagent` command. Direct import is typically for API calls within the application.","symbol":"pyagent","correct":"pyagent run -c appdynamics.cfg -- python my_app.py"},{"note":"While 'from ... import init' works, the recommended pattern often involves importing the 'appdynamics.agent' module as a whole for accessing other functionalities like decorators.","wrong":"from appdynamics.agent import init; init()","symbol":"appdynamics.agent.init","correct":"import appdynamics.agent\nappdynamics.agent.init()"},{"note":"Used as a decorator to define custom business transactions.","symbol":"appdynamics.agent.bt","correct":"@appdynamics.agent.bt()"}],"quickstart":{"code":"import os\nfrom flask import Flask\nimport appdynamics.agent\n\n# Initialize AppDynamics Agent (if not started via pyagent run)\n# Ensure APPDYNAMICS_CONTROLLER_HOST_NAME and other env vars are set\n# or use an appdynamics.cfg file.\n# For a quickstart, assume pyagent run wrapper is used or environment variables.\nappdynamics.agent.init(\n    controller_host=os.environ.get('APPDYNAMICS_CONTROLLER_HOST_NAME', 'your-controller.saas.appdynamics.com'),\n    controller_port=int(os.environ.get('APPDYNAMICS_CONTROLLER_PORT', 443)),\n    controller_ssl_enabled=bool(os.environ.get('APPDYNAMICS_CONTROLLER_SSL_ENABLED', 'True').lower() == 'true'),\n    account_name=os.environ.get('APPDYNAMICS_AGENT_ACCOUNT_NAME', 'customer1'),\n    account_access_key=os.environ.get('APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY', 'YOUR_ACCESS_KEY'),\n    application_name=os.environ.get('APPDYNAMICS_AGENT_APPLICATION_NAME', 'MyPythonApp'),\n    tier_name=os.environ.get('APPDYNAMICS_AGENT_TIER_NAME', 'MyPythonTier'),\n    node_name=os.environ.get('APPDYNAMICS_AGENT_NODE_NAME', 'my-python-node-1')\n)\n\napp = Flask(__name__)\n\n@app.route('/')\n@appdynamics.agent.bt(name='HelloWorld')\ndef hello_world():\n    return 'Hello, AppDynamics World!'\n\n@app.route('/error')\n@appdynamics.agent.bt(name='ErrorRoute')\ndef error_route():\n    raise Exception('This is a simulated error!')\n\nif __name__ == '__main__':\n    # In a real scenario, you'd typically run this with 'pyagent run'\n    # For direct execution, ensure agent.init() is configured correctly.\n    port = int(os.environ.get('PORT', 5000))\n    app.run(debug=True, host='0.0.0.0', port=port)\n","lang":"python","description":"This quickstart demonstrates how to instrument a basic Flask application with the AppDynamics Python Agent. The agent can be initialized programmatically using `appdynamics.agent.init()` or via an `appdynamics.cfg` file and environment variables. The recommended way to run the application with the agent is by prefixing your application's startup command with `pyagent run`. Environment variables are used for agent configuration to avoid hardcoding sensitive information."},"warnings":[{"fix":"Upgrade your Python environment to version 3.9 or higher. Python 3.14 is supported starting from agent version 26.4.0.","message":"AppDynamics Python Agent version 26.4.0 deprecates support for Python 3.8 and has removed support for Python 3.7 and older versions.","severity":"breaking","affected_versions":">=26.4.0"},{"fix":"Verify that `APPDYNAMICS_CONTROLLER_HOST_NAME`, `APPDYNAMICS_CONTROLLER_PORT`, `APPDYNAMICS_AGENT_ACCOUNT_NAME`, and `APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY` environment variables are correctly set, or ensure your `appdynamics.cfg` file contains accurate values. Check agent logs for '401 Unauthorized' errors.","message":"Agent startup can fail or data may not be reported to the Controller due to incorrect configuration of Controller Host, Port, Account Name, or Access Key.","severity":"gotcha","affected_versions":"*"},{"fix":"Refer to AppDynamics documentation for configuring agent logging levels, often involving modifications to `log4j2.xml` within the agent's bindeps directory. This is sometimes an unsupported workaround.","message":"Verbose logging from the AppDynamics agent and its proxy can flood stdout, obscuring application-specific logs.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure that all platform-specific dependencies are correctly installed and that the Java proxy can access necessary native libraries. Consult AppDynamics support or documentation for specific troubleshooting steps for your environment, especially on non-standard architectures like Apple M1.","message":"Issues with the Java-based proxy agent failing to find native libraries (e.g., `jzmq`) can lead to agent startup failures, particularly on specific operating systems or architectures.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify that the AppDynamics Python Agent (including `appdynamics-bindeps` and `appdynamics-proxysupport` packages) is correctly installed for your specific operating system and architecture. Check AppDynamics documentation for setting `java.library.path` if running the proxy separately, or ensure `pip install appdynamics` pulls the correct wheel.","cause":"The Java-based proxy component of the AppDynamics Python Agent cannot find its required native ZMQ library, often due to an incorrect library path or missing architecture-specific binaries.","error":"java.lang.UnsatisfiedLinkError: no jzmq in java.library.path"},{"fix":"Ensure a clean re-installation: `pip uninstall appdynamics appdynamics-bindeps-* appdynamics-proxysupport-* && pip install appdynamics`. Verify Python version compatibility with the installed agent.","cause":"This error often indicates an issue with the installation or loading of the `appdynamics_bindeps` package, specifically related to its Cython-compiled ZMQ backend, potentially due to a circular import or corrupted installation.","error":"ImportError: cannot import name 'constants' from partially initialized module 'appdynamics_bindeps.zmq.backend.cython'"},{"fix":"Double-check the `APPDYNAMICS_AGENT_ACCOUNT_NAME` and `APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY` environment variables or the corresponding settings in `appdynamics.cfg`. Ensure the client secret generated in the Controller UI was saved correctly.","cause":"The AppDynamics Python Agent is unable to authenticate with the Controller, typically because of an incorrect Account Name or Account Access Key.","error":"HTTP Error 401 Unauthorized"}]}