diff --git a/CHANGELOG.md b/CHANGELOG.md index 5812b1c..7297b2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # main (unreleased) - **[FEATURE]**: feat(capture): add support for capture tracepoints [#34](https://github.com/intergral/deep/pull/34) [@Umaaz](https://github.com/Umaaz) +- **[BUGFIX]**: fix(duration): snapshot duration not set [#37](https://github.com/intergral/deep/pull/37) [@Umaaz](https://github.com/Umaaz) # 1.1.0 (06/02/2024) diff --git a/src/deep/api/tracepoint/eventsnapshot.py b/src/deep/api/tracepoint/eventsnapshot.py index 6ead750..8cf9da8 100644 --- a/src/deep/api/tracepoint/eventsnapshot.py +++ b/src/deep/api/tracepoint/eventsnapshot.py @@ -45,19 +45,11 @@ def __init__(self, tracepoint, ts, resource, frames, var_lookup: Dict[str, 'Vari self._attributes = BoundedAttributes(immutable=False) self._duration_nanos = 0 self._resource = Resource.get_empty().merge(resource) - self._open = True self._log = None def complete(self): """Close and complete the snapshot.""" - if not self._open: - return self._duration_nanos = time_ns() - self._ts_nanos - self._open = False - - def is_open(self): - """Is this snapshot still open.""" - return self._open def add_watch_result(self, watch_result: 'WatchResult'): """ @@ -66,8 +58,7 @@ def add_watch_result(self, watch_result: 'WatchResult'): :param watch_result: the result to append. :return: """ - if self.is_open(): - self.watches.append(watch_result) + self.watches.append(watch_result) def merge_var_lookup(self, lookup: Dict[str, 'Variable']): """ @@ -75,8 +66,7 @@ def merge_var_lookup(self, lookup: Dict[str, 'Variable']): :param lookup: the values to merge """ - if self.is_open(): - self._var_lookup.update(lookup) + self._var_lookup.update(lookup) @property def id(self): diff --git a/src/deep/processor/context/snapshot_action.py b/src/deep/processor/context/snapshot_action.py index 8d95216..b648226 100644 --- a/src/deep/processor/context/snapshot_action.py +++ b/src/deep/processor/context/snapshot_action.py @@ -139,6 +139,7 @@ def _process_action(self): snapshot.add_watch_result(watch) snapshot.merge_var_lookup(new_vars) + snapshot.complete() if self._is_deferred(): self.trigger_context.attach_result(DeferredSnapshotActionResult(self, snapshot)) else: diff --git a/tests/it_tests/test_it_basic.py b/tests/it_tests/test_it_basic.py index f3094b6..aae96df 100644 --- a/tests/it_tests/test_it_basic.py +++ b/tests/it_tests/test_it_basic.py @@ -47,6 +47,9 @@ def test_simple_it(self): snapshot = server.await_snapshot() _deep.shutdown() self.assertIsNotNone(snapshot) + + self.assertIsNot(0, snapshot.duration_nanos) + frames = snapshot.frames self.assertEqual(it_tests.test_target.__file__, frames[0].file_name) self.assertEqual("/it_tests/test_target.py", frames[0].short_path) @@ -81,6 +84,8 @@ def test_log_action(self): self.assertIsNotNone(snapshot) + self.assertIsNot(0, snapshot.duration_nanos) + self.assertEqual("[deep] test log name", snapshot.log_msg) self.assertIn("[deep] test log name", logs.output[0])