Search code examples
ruby-on-railsnewrelicamp-html

How to disable newrelic_rpm on Rails AMP page


The AMP validator says "The tag 'script' is disallowed except in specific forms.".

Now I know this tag 'script' is automatically created by newrelic_rpm.

My problem is that how I can disable newrelic_rpm on AMP page.

The URL of my AMP page is like http://example.com/foo/bar.amp.

So I tried settings like this config/newrelic.yml:

common: &default_settings
  license_key: foobarfoobarfoobarfoobar

  app_name: Foobar

  rules.ignore_url_regexes: ["amp", ".*amp"]

development:
  <<: *default_settings
  app_name: FooBar (Development)

  developer_mode: true

But it doesn't work.

My project environment:

  • rails (4.1.8)
  • ruby (2.2.3)
  • newrelic_rpm (3.14.0.305)

Solution

  • I did the same thing. Small tweaks to @Awjecc's answer

    ApplicationController < ActionController::Base
    
      before_action :ignore_newrelic, :if => :amp_request?
    
       ...
    
    
      private
    
      def ignore_newrelic
        NewRelic::Agent.ignore_transaction
        NewRelic::Agent.ignore_apdex
        NewRelic::Agent.ignore_enduser
      end
    
      def amp_request?
        request.format.try(:amp?)
      end
    
    end