Skip to content

fix(NewRelicContextFormatter): add cause and context to stack traces#1266

Merged
TimPansino merged 11 commits intonewrelic:mainfrom
sweco:main
Jan 29, 2025
Merged

fix(NewRelicContextFormatter): add cause and context to stack traces#1266
TimPansino merged 11 commits intonewrelic:mainfrom
sweco:main

Conversation

@sweco
Copy link
Contributor

@sweco sweco commented Nov 29, 2024

Overview

NewRelicContextFormatter logs stack traces without causes which makes many errors hard to debug.

Let's take a look at the following code:

try:
    try:
        raise ValueError("First exception")
    except:
        raise ValueError("Second exception")
except Exception as e:
    logging.error("Encountered error", exc_info=e)

Before the PR, the exception message looked as follows:

  File ".../newrelic_exception_cause.py", line 60, in <module>
    raise ValueError("Second exception")

After the PR, it shows more details on the first cause:

Traceback (most recent call last):
  File ".../newrelic_exception_cause.py", line 58, in <module>
    raise ValueError("First exception")
ValueError: First exception
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File ".../newrelic_exception_cause.py", line 60, in <module>
    raise ValueError("Second exception")
ValueError: Second exception

Related Github Issue

No Github issue created.

Testing

Tests were updated to test a particular case where exception has a cause.

@CLAassistant
Copy link

CLAassistant commented Nov 29, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ sweco
✅ TimPansino
❌ mergify[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@sweco sweco marked this pull request as ready for review November 29, 2024 15:01
@sweco sweco requested a review from a team as a code owner November 29, 2024 15:01
@TimPansino
Copy link
Contributor

We'll give this a review after the US holiday season is over, we're going to avoid the risk of changing anyone's logs during this time period.

@mergify mergify bot added tests-failing Tests failing in CI. and removed tests-failing Tests failing in CI. labels Jan 29, 2025
@TimPansino TimPansino merged commit 019b019 into newrelic:main Jan 29, 2025
50 of 53 checks passed
@TimPansino TimPansino added this to the v10.5.0 milestone Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants