diff --git a/ddtrace/debugging/_exception/auto_instrument.py b/ddtrace/debugging/_exception/auto_instrument.py index 36a4bbbe354..7b153647198 100644 --- a/ddtrace/debugging/_exception/auto_instrument.py +++ b/ddtrace/debugging/_exception/auto_instrument.py @@ -178,34 +178,32 @@ def on_span_finish(self, span: Span) -> None: code = frame.f_code seq_nr = next(seq) - if not is_user_code(Path(frame.f_code.co_filename)): - continue - - snapshot_id = frame.f_locals.get(SNAPSHOT_KEY, None) - if snapshot_id is None: - # We don't have a snapshot for the frame so we create one - snapshot = SpanExceptionSnapshot( - probe=SpanExceptionProbe.build(exc_id, frame), - frame=frame, - thread=current_thread(), - trace_context=span, - exc_id=exc_id, - ) - - # Capture - snapshot.line() - - # Collect - self.collector.push(snapshot) - - # Memoize - frame.f_locals[SNAPSHOT_KEY] = snapshot_id = snapshot.uuid - - # Add correlation tags on the span - span.set_tag_str(FRAME_SNAPSHOT_ID_TAG % seq_nr, snapshot_id) - span.set_tag_str(FRAME_FUNCTION_TAG % seq_nr, code.co_name) - span.set_tag_str(FRAME_FILE_TAG % seq_nr, code.co_filename) - span.set_tag_str(FRAME_LINE_TAG % seq_nr, str(_tb.tb_lineno)) + if is_user_code(Path(frame.f_code.co_filename)): + snapshot_id = frame.f_locals.get(SNAPSHOT_KEY, None) + if snapshot_id is None: + # We don't have a snapshot for the frame so we create one + snapshot = SpanExceptionSnapshot( + probe=SpanExceptionProbe.build(exc_id, frame), + frame=frame, + thread=current_thread(), + trace_context=span, + exc_id=exc_id, + ) + + # Capture + snapshot.line() + + # Collect + self.collector.push(snapshot) + + # Memoize + frame.f_locals[SNAPSHOT_KEY] = snapshot_id = snapshot.uuid + + # Add correlation tags on the span + span.set_tag_str(FRAME_SNAPSHOT_ID_TAG % seq_nr, snapshot_id) + span.set_tag_str(FRAME_FUNCTION_TAG % seq_nr, code.co_name) + span.set_tag_str(FRAME_FILE_TAG % seq_nr, code.co_filename) + span.set_tag_str(FRAME_LINE_TAG % seq_nr, str(_tb.tb_lineno)) # Move up the stack _tb = _tb.tb_next diff --git a/tests/debugging/exception/test_auto_instrument.py b/tests/debugging/exception/test_auto_instrument.py index 7717e746e89..53cee4b88d8 100644 --- a/tests/debugging/exception/test_auto_instrument.py +++ b/tests/debugging/exception/test_auto_instrument.py @@ -4,6 +4,7 @@ import ddtrace import ddtrace.debugging._exception.auto_instrument as auto_instrument +from ddtrace.internal.packages import _third_party_packages from ddtrace.internal.rate_limiter import BudgetRateLimiterWithJitter as RateLimiter from tests.debugging.mocking import exception_debugging from tests.utils import TracerTestCase @@ -24,8 +25,10 @@ def setUp(self): super(ExceptionDebuggingTestCase, self).setUp() self.backup_tracer = ddtrace.tracer ddtrace.tracer = self.tracer + _third_party_packages().remove("ddtrace") def tearDown(self): + _third_party_packages().add("ddtrace") ddtrace.tracer = self.backup_tracer super(ExceptionDebuggingTestCase, self).tearDown()