---
title: Ignore specific transactions
source: https://docs.newrelic.com/docs/apm/agents/java-agent/instrumentation/ignore-transactions-using-api
---

New Relic for Java gives you multiple methods to ignore specific transactions. This document explains how to use the [Java agent API annotations](https://docs.newrelic.com/docs/agents/java-agent/custom-instrumentation/java-agent-api) and `ServletRequest` to ignore transactions.

It is also possible to use the `ignoreTransaction()` [API call](http://newrelic.github.io/java-agent-api/javadoc/index.html?com/newrelic/api/agent/NewRelic.html) and [XML instrumentation files](https://docs.newrelic.com/docs/agents/java-agent/custom-instrumentation/java-custom-instrumentation-xml-examples#file-format) to ignore transactions.

> #### ⚠️ IMPORTANT
>
> Ignoring transactions involves changing your application's source code and recompiling your application in all cases **unless** you use an [XML instrumentation file](https://docs.newrelic.com/docs/agents/java-agent/custom-instrumentation/java-custom-instrumentation-xml-examples#file-format). If you cannot manipulate your code, use XML to ignore transactions.

## Ignore web transactions with ServletRequest [#servlet]

To ignore a web transaction, set a [`ServletRequest`](http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html) attribute named `com.newrelic.agent.IGNORE` to `true` during the request:

```java
request.setAttribute("com.newrelic.agent.IGNORE", true);
```

To specify URLs to ignore, create a servlet [filter](http://docs.oracle.com/javaee/6/api/javax/servlet/Filter.html) which sets that attribute and apply the filter to the servlet you want to ignore. The filter will have access to the request URI if you need to ignore specific URLs.

## Ignore transactions with annotation [#annotation]

To tell the Java agent to ignore transactions using annotations:

1.  Define an annotation called `NewRelicIgnoreTransaction` in your application's code or a library you can integrate with your application:

    ```java
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface NewRelicIgnoreTransaction {
    }
    ```
2.  Apply the annotation to the methods or classes you want to ignore. For example:

    ```java
    @NewRelicIgnoreTransaction
    public void methodToBeIgnored() {
    }
    ```

If a transaction calls a method or class annotated with `@NewRelicIgnoreTransaction`, the transaction is ignored. This means it does not contribute to the overall Apdex score; and the transaction trace and performance data is not reported.

## Ignore apdex but not traces [#apdex]

You can also prevent the transaction from contributing to the Apdex score but still be used in transaction. This can prevent one particularly lengthy transaction from skewing your Apdex score. To prevent a transaction from contributing to your Apdex score:

1.  Define an annotation called `NewRelicIgnoreApdex` in your application's code or a library you can integrate with your application:

    ```java
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface NewRelicIgnoreApdex {
    }
    ```
2.  Apply the annotation to the methods or classes you want to ignore. For example:

    ```java
    @NewRelicIgnoreApdex
    public void ignoreApdexOfThisMethod() {
    }
    ```

If a transaction calls a method or class annotated with `@NewRelicIgnoreApdex`, the transaction is reported, but does not contribute to the overall Apdex score.
