With the Ruby agent, you can add browser monitoring agent instrumentation to your webpages either automatically or manually. To enable browser monitoring in the UI, follow the procedures to install the browser agent. Then follow the procedures in this section to set up the Ruby agent.
Automatic browser instrumentation is supported for most recent versions of Rails:
- New Relic Ruby agent (version 3.0.1 or higher)
- For automatic instrumentation: Rails 2.3 or higher
- For manual instrumentation: Rails 2.0 to 2.2
Automatic instrumentation works with Rack, and requires Rails 2.3 or higher.
Configure the agent to automatically instrument pages with end user monitoring scripts, by adding or editing the following flag in
X-UA-Compatible meta tag is present and the
<head> tag is longer than 50k, auto-instrumentation will fail gracefully.
Auto-instrumentation will look for an
X-UA-Compatible meta tag, it will insert after the opening head tag, and failing that it will insert after the opening body tag. If any of these tags are wrapped in conditionals or comments, the automatic instrumentation will likely fail.
If auto-instrumentation fails to correctly instrument your application’s pages, then you must manually instrument via agent API.
If you are using Rails 2.1 to 2.2 or cannot use auto-instrumentation, you can still set up end user monitoring manually by including appropriate scripts in your pages. Use the New Relic Ruby agent's API to generate the script to be inserted into your pages.
For example, to modify your application's template to call the agent, use:
<head><%= ::NewRelic::Agent.browser_timing_header rescue "" %>... existing template code ...</head>
CSP Nonce usage in our browser instrumentation is supported in version 7.1.0+ of the Ruby agent. To use a nonce with the browser instrumentation, you must disable browser monitoring auto instrumentation and use the manual instrumentation via the agent API.
You may now pass a nonce as an argument into the API method to allow the agent to insert the nonce into the browser instrumentation. For example,
If you do not see any browser data being reported, view the HTML source and confirm two blocks of script similar to this in your HTML head:
If these are not present, check the auto-instrumentation settings or the placement of manual instrumentation in your template files.
In versions of the Ruby agent prior to 3.7.0,
<%=::NewRelic::Agent.browser_timing_footer rescue "" %> also needed to be called as close to the bottom of the document as possible. With 3.7.0, all the required script is included by
browser_timing_footer returns an empty string for compatibility.
The default value of
true (even when unspecified). To disable auto-instrumentation, set this flag to
To disable auto-instrumentation only for certain controllers or controller actions, use
newrelic_ignore_enduser. Server-side instrumentation will be unaffected by this call.
If you need more help, check out these support and learning resources:
- Browse the Explorers Hub to get help from the community and join in discussions.
- Find answers on our sites and learn how to use our support portal.
- Run New Relic Diagnostics, our troubleshooting tool for Linux, Windows, and macOS.
- Review New Relic's data security and licenses documentation.