AppDynamics Python Agent
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.
Common errors
-
java.lang.UnsatisfiedLinkError: no jzmq in java.library.path
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.fixVerify 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. -
ImportError: cannot import name 'constants' from partially initialized module 'appdynamics_bindeps.zmq.backend.cython'
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.fixEnsure a clean re-installation: `pip uninstall appdynamics appdynamics-bindeps-* appdynamics-proxysupport-* && pip install appdynamics`. Verify Python version compatibility with the installed agent. -
HTTP Error 401 Unauthorized
cause The AppDynamics Python Agent is unable to authenticate with the Controller, typically because of an incorrect Account Name or Account Access Key.fixDouble-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.
Warnings
- breaking AppDynamics Python Agent version 26.4.0 deprecates support for Python 3.8 and has removed support for Python 3.7 and older versions.
- gotcha 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.
- gotcha Verbose logging from the AppDynamics agent and its proxy can flood stdout, obscuring application-specific logs.
- gotcha 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.
Install
-
pip install appdynamics
Imports
- pyagent
pyagent run -c appdynamics.cfg -- python my_app.py
- appdynamics.agent.init
from appdynamics.agent import init; init()
import appdynamics.agent appdynamics.agent.init()
- appdynamics.agent.bt
@appdynamics.agent.bt()
Quickstart
import os
from flask import Flask
import appdynamics.agent
# Initialize AppDynamics Agent (if not started via pyagent run)
# Ensure APPDYNAMICS_CONTROLLER_HOST_NAME and other env vars are set
# or use an appdynamics.cfg file.
# For a quickstart, assume pyagent run wrapper is used or environment variables.
appdynamics.agent.init(
controller_host=os.environ.get('APPDYNAMICS_CONTROLLER_HOST_NAME', 'your-controller.saas.appdynamics.com'),
controller_port=int(os.environ.get('APPDYNAMICS_CONTROLLER_PORT', 443)),
controller_ssl_enabled=bool(os.environ.get('APPDYNAMICS_CONTROLLER_SSL_ENABLED', 'True').lower() == 'true'),
account_name=os.environ.get('APPDYNAMICS_AGENT_ACCOUNT_NAME', 'customer1'),
account_access_key=os.environ.get('APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY', 'YOUR_ACCESS_KEY'),
application_name=os.environ.get('APPDYNAMICS_AGENT_APPLICATION_NAME', 'MyPythonApp'),
tier_name=os.environ.get('APPDYNAMICS_AGENT_TIER_NAME', 'MyPythonTier'),
node_name=os.environ.get('APPDYNAMICS_AGENT_NODE_NAME', 'my-python-node-1')
)
app = Flask(__name__)
@app.route('/')
@appdynamics.agent.bt(name='HelloWorld')
def hello_world():
return 'Hello, AppDynamics World!'
@app.route('/error')
@appdynamics.agent.bt(name='ErrorRoute')
def error_route():
raise Exception('This is a simulated error!')
if __name__ == '__main__':
# In a real scenario, you'd typically run this with 'pyagent run'
# For direct execution, ensure agent.init() is configured correctly.
port = int(os.environ.get('PORT', 5000))
app.run(debug=True, host='0.0.0.0', port=port)