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

Support for Chained Exception Tracebacks

Open fliu98 opened this issue 3 years ago • 4 comments

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

Being able to see the tracebacks for chained exceptions as a part of the stack trace in the NewRelic Errors UI is helpful for debugging issues in our code.

Currently, only the traceback for the most recent exception is considered when building error nodes. The traceback is extracted from sys.exc_info() in _observe_exception(...), then formatted by this call to exception_stack(...).

Feature Description

Ideally, exception_stack(...) should take in the value of the exception, then read and format the traceback from its __traceback__ attribute, concatenating it to the end of the formatted current stack. Additionally, it should follow the exception chain using the __context__ or __cause__ attribute on the exception while concatenating the formatted traceback of each exception along the way.

Describe Alternatives

Looking for suggestions.

Additional context

Here's a short example:

# foo.py

import newrelic.agent

def c():
    raise Exception("c")


def d():
    try:
        c()
    except Exception as e:
        raise Exception("d") from e


try:
    d()
except:
    newrelic.agent.notice_error()

Should report something like:

Traceback (most recent call last):
File "foo.py", line 17, in <module>
File "foo.py", line 13, in d
caused by: Exception('c')
Traceback (most recent call last):
File "foo.py", line 11, in d
File "foo.py", line 6, in c

Priority

Really Want

fliu98 avatar Mar 07 '22 19:03 fliu98

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 13 '22 00:06 stale[bot]