The New Relic Python agent provides support for the Waitress WSGI server. This includes automatically instrumenting the WSGI application entry point supplied to the Waitress server. The automatic instrumentation will work if the
waitress.serve() API function is used directly, or if
egg:waitress#main is specified as the server to use when starting up the web application using PasteDeploy.
If you have manually integrated the call to
waitress.serve() in your application script, such as in:
import waitress def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] waitress.serve(application)
and you are starting your WSGI application as a Python script directly with Python as:
all you need to instead do is run:
NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-python app.py
Instead of defining the
NEW_RELIC_CONFIG_FILE environment variable on the same line as executing the command, it can instead be separately exported and set in the process environment before running the command.
NEW_RELIC_CONFIG_FILE=newrelic.ini export NEW_RELIC_CONFIG_FILE newrelic-admin run-python app.py
newrelic.ini should be replaced with the appropriate absolute or relative path to the location of your actual Python agent configuration file.
If rather than manually integrating the call to startup the Waitress WSGI server in your application code, you are using PasteDeploy with a configuration similar to:
[server:main] use = egg:waitress#main host = 127.0.0.1 port = 8080
all you instead need to do to start up your WSGI application is wrap the running of the
NEW_RELIC_CONFIG_FILE=newrelic.ini newrelic-admin run-program paster serve production.ini
When using the
newrelic-admin wrapper script with the Waitress WSGI server, the agent will be automatically initialized when the web application starts. You do not need to make any code changes to your web application.
If you are not able to, or do not wish to use the
newrelic-admin wrapper script, you can still manually add in calls to the agent API to initialize it when your web application starts.
As per instructions for integration with your Python application, this should be done as the very first step by your web application, after any module import paths are setup, but before any imports of the Waitress WSGI server, separate application modules or any modules for frameworks being used.