Skip to content

Commit 96a26d7

Browse files
chore(di): fix top of stack in function snapshots [backport 2.16] (#11417)
Backport 9f6776d from #11239 to 2.16. We fix a regression introduced with #11153 whereby the top of the stack might have incorrect line number information ## 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 a46977f commit 96a26d7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

ddtrace/debugging/_signal/snapshot.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ def exit(self, retval, exc_info, duration, scope) -> None:
137137
self.duration = duration
138138
self.return_capture = self._do(retval, exc_info, scope)
139139

140+
# Fix the line number of the top frame. This might have been mangled by
141+
# the instrumented exception handling of function probes.
142+
assert self._stack is not None # nosec B101
143+
tb = exc_info[2]
144+
while tb is not None:
145+
frame = tb.tb_frame
146+
if frame == self.frame:
147+
self._stack[0]["lineNumber"] = tb.tb_lineno
148+
break
149+
tb = tb.tb_next
150+
140151
def line(self, scope) -> None:
141152
self.line_capture = self._do(_NOTSET, sys.exc_info(), scope)
142153

tests/debugging/test_debugger.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ def test_debugger_function_probe_on_function_with_exception():
207207
snapshot_data = snapshot["debugger"]["snapshot"]
208208
assert snapshot_data["stack"][0]["fileName"].endswith("stuff.py")
209209
assert snapshot_data["stack"][0]["function"] == "throwexcstuff"
210+
assert snapshot_data["stack"][0]["lineNumber"] == 110
210211

211212
entry_capture = snapshot_data["captures"]["entry"]
212213
assert entry_capture["arguments"] == {}

0 commit comments

Comments
 (0)