I work for New Relic.
The reason that New Relic's middlewares are not showing up when running rake middleware
is that they are conditionally inserted into the middleware stack. These middlewares are inserted only if the agent is configured to run in the current environment. You can force New Relic's middlewares to be inserted when running rake middleware
in order to inspect the middleware stack by setting NEW_RELIC_AGENT_ENABLED=true
on the command line when starting the rake task.
Adding the following code to config/application.rb
should ensure that the Rack::ETag middleware has a chance to calculate and inject the ETag before the browser monitoring middleware injects its dynamic content:
config.after_initialize do
config.middleware.delete "Rack::ETag"
config.middleware.insert_after "NewRelic::Rack::BrowserMonitoring", "Rack::ETag"
end
The reason the JavaScript code injected into responses by the NewRelic::Rack::BrowserMonitoring
middleware is dynamic is that it contains timings of how long the response took to generate on the server-side, and (if applicable) how long it was queued before reaching the Rails stack. These timings will vary with each incoming request. If ETags are generated based on hashing the page content before the dynamic information is inserted, then out-of-date server-side timings will potentially be used when a response is serviced from the cache. You can read details about how this is handled by New Relic here: https://newrelic.com/docs/features/how-does-real-user-monitoring-work#cached-pages
This is also a nice overview of ordering your middleware correctly: http://verboselogging.com/2010/01/20/proper-rack-middleware-ordering
If you need more in-depth help, please open up a ticket with us by emailing support@newrelic.com