pyagent run
If you can control the way your WSGI server is invoked, you can instrument the
application using pyagent run
. This command runs your WSGI server
with the Python agent enabled. This option is generally possible if you use a
process launcher/manager that takes a command to execute. For example, frameworks
managed by Supervisor, uWSGI without Emperor, init.d scripts, and so on.
To use the pyagent run
command, prepend to your existing application
run command the pyagent run
command, passing the AppDynamics
configuration file described in Configure
the Agent as a parameter.
Do not overwrite PYTHONPATH
for any reason. Doing so will prevent
the pyagent run
command from loading the agent. If you need to add
to PYTHONPATH
, use the pythonpath configuration variable. For
example, these commands add /foo
and /bar
to the
PYTHONPATH
instead of overwriting it:
PYTHONPATH
:pythonpath = /foo
pythonpath = /bar
PYTHONPATH
using the following syntax. This
is the wrong way to add to
PYTHONPATH
:env = PYTHONPATH=/foo:/bar
Using supervisorctl
If you use supervisorctl
,
after updating your Supervisor configuration you must use the supervisorctl
reload
command to have the Python agent loaded. Supervisor does not
re-read its configuration files when you use the supervisorctl
restart
command.
To verify that the agent was loaded, look for
the Python agent log file. Its default location is
/tmp/appd/logs/<app_name>-<node_name>.log
. For
example, if your application name is myapp and your node name is mynode as specified
in the agent configuration file, and you have not changed the location of the log
file, the log file will be /tmp/appd/logs/myapp-mynode
.
If
the log file exists, the agent was loaded. If the log file does not exist, the agent
was not loaded, in which case you should try reloading the Supervisor configuration
with supervisorctl reload
.
Django and Flask
- If your framework is Django or Flask, simply prepend
pyagent run
to your run command. For example, if your current run command looks like this:gunicorn -w 8 -b '0.0.0.0:9000' example.app:application
- If you are running your ASGI codebase under the uvicorn server, simply prepend
pyagent run
to your run command. For example, if your current run command looks like this:uvicorn --port 9090 --reload --log-level trace mysite.asgi:application
- gnuicorn
pyagent run -c <path_to_appdynamics_config_file> -- gunicorn -w 8 -b '0.0.0.0:9000' example.app:application
- uvicorn
pyagent run -c <path_to_appdynamics_config_file> -- uvicorn --port 9090 --reload --log-level trace mysite.asgi:application
Other Pure Python WSGI-Based Frameworks
- In the AppDynamics configuration file, specify your WSGI application by setting the APPD_WSGI_MODULE directive to point to your app module. See Python Agent Settings.
- Prepend
pyagent run
to your run command. - Run the AppDynamics-generated application.
gunicorn -w 8 -b '0.0.0.0:9000' example.app:application
pyagent run -c /path/to/appdynamics.cfg -- gunicorn -w 8 -b '0.0.0.0:9000'
appdynamics.scripts.wsgi:application