newrelic / newrelic/newrelic-python-agent

Support for Chained Exception Tracebacks

Open
#496 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request
Dominant language
Python
Stars
210
Forks
137
Avg merge
4d 19h
Merged PRs (30d)
12

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in newrelic/api/time_trace.py at _observe_exception(...) and newrelic/api/transaction.py at the exception_stack(...) call to trace how sys.exc_info() is currently formatted. Follow the requested traceback, context, and cause behavior, and consider the provided foo.py output the definition of done: the current and chained exception tracebacks appear in the reported stack.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability-sre
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.