---
title: Ignoring specific transactions
source: https://docs.newrelic.com/docs/apm/agents/ruby-agent/api-guides/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 [#ignore]

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:

```rb
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 [#ignore-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:

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

To ignore all actions on the controller **except** `index`:

```rb
newrelic_ignore :except => [:index]
```

## Ignoring specific routes with Roda [#ignore-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](https://docs.newrelic.com/docs/agents/ruby-agent/frameworks/roda-support#ignoring-routes).

## Ignoring specific routes with Sinatra [#ignore-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](https://docs.newrelic.com/docs/agents/ruby-agent/frameworks/sinatra-support#ignoring-routes).

## Ignoring Apdex contributions [#apdex]

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`:

```rb
newrelic_ignore_apdex
```

In a Rails application, `newrelic_ignore_apdex` supports the same [`:only` and `:except` options](#ignore-rails) as `newrelic_ignore`. In a Roda or Sinatra application, it will accept the [same Roda-style route](#ignore-roda) or [Sinatra-style route](#ignore-sinatra) for targeting specific transactions.

## Blocking browser instrumentation [#page-load-timing-rum]

Using `newrelic_ignore_enduser` prevents the agent from automatically inserting the JavaScript used to capture [browser monitoring](https://docs.newrelic.com/docs/agents/ruby-agent/features/page-load-timing-ruby) 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:

```rb
newrelic_ignore_enduser
```

In a Rails application, `newrelic_ignore_enduser` supports the same [`:only` and `:except` options](#ignore-rails) as `newrelic_ignore`. In a Roda or Sinatra application, it will accept the [same Roda-style route](#ignore-roda) or [Sinatra-style route](#ignore-sinatra) for targeting specific transactions.

## Ignoring transactions dynamically [#dynamic-ignoring]

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:

```rb
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 [#config-ignoring]

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

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

This configuration will only prevent [Transaction events](https://docs.newrelic.com/docs/telemetry-data-platform/understand-data/event-data/events-reported-apm/) 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:

```sh
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.
