Blocking instrumentation in Java

There are multiple ways to block instrumentation in Java. Transactions that are ignored will not be included in the metrics you see in New Relic.

To use the API, refer to the Java agent API document. Some other methods are listed below.

Set a servlet request

To ignore a web transaction, set a ServletRequest attribute named com.newrelic.agent.IGNORE to true during the request:

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

To specify URLs to ignore, create a servlet filter 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.

Use an annotation

To tell the Java agent to ignore transactions using Annotations:

  1. Define an annotation called NewRelicIgnoreTransaction:

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

    @NewRelicIgnoreTransaction
    public void ignore() {
    }

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.

You can also prevent the transaction from contributing to the Apdex score but still be used in transaction traces, define a NewRelicIgnoreApdex annotation:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface NewRelicIgnoreApdex {
}

For more help

You can also use the API to block instrumentation:

If you need additional help, get support at support.newrelic.com.