newrelic-python-agent icon indicating copy to clipboard operation
newrelic-python-agent copied to clipboard

Include backtrace when logger.exception(...) is called.

Open philomory opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

We are trying to get backtraces attached to our logged exceptions, the way they are in e.g. the Java agent. We log exceptions via e.g.

try:
  some_code()
except ExampleException:
  logger.exception("a message!")

In the console output for the application, this results in the full exception details being logged alongside the message, include the exception class, backtrace, etc. But New Relic only gets the exception message.

Feature Description

When the logger.exception(...) method of the standard library logging module is called, the exception details should be included in the Log event sent to New Relic.

Describe Alternatives

We can (and will have to) add newrelic.agent.notice_error(...) calls to all of our exception handlers, but, this feels like something that should not be necessary (and is actually a slightly different feature regardless, since that still doesn't attach the backtrace to the logs the way they ought to be).

Additional context

Python 3.8, New Relic Python Agent version 9.12.0, non-web process. All default configuration (except NEW_RELIC_APP_NAME, NEW_RELIC_LOG, NEW_RELIC_LABELS, NEW_RELIC_LICENSE_KEY. Tried setting NEW_RELIC_APPLICATION_LOGGING_FORWARDING_CONTEXT_DATA_ENABLED, but it did not have the desired effect.

Priority

Please help us better understand this feature request by choosing a priority from the following options: Really Want

philomory avatar Jul 17 '24 01:07 philomory

https://new-relic.atlassian.net/browse/NR-292557

Is there any update on this? Any straightforward work-arounds for getting error traceback in the UI while this is being worked on?

neerajprad avatar Jan 27 '25 18:01 neerajprad

You're likely looking for context data on logs. When called with logging.exception() you should see exception information as available context data attributes.

If you enable this, you may want to set up filtering with include/exclude rules as well to only include nonsensitive data you actually care about.

If this setting doesn't have what you're looking for let us know.

TimPansino avatar Jan 29 '25 22:01 TimPansino