To use page load timing (sometimes referred to as real user monitoring or RUM) with New Relic's Python agent, make sure you have the latest release.
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 page load timing in Python.
Use automatic instrumentation
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:
If you are using a WSGI server that allows per-request configuration, such as Apache/mod_wsgi, you can also disable automatic instrumentation by setting the
newrelic.disable_browser_autorum key for that request in the WSGI environ dictionary passed into your monitored application.
For example, if using Apache/mod_wsgi, you could disable automatic instrumentation by filtering on the URL:
<Location /login> SetEnv newrelic.disable_browser_autorum true </Location>
Manually instrument via agent API
You can manually add instrumentation to specific pages. This is useful, for example, if automatic instrumentation is not possible for your application, or if you want to collect page load timing data for only some pages.
To enable manual instrumentation, place the calls in this procedure on every request you want to monitor. You cannot call these functions once at global scope and cache the result for later use.
- Disable automatic instrumentation: In the newrelic.ini file, set
- Restart your application.
Place these calls into the request handler of every page you want to monitor:
import newrelic.agent header = newrelic.agent.get_browser_timing_header() footer = newrelic.agent.get_browser_timing_footer()
- Pass the
footervariables to the HTML response.
- On the corresponding page, insert the
headervariable in the
<head>element. Place the
headervariable after any
charsetproperties or any meta tags for
http-equivwith a value of
- Insert the
footervariable before the end of the
For more help
Additional documentation resources include:
- Instrumentation for page load timing and Page load timing process (overview of New Relic Browser's page load timing feature)
- Optional manual page load timing with Django (steps on doing this same manual instrumentation process with a Django application)
- Troubleshooting page view monitoring (procedures for troubleshooting your setup for page load timing, sometimes referred to as real user monitoring or RUM)