Can I ignore particular exceptions in New Relic Java API?
Asked Answered
D

3

7

I am using the New Relic Java API to monitor a Jersey Rest application secured by OAuth.

In our application we throw an exception whenever somebody tries to do something unauthorized. While these are exceptions, they do not need to be monitored by the New Relic Error reporting.

I see on the Java API that there is a method to make sure that an error is reported to New Relic ( https://docs.newrelic.com/docs/java/java-agent-api NewRelic.noticeError(Throwable throwable) )

Is there any way to suppress reporting of a particular type of exception? My idea would be something like NewRelic.ignoreError(Class clazz) where I could mark certain types of exception classes as ignored for reporting.

Dominicadominical answered 12/11, 2013 at 20:56 Comment(0)
I
9

I work for New Relic.

While there is no Java Agent API call to ignore an error, I have filed a feature request to create such a call. However, this won't help you in the near term since we won't be able to promise a timeline on when or if we'll implement this.

So, here is the nature of the things our agent calls errors - perhaps you will be able to change your code a bit so that the error is not noticed by our agent? Effectively, once you handle an exception and DO NOT call the noticeError() method, the exception will not be categorized as or recorded as an error in New Relic. Any chance you can add an exception handler to render your 40x pages instead of letting those exceptions go unhandled?

You can also choose to ignoreTransaction() on the entire transaction, which will cause it not to be categorized as an error either. It's suboptimal since preferably you watch all of your production traffic to know when your error handler itself gets slow or ends up creating its own (unexpected) error, but this should work as well.

Finally, you can ignore HTTP status codes and specific exception names in your agent config - either newrelic.yml (if you use client side config) or on your application settings page (https://rpm.newrelic.com/accounts/X/applications/Y/edit) page if you use server side config.

Note that ignoring a status code or exception name via agent config will only prevent the error from being logged individually, but will still add to the error count / Error Rate, upon which you might be alerting; handling the exception or calling ignoreTransaction() will purge it from the error rate as well.

If none of these approaches work for you, we'd be happy to talk with you further, but you should open a support ticket at https://support.newrelic.com , since this isn't the right forum for discussion.

Ibidem answered 12/11, 2013 at 23:49 Comment(3)
Thanks for the detailed answer! Refactoring the application to handle all exceptions like this is a bigger job than we're prepared to take on for this purpose. And we want to include these transactions in the overall performance monitoring so I can't just ignore the transaction as ignored. I will follow the guidance to set particular HTTP status codes as 'ignored', but as you point out this will still lead to high error counts. documentation here: docs.newrelic.com/docs/java/java-agent-configurationDominicadominical
can I use the ignore_errors config setting to ignore those exceptions?Dominicadominical
Another possibility is marking the error as expected: docs.newrelic.com/docs/agents/manage-apm-agents/agent-data/…Tribute
N
6

I work for New Relic too, and since Fool is my mortal enemy, I disagree! Not really, but I would note that I think the ignore_errors setting within the the newrelic.yml configuration file is the best option here: you can specify class names to ignore. Otherwise you can use ignore_status_codes, and I think your 'not authorized' errors probably have a consistent error code.

This will also cause your error rate to go down (in earlier versions of the agent ignore_errors would only prevent traces and not change error rate, this is fixed after version 3.0).

Nyberg answered 30/11, 2013 at 19:26 Comment(0)
H
-1

I don't work for New Relic, but to state the final option. Is it possible for your application not to return an error, and instead return 200 but give details of the error in the reply.

Not ideal but it's an option.

Hueyhuff answered 25/11, 2015 at 12:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.