Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Relic Solution: Troubleshooting Java Agent Browser Auto-Injection Issues

browser
java
javaagent
autoinjection
js
jasper

#1

Intro

New Relic Browser 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. There are a few ways to enable Browser, but this guide will focus on troubleshooting the most common issue users face - Browser agent auto-injection with the Java agent. Users will often see unexpected results or pages not reporting in their application after enabling Browser in the New Relic UI because the auto-injection fails for some mysterious reason.

Troubleshooting steps:

To begin, there are some requirements that you’ll need for this to work:

  • You must be using JSPs.

    • Not using JSPs? The New Relic Java agent only supports auto-injection of the Browser agent javascript at compile time of JSPs.
  • You must be using Jasper compiler (the default compiler for Tomcat, Jetty, Glassfish, and JBoss 4).

    • Not using Jasper compiler? The New Relic Java agent Browser auto-injection is only supported with the Jasper compiler.

To troubleshoot this behavior, attempt these steps:

1. Enable finest logging

How do I do that?

To generate detailed finest log files:
Edit your newrelic.yml file, and change the log_level to finest. Be sure to keep these lines indented two spaces:

 # The agent uses its own log file to keep its logging
 # separate from that of your application. Specify the log level here.
 # This setting is dynamic, so changes do not require restarting your application.
 # The levels in increasing order of verboseness are:
 # off, severe, warning, info, fine, finer, finest
 # Default is info.
 log_level: finest

 # Log all data sent to and from New Relic in plain text.
 # This setting is dynamic, so changes do not require restarting your application.
 # Default is false.
 audit_mode: false

2. Clear the Tomcat /work folder of any previously compiled JSPs

Show me how..?

Depending on your Tomcat configuration, at some point in the life cycle of a webapp, your JSP files will get compiled into servlets. These new servlet files are stored in the %TOMCAT_HOME%/work directory. There should be a subfolder /Catalina, which contains a subfolder representing the domain name which defaults to /localhost. Inside of that should be the /project folder, which contains package hierarchy org.apache.jsp, which contains the compiled JSP files:

Tomcat
 |-- backup
 |-- bin
 |-- conf
 |-- lib
 |-- logs
 |-- temp
 |-- webapps
   -- work
      `-- Catalina
           `-- localhost
                `-- Foo_project_name
                     `-- org
                          `-- apache
                               `-- jsp
                                    |-- foo_jsp.class
                                    `-- foo_jsp.java

The above path may be different depending on your directory setup.

Can't find the `/jsp` folder?
  • Are you testing in an IDE? Some IDEs such as IntelliJ IDEA and Eclipse place these into a folder other than the default, as they take over deployment control from Tomcat.
  • What are the results of running find . | grep 'nameOfYourJsp_jsp.java'?

3. Restart the application

4. Exercise your web application for about five minutes to generate sufficient logging data making sure to hit the pages where you’d like to confirm Browser instrumentation or pages that are giving you trouble

5. Review the logs

I don't know how to do this...

By default, log files are stored in a logs sub-directory inside the same directory as newrelic.jar (as is the default location of the newrelic.yml). We are looking for the following entries for clues about whether auto-instrumentation is succeeding or not:

When the JSP engine compiles a JSP:

May 17, 2018 9:33:18 AM NewRelic FINE: Compiling JSP: /jsp/header.jsp
May 17, 2018 9:33:18 AM NewRelic FINE: Injecting browser timing header into: /jsp/header.jsp

May 17, 2018 9:33:36 AM NewRelic FINE: Compiling JSP: /jsp/footer.jsp
May 17, 2018 9:33:36 AM NewRelic FINE: Injecting browser timing footer into: /jsp/footer.jsp

After the agent connects to the server:

The JavaScript snippet is not inserted into the HTML response until after the agent connects to the server.

May 17, 2018 9:43:21 AM NewRelic INFO: Real user monitoring is enabled with auto instrumentation
I'm seeing `Real user monitoring disabled`?

Check to confirm that the auto_instrument flag under browser_monitoring isn’t set to false in your newrelic.yml:

browser_monitoring:
  auto_instrument: true

When New Relic invokes the JSP:

May 17, 2018 9:43:23 AM NewRelic FINER: Injecting browser timing header in a JSP.  Content type is text/html
May 17, 2018 9:43:23 AM NewRelic FINER: Injecting browser timing footer in a JSP.  Content type is text/html

When the agent calls the header and footer API:

May 17, 2018 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, 2018 9:43:23 AM NewRelic FINEST: Got browser timing footer in NewRelic API: <script>

Note: The finest log setting is a highly verbose logging level. To reduce disk space consumption after testing, return the log_level to its original setting.

I'm still not seeing the desired page reporting!
  • Are you able to see the New Relic Browser javascript on the page?
How do I check for this?
  • Open the Google Chrome web browser
    • Navigate to the web page you would like to examine.
    • Right-click anywhere on the page and look at the menu that appears. From that menu, click View page source.
    • The source code for that page will now appear as a new tab in the browser. Alternatively, you can also use the keyboard shortcuts of CTRL+U on a PC to open a window with a site’s source code displayed. On a Mac, this shortcut is Command+Alt+U.
    • Use the keyboard shortcut CTRL+F to find the NREUM string that is contained within the New Relic Browser javascript. This should be located very close to the <head> element at the top of the page.
  • Does the page have a text/html content type in the response headers?
What is a context type or a response header?
  • Check the network tab in developer tools to see this (don’t look at what’s put in the page!).
  • Open the Google Chrome web browser
  • Navigate to the web page you would like to examine.
  • Right-click anywhere on the page and look at the menu that appears. From that menu, click Inspect.
  • The Chrome Dev Tools will appear. From the tabs available, choose Network.
  • Refresh the page
  • The page should reload and the desired page should appear.
  • Select the desired page
  • Select Headers
  • Under Response Headers choose Content-Type and look for the following:
    Content-Type: text/html;charset=UTF-8
  • Does the page validate minimally for HTML structure?

    • The page needs to have <head> and <body> tags, opening and closing. You can use an HTML validator online such as http://validator.w3.org/ to test your page. Malformed HTML is something that Browser auto-injection doesn’t really handle well.
  • Other issues listed in the Best Practices for Browser docs:


APM Browser Help Spring Boot and Angular
Browser Lite - missing data