The capability gives you visibility into how your users are interacting with your Java application by using a JavaScript snippet (or "agent") to instrument your app's webpages. To install the browser agent via the UI, follow the procedures to install the browser agent. For example, you can:
Enable an APM-monitored app.
Enable with the copy/paste method.
Enable by using the REST API.
You can also manually instrument your webpages by using the Java agent API, as explained in this document.
Use Java agent API
If your framework does not allow you to enable browser monitoring from our UI, with the copy/paste method, or by using our REST API, you can manually instrument monitoring for your webpages. To do this, use our Java agent API.
Set the auto_instrument flag under browser_monitoring to false in your newrelic.yml.
browser_monitoring:
auto_instrument:false
Restart your application.
Flush the app server's work cache.
Flushing the work cache forces the app server to recompile JSPs, which is when auto-instrumentation occurs.
Use the disabled_auto_pages flag under the browser_monitoring section. For example, to disable auto-instrumentation on testpage_1.jsp and testpage_2.jsp, use the following:
If you are using Velocity Tools, define a NewRelic tool in toolbox.xml:
<toolbox>
<tool>
<key>NewRelic</key>
<scope>application</scope>
<class>com.newrelic.api.agent.NewRelic</class>
</tool>
</toolbox>
Call the NewRelic API in your velocity template:
$NewRelic.getBrowserTimingHeader()
...
To ensure that all of your browser page views are not grouped under a single /velocity transaction (and to avoid metric grouping issues), disable your enable_auto_transaction_naming setting in your newrelic.yml file:
enable_auto_transaction_naming:false
Add newrelic-api.jar to the classpath of Tomcat, typically in .../tomcat/bin/setenv.sh:
If a <toolbox scope="application"> tag already exists, put the <tool ... /> within the tag.
In each app, edit the Velocity template that the other pages in the application use. Add this tag within the <head> section before any <link> and <script> declarations and after any meta tags:
$NewRelic.getBrowserTimingHeader()
Restart the Tomcat server:
If you are using Linux/Unix, add the following command line to the Users/Tomcat/bin directory:
./shutdown.sh
./startup.sh
If you are using Windows, go to your Users/Tomcat/bin directory, and add the following command line:
% shutdown.bat
% startup.bat
Check the log file to verify that the agent is instrumenting correctly. Set the log_level setting in newrelic.yml to log_level: finer and check for the following messages:
May 17, 2011 9:33:18 AM NewRelic FINE: Compiling JSP: /jsp/header.jsp
May 17, 2011 9:33:18 AM NewRelic FINE: Injecting browser timing header into: /jsp/header.jsp
May 17, 2011 9:33:36 AM NewRelic FINE: Compiling JSP: /jsp/footer.jsp
May 17, 2011 9:33:36 AM NewRelic FINE: Injecting browser timing footer into: /jsp/footer.jsp
The JavaScript snippet is not inserted into the HTML response until after the agent connects to the server.
May 17, 2011 9:43:21 AM NewRelic INFO: Real user monitoring is enabled with auto instrumentation
May 17, 2011 9:43:23 AM NewRelic FINER: Injecting browser timing header in a JSP. Content type is text/html
May 17, 2011 9:43:23 AM NewRelic FINER: Injecting browser timing footer in a JSP. Content type is text/html
May 17, 2011 9:43:23 AM NewRelic FINEST: Got browser timing header in NewRelic API: <script>var NREUMQ=[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);(function(){var d=document;var e=d.createElement("script");e.type="text/javascript";e.async=true;e.src="https://d7p9czrvs14ne.cloudfront.net/11/eum/rum.js";var s=d.getElementsByTagName("script")[0];s.parentNode.insertBefore(e,s);})();</script>
May 17, 2011 9:43:23 AM NewRelic FINEST: Got browser timing footer in NewRelic API: <script type="text/javascript" charset="utf-8">NREUMQ.push(["nrf2","staging-beacon-1.newrelic.com","8512b4d93f",7449,"M1RTYksFDEYDUxdcDgoeZERQSwhGEmQGRhVL",0,413])</script>