I've got a Python-based REST API. When an exception is hit during the execution of an API request, I generally try to catch the exception, log it, and return a generic error message along with an HTTP error code appropriate to the actual cause (i.e. 400 if the user makes and invalid request, 500 if the request is valid and something fails server-side).
The issue I'm having is that because I am catching the exceptions and logging them rather than raising them, the New Relic Python Agent is not logging most of my exceptions as errors, a really useful feature.
I know I can parse my logs to get the data I want for my own analysis, but I'd really like to continue to handle my issues and somehow still see them in New Relic without a ton of extra work. Any ideas on how or if this is possible?
By default the Python agent only picks up unhandled exceptions, however, you can override that default behavior by using this API call:
newrelic.agent.notice_error()
You should read this page on the Python agent API.