Skip to content

Commit 6e4b335

Browse files
fix(er): prioritize tb from exception object [backport 3.12] (#14503)
Backport 0103e2f from #14465 to 3.12. We retrieve the traceback object from the exception object itself, if available and prioritize it over the traceback component of the exception info tuple. Some frameworks, such as Celery, might modify the exception info tuple by passing around a custom traceback object that might not have all the information required by Exception Replay. ## Testing Strategy We tested that we can retrieve local variables in ER when Celery tasks throw exceptions with this change. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Gabriele N. Tornetta <[email protected]>
1 parent bdad60b commit 6e4b335

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

ddtrace/debugging/_exception/replay.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,16 @@ def _capture_tb_frame_for_span(
266266
return snapshot is not None
267267

268268
def on_span_exception(
269-
self, span: Span, _exc_type: t.Type[BaseException], exc: BaseException, tb: t.Optional[TracebackType]
269+
self, span: Span, _exc_type: t.Type[BaseException], exc: BaseException, traceback: t.Optional[TracebackType]
270270
) -> None:
271271
if span.get_tag(DEBUG_INFO_TAG) == "true" or not can_capture(span):
272272
# Debug info for span already captured or no budget to capture
273273
return
274274

275+
# Prioritize the traceback from the exception, if available. Some
276+
# frameworks (like celery) may modify the traceback object that is
277+
# passed to the exception handler.
278+
tb = exc.__traceback__ or traceback
275279
chain, exc_id = unwind_exception_chain(exc, tb)
276280
if not chain or exc_id is None:
277281
# No exceptions to capture
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
exception replay: fixed an issue that prevented snapshots from retrieving
5+
local variables from traceback frames from exception thrown by Celery tasks.

0 commit comments

Comments
 (0)