【问题标题】:How to disable newrelic_rpm on Rails AMP page如何在 Rails AMP 页面上禁用 newrelic_rpm
【发布时间】:2017-02-18 00:24:53
【问题描述】:

AMP 验证器显示“不允许使用标签‘脚本’,除非以特定形式出现。”。

现在我知道这个标签“脚本”是由 newrelic_rpm 自动创建的。

我的问题是如何在 AMP 页面上禁用 newrelic_rpm。

我的 AMP 页面的 URL 类似于 http://example.com/foo/bar.amp

所以我尝试了这样的设置 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

但它不起作用。

我的项目环境:

  • 导轨 (4.1.8)
  • 红宝石 (2.2.3)
  • newrelic_rpm (3.14.0.305)

【问题讨论】:

    标签: ruby-on-rails newrelic amp-html


    【解决方案1】:

    我也做了同样的事情。对@Awjecc 答案的小调整

    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
    

    【讨论】:

    • 也许值得让你的其他控制器使用amp_request?,不是吗?
    • 其他控制器通常继承自 ApplicationController 并且应该可以访问该方法
    • private 方法不能从继承/子类访问。这就是为什么你通常使用protected 方法来代替。
    • 是的,要在另一个控制器中使用amp_request? 方法,它不能是私有的——它可以被保护。
    【解决方案2】:

    我自己解决了。

    application_controller.rb

    class ApplicationController < ActionController::Base
      before_action :before_amp,
                    if: -> { request.path_parameters[:format] == 'amp' }
    
      private
    
      def before_amp
        NewRelic::Agent.ignore_transaction
        NewRelic::Agent.ignore_apdex
        NewRelic::Agent.ignore_enduser
      end
    end
    

    我会把这个问题留给遇到同样情况的人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多