Instrumentation for browser monitoring

For standard page load timing, sometimes referred to as real user monitoring (RUM), New Relic measures the overall time to load the entire webpage. Additional monitoring after page load provides details on in-page AJAX calls, JavaScript errors, and other events and interactions.

Browser monitoring can leverage the New Relic agent to dynamically inject JavaScript into pages as they are built, in order to collect more detailed back-end timing information. New Relic Browser can also monitor apps with single-page application (SPA) architectures.

Instrumentation to collect browser data

Access to some of these features depends on your subscription level.

To collect data, New Relic Browser uses JavaScript elements pasted or injected into your webpages, typically as part of the HEAD of the page, containing configuration details and essential browser environment instrumentation. Once the page finishes loading, an additional script is downloaded from a CDN server. This additional script processes the collected data and reports it back to New Relic via bam.nr-data.net so that you can see the data in your New Relic account.

The script elements can be injected automatically or via the New Relic agent API by an APM agent installed in the back-end application, or they can be inserted manually via copy/paste. Both API calls and the copy/paste method allow you to control when and where the script elements are inserted.

The New Relic JavaScript uses these methods to collect the page load timing information:

Method Collecting page load timing information
Browsers with Navigation Timing Specification API

For browsers that implement the Navigation Timing Specification API, page load timing information is read from the browser and reported to New Relic by the browser agent. The appropriate values simply are read from the webpage's performance timing object to capture the timing information.

  • Navigation start: navigationStart
  • First byte: responseStart
  • DOM ready: DOMContentLoadedEventEnd
  • Page ready: loadEventEnd
Browsers without Navigation Timing Specification API

For browsers that do not implement the Navigation Timing Specification API, New Relic relies on the NREUM cookie and the browser agent to collect timing information.

Additional instrumentation

New Relic Browser also uses:

Resource Timing API

For browsers that implement the Resource Timing API, New Relic's Browser agent reads and reports session trace details.

Single page app (SPA) monitoring

For SPA monitoring, New Relic requires the Navigation Timing Specification API and the addEventListener API.

JavaScript placement requirements

Injecting the JavaScript inline in the HEAD is an unusual requirement for a JavaScript library, and different from how third-party scripts are typically included. New Relic requires this so that New Relic Browser provides accurate information without impacting page load performance.

The injected browser JavaScript elements wrap many of the browser's built in APIs to record information about JavaScript errors or callback timings. The unusual placement of the code element is necessary for the following reasons:

  • The inline HEAD placement ensures the instrumentation code is loaded before all other scripts so that wrapping will occur when other libraries are registered.
  • Inline code placement also eliminates the network round trips caused by externally referenced scripts.

Data transmission

For both https and http webpages, New Relic transmits data via https. This summarizes when the data is transmitted to and from the webpage.

New Relic requires support of the SHA256 hash function, which some older operating systems do not support. If an end user lacks SHA256, the Browser agent will not connect to New Relic and data will not be sent.

Data transmission Frequency
Fetch the agent script Once following page load via https
Send page load timing data Once following page load via https
Send AJAX and JavaScript error data Once per minute when there is activity via https
Send session trace data Every ten seconds when there is activity and a session trace is occurring via https
Send SPA data At the end of an interaction via https

For more help

For an example of how New Relic engineers used page load timing to improve our own app performance when developing New Relic Browser, read this blog post.

Discuss Browser monitoring in the New Relic Online Technical Community! Troubleshoot and ask questions, or discuss JavaScript error reporting or AJAX timing in detail.

If you need additional help, get support at support.newrelic.com.