newrelic / newrelic-python-agent

New Relic Python Agent
https://docs.newrelic.com/docs/agents/python-agent
Apache License 2.0
175 stars 99 forks source link

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

Open philomory opened 1 month ago

philomory commented 1 month ago

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

workato-integration[bot] commented 1 month ago

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