[Java] JSP broken by enabling auto-instrumentation keeps breaking after disabling auto-instrumentation

Enabling auto-instrumentation by the Java agent breaks some critical JSP pages for the application with java.lang.IllegalStateException: Attempt to clear a buffer that’s already been flushed in JSP forward code.

So we decided to disable auto-instrumentation. We met an issue: it seems to be impossible to disable!

  • the application does not appear in Browser apps (deleted a long time ago)
  • auto_instrument: false in newrelic.yml
  • APM > Settings > Environment shows browser_monitoring.auto_instrument = false
  • agent log file shows “com.newrelic INFO: Real user monitoring is enabled for application MYAPP. Auto instrumentation is disabled”.

However the JSP is still broken and show source in browser shows the NewRelic Javascript snippet injected in the page even if disabled.

We have checked that application works fine if newrelic agent is completely removed and breaks again when reinstalled.

How can we make sure newrelic agent does not mess with JSP? This is a blocker issue.

Hello @saas.contact,

You mentioned that you enabled auto-injection, which for the Java agent leverages the Jasper JSP compiler to perform the actual injection of our page load timing JavaScript into your JSP page source. Jasper is the default JSP compiler for a number of different application servers, including Tomcat, Jetty, GlassFish and a few others. This is documented here:

https://docs.newrelic.com/docs/new-relic-solutions/best-practices-guides/full-stack-observability/browser-monitoring-best-practices-java/

Now, in general Jasper will only recompile a JSP if it notices a change, and because our injection happens at compilation time, it’s quite possible that the application server is holding on to an old copy of the JSP since it doesn’t see that the JSP source has been altered since the last compilation. That cached copy of the JSP may still contain our page load timing scripts.

Technically this is not a problem of our agent, you have correctly disabled further auto-injection, it’s an issue with the application server. The solution is to figure out where your application server stores cached JSPs, and clear the JSP cache. In Tomcat, this is usually the /tomcat/webapps folder, but without knowing your specific configuration I can’t point you at the precise location. That’s the most likely solution though – clear the JSP cache on your application server, force Jasper to recompile the JSPs from source while the agent’s Browser auto-instrumentation is disabled, and everything should work.

If it doesn’t, let me know.

1 Like