wp-newrelic
wp-newrelic copied to clipboard
Posts that are served through caching plugins like batcache bypass `disable_nr_autorum()` logic
I've noticed on a production site that posts which are retrieved through batcache seem to be getting New Relic's <script>
tags embedded, in cases where it should be disabled.
An example is AMP pages. On the initial page render, the action pre_amp_render_post
action is fired, which causes disable_nr_autorum()
to fire, preventing the New Relic browser scripts from being injected on the page.
However, if that same page request is served through batcache, the appropriate action isn't fired, and New Relic scripts are inserted (in some cases, re-inserted) into the HTML markup retrieved from memcache.
This may not be an issue that can be easily fixed in this plugin, but I wanted to open an issue here to track progress on it. It may be possible to output a special vary_cache_on
function if batcache is detected. If not, and this is something that needs to be fixed with a special nginx directive or a function in the wp-config file, it would be good to at least have it documented here. Perhaps we can show example code that users can copy into their webserver configuration in an admin notice or help page?
I have been able to implement a work around for this by wielding the great and terrible power of nginx aginst it. Use a regex to detect the /amp/ routes being requested and inject a fastcgi_param PHP value to disable auto instrumentation
set $param "";
if ( $request_uri ~* /amp/ ) {
set $param "newrelic.browser_monitoring.auto_instrument=0";
}
location ~ \.php$ {
fastcgi_param PHP_VALUE $param;
....rest of php config.....
it's worth noting, that if you are injecting any other PHP_VALUE parameters, they will overwrite each other and you will need to put them all into a single PHP_VALUE parameter