• /
  • EnglishEspañol日本語한국어Português
  • 로그인지금 시작하기

Ignoring specific transactions

New Relic for Ruby allows you to selectively disable instrumentation for particular requests within your Rails, Roda, or Sinatra application.

Blocking all instrumentation

Call newrelic_ignore with no arguments from within a Rails controller, Roda application, or Sinatra application to prevent instrumentation of all requests serviced by that controller or application:

newrelic_ignore

Using newrelic_ignore prevents the agent from recording any performance data (metrics, transaction traces, events, traced errors, and so on) for the targeted transactions, and will also prevent the transactions from contributing to your overall Apdex score.

Ignoring specific actions with Rails

If you want to ignore only specific actions with a Rails controller, you can use the :only or :except options with newrelic_ignore.

For example, to ignore only the index and show actions on the controller, use:

newrelic_ignore :only => [:index, :show]

To ignore all actions on the controller except index:

newrelic_ignore :except => [:index]

Ignoring specific routes with Roda

Ignore specific routes in Roda applications by passing a Roda-style route to newrelic_ignore from outside your Roda application's route block. For more information, see Roda: Ignoring routes.

Ignoring specific routes with Sinatra

If you want to ignore only specific routes within your Sinatra application, you can pass a Sinatra-style route definition to newrelic_ignore from within your Sinatra application. For more information, see Sinatra: Ignoring routes.

Ignoring Apdex contributions

If you want to prevent all actions in a controller from contributing to your Apdex score, but still want other performance data, use newrelic_ignore_apdex:

newrelic_ignore_apdex

In a Rails application, newrelic_ignore_apdex supports the same :only and :except options as newrelic_ignore. In a Roda or Sinatra application, it will accept the same Roda-style route or Sinatra-style route for targeting specific transactions.

Blocking browser instrumentation

Using newrelic_ignore_enduser prevents the agent from automatically inserting the JavaScript used to capture data. Server-side instrumentation will be unaffected.

To prevent browser agent injection for all actions in a controller, add a call like this to the controller class:

newrelic_ignore_enduser

In a Rails application, newrelic_ignore_enduser supports the same :only and :except options as newrelic_ignore. In a Roda or Sinatra application, it will accept the same Roda-style route or Sinatra-style route for targeting specific transactions.

Ignoring transactions dynamically

In some cases, you may want to base the decision to ignore a specific transaction on criteria only known at runtime, during the request. For scenarios like this, the declarative mechanisms explained above aren't a good fit. Starting in Ruby agent version 3.9.2, you can instead use the following family of API calls from any point within your transaction:

NewRelic::Agent.ignore_transaction
NewRelic::Agent.ignore_apdex
NewRelic::Agent.ignore_enduser

These methods will have a similar results to the newrelic_ignore, newrelic_ignore_apdex, and newrelic_ignore_enduser calls, but can be called during a request instead of during the class definition.

Ignoring transactions by URL with configuration

You can ignore transactions by URL using the rules.ignore_url_regexes configuration setting:

rules:
ignore_url_regexes: ["secret", "^/admin"]

This configuration will only prevent Transaction events that match the set pattern from reporting. Use any of the newrelic_ignore* family of methods if you would like to prevent all data, such as trace data, from reporting from a transaction.

Note that regexes do not include any type of anchoring by default. The /secret/ regex will match 'newrelic.com/secret/login' and it will also match 'newrelic.com/users/secretpanda'. The anchored admin regex will match 'newrelic.com/admin/praetorians' but it will not match 'newrelic.com/users/totally-real-admin'.

If necessary you may also provide a list of regexes in a comma-separated string, allowing you to set ignore regexes with an environment variable:

bash
$
NEW_RELIC_RULES_IGNORE_URL_REGEXES="secret,^/admin"

As always configuration from environment variables will override configuration in newrelic.yml.

Troubleshooting

The newrelic_ignore* family of methods will only work from within Rails controller classes, outside the route block of Roda applications (subclasses of Roda), or within Sinatra applications (subclasses of Sinatra::Base). Other applications should use the NewRelic::Agent.ignore_* family of calls from within each request that you would like to ignore, which will work in any context.

If you get a NoMethodError when trying to use newrelic_ignore from within a Rails controller, Roda application, or Sinatra application, make sure that newrelic_rpm has been required before you try to call newrelic_ignore inside of your class definition.

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.