AppDynamics Python Agent

26.4.0.8689 · active · verified Thu Apr 16

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

Warnings

Install

Imports

Quickstart

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.

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)

view raw JSON →