diff --git a/ddtrace/debugging/_exception/replay.py b/ddtrace/debugging/_exception/replay.py index 690b269848c..fb1ddf43d4a 100644 --- a/ddtrace/debugging/_exception/replay.py +++ b/ddtrace/debugging/_exception/replay.py @@ -266,12 +266,16 @@ def _capture_tb_frame_for_span( return snapshot is not None def on_span_exception( - self, span: Span, _exc_type: t.Type[BaseException], exc: BaseException, tb: t.Optional[TracebackType] + self, span: Span, _exc_type: t.Type[BaseException], exc: BaseException, traceback: t.Optional[TracebackType] ) -> None: if span.get_tag(DEBUG_INFO_TAG) == "true" or not can_capture(span): # Debug info for span already captured or no budget to capture return + # Prioritize the traceback from the exception, if available. Some + # frameworks (like celery) may modify the traceback object that is + # passed to the exception handler. + tb = exc.__traceback__ or traceback chain, exc_id = unwind_exception_chain(exc, tb) if not chain or exc_id is None: # No exceptions to capture diff --git a/releasenotes/notes/fix-er-tb-priority-77dc656bdb2c4802.yaml b/releasenotes/notes/fix-er-tb-priority-77dc656bdb2c4802.yaml new file mode 100644 index 00000000000..c3b55431431 --- /dev/null +++ b/releasenotes/notes/fix-er-tb-priority-77dc656bdb2c4802.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + exception replay: fixed an issue that prevented snapshots from retrieving + local variables from traceback frames from exception thrown by Celery tasks.