New Relic Browser and the Python agent

With the Python agent, you can add New Relic Browser instrumentation to your webpages either automatically or manually. To enable Browser in the user interface, follow the procedures to install the Browser agent. Then follow the procedures in this section to set up the Python agent.

Support for automatic instrumentation

New Relic's Python agent only supports automatic instrumentation for WSGI applications that are hosted directly on a dedicated WSGI server with a native WSGI interface, and where the WSGI application returns the HTML page response via an iterable/generator.

Automatic instrumentation requires a dedicated WSGI server.

WSGI servers such as Apache/mod_wsgi, gunicorn and uWSGI are supported.

Using WSGI adapters on top of either the Tornado or Twisted frameworks is not supported.

The Python agent does not support insertion of instrumentation when using the write() callback returned from the WSGI start_response() function to write back the HTML page response. For more information about requirements for automatic instrumentation, see Troubleshooting Browser instrumentation in Python.

Use automatic instrumentation

The Python agent can automatically add the New Relic Browser JavaScript agent to any HTML page responses. For WSGI applications, the agent uses a WSGI middleware installed into the request pipeline. Since the middleware is at WSGI level, automatic instrumentation should work for any WSGI application regardless of the web framework you are using, including popular Python web frameworks such as Django, Flask and Pyramid.

Disable instrumentation for specific pages

If you want to use automatic instrumentation, but have an HTML page response that you do not want instrumented, you can disable instrumentation for that request. Add this Python agent API call into the code for that request handler:

Manually enable Browser monitoring for specific pages

You can manually add Browser instrumentation to specific pages. This is useful, for example, if automatic instrumentation is not possible for your application, or if you want to collect Browser data for only some pages.

The calls in this procedure must be placed on every request you want to monitor. You cannot call these functions once at global scope and cache the result for later use.