Skip to content

Commit a2776ce

Browse files
fix(debugging): use millisecond for duration in expression DSL [backport 1.18] (#6766)
Backport b97591c from #6732 to 1.18. We convert the `@duration` injected local variable in milliseconds to match the UI expectation and report correct numbers. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] 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 8054daf commit a2776ce

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

ddtrace/debugging/_signal/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _eval_condition(self, _locals=None):
8484

8585
def _enrich_args(self, retval, exc_info, duration):
8686
_locals = list(self.args or safety.get_args(self.frame))
87-
_locals.append(("@duration", duration))
87+
_locals.append(("@duration", duration / 1e6)) # milliseconds
8888
if exc_info[1] is None:
8989
_locals.append(("@return", retval))
9090
return dict(_locals)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
dynamic instrumentation: function duration measurements are now reported in
5+
milliseconds to match the expectation from the UI.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
from threading import current_thread
3+
4+
from ddtrace.debugging._signal.snapshot import Snapshot
5+
from tests.debugging.utils import create_log_function_probe
6+
7+
8+
def test_duration_millis():
9+
duration = 123456
10+
args = Snapshot(
11+
probe=create_log_function_probe(
12+
probe_id="test_duration_millis",
13+
module="foo",
14+
func_qname="bar",
15+
template="",
16+
segments=[],
17+
),
18+
frame=sys._getframe(),
19+
thread=current_thread(),
20+
)._enrich_args(None, (None, None, None), duration)
21+
22+
assert args["@duration"] == duration / 1e6

0 commit comments

Comments
 (0)