diff --git a/ddtrace/debugging/_origin/span.py b/ddtrace/debugging/_origin/span.py index 9f3c2174a4c..abd63dbb97d 100644 --- a/ddtrace/debugging/_origin/span.py +++ b/ddtrace/debugging/_origin/span.py @@ -154,6 +154,8 @@ def __enter__(self): s.set_tag_str("_dd.code_origin.frames.0.type", location.module) s.set_tag_str("_dd.code_origin.frames.0.method", location.name) + self.set("start_time", monotonic_ns()) + return self def _close_signal(self, retval=None, exc_info=(None, None, None)): @@ -180,9 +182,6 @@ def _close_signal(self, retval=None, exc_info=(None, None, None)): root.set_tag_str("_dd.code_origin.frames.0.snapshot_id", snapshot.uuid) span.set_tag_str("_dd.code_origin.frames.0.snapshot_id", snapshot.uuid) - self.set("snapshot", snapshot) - self.set("start_time", monotonic_ns()) - snapshot.do_exit(retval, exc_info, monotonic_ns() - self.get("start_time")) self.collector.push(snapshot) diff --git a/tests/debugging/test_session.py b/tests/debugging/test_session.py index af2988ec49f..ef71b062d70 100644 --- a/tests/debugging/test_session.py +++ b/tests/debugging/test_session.py @@ -1,14 +1,30 @@ import pytest +from ddtrace.debugging._session import DEFAULT_SESSION_LEVEL +from ddtrace.debugging._session import Session from ddtrace.debugging._session import _sessions_from_debug_tag from ddtrace.debugging._session import _sessions_to_debug_tag +@pytest.mark.parametrize( + "tag,sessions", + [ + ("session1", [Session("session1", DEFAULT_SESSION_LEVEL)]), + ("session1:2", [Session("session1", 2)]), + ("session1:1.session2:2", [Session("session1", 1), Session("session2", 2)]), + ("session1.session2", [Session("session1", DEFAULT_SESSION_LEVEL), Session("session2", DEFAULT_SESSION_LEVEL)]), + ], +) +def test_session_parse(tag, sessions): + assert list(_sessions_from_debug_tag(tag)) == sessions + + @pytest.mark.parametrize( "a,b", [ ("session1:1.session2:2", "session1.session2:2"), ("session1:0.session2:2", "session1:0.session2:2"), + ("session1.session2", "session1.session2"), ], ) def test_tag_identity(a, b):