From 089147f0551acb4a807874a018bdf0e2a4d894f2 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 7 May 2026 13:57:34 +0200 Subject: [PATCH 1/7] ref: Rename _timestamp to _end_timestamp --- sentry_sdk/traces.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sentry_sdk/traces.py b/sentry_sdk/traces.py index 7f3997438f..6f1bb3f290 100644 --- a/sentry_sdk/traces.py +++ b/sentry_sdk/traces.py @@ -291,7 +291,7 @@ def __init__( self._sample_rate = sample_rate self._start_timestamp = datetime.now(timezone.utc) - self._timestamp: "Optional[datetime]" = None + self._end_timestamp: "Optional[datetime]" = None # profiling depends on this value and requires that # it is measured in nanoseconds @@ -327,7 +327,7 @@ def __enter__(self) -> "StreamedSpan": def __exit__( self, ty: "Optional[Any]", value: "Optional[Any]", tb: "Optional[Any]" ) -> None: - if self._timestamp is not None: + if self._end_timestamp is not None: # This span is already finished, ignore return @@ -361,7 +361,7 @@ def _start(self) -> None: self._previous_span_on_scope = old_span def _end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None: - if self._timestamp is not None: + if self._end_timestamp is not None: # This span is already finished, ignore. return @@ -392,15 +392,15 @@ def _end(self, end_timestamp: "Optional[Union[float, datetime]]" = None) -> None pass if isinstance(end_timestamp, datetime): - self._timestamp = end_timestamp + self._end_timestamp = end_timestamp else: logger.debug( "[Tracing] Failed to set end_timestamp. Using current time instead." ) - if self._timestamp is None: + if self._end_timestamp is None: elapsed = nanosecond_time() - self._start_timestamp_monotonic_ns - self._timestamp = self._start_timestamp + timedelta( + self._end_timestamp = self._start_timestamp + timedelta( microseconds=elapsed / 1000 ) @@ -480,7 +480,7 @@ def start_timestamp(self) -> "Optional[datetime]": @property def timestamp(self) -> "Optional[datetime]": - return self._timestamp + return self._end_timestamp def _is_segment(self) -> bool: return self._segment is self From fee89f1488145e262149bab770161148d1244144 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 7 May 2026 13:59:16 +0200 Subject: [PATCH 2/7] more occurrences --- sentry_sdk/traces.py | 4 ++-- sentry_sdk/tracing_utils.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/traces.py b/sentry_sdk/traces.py index 6f1bb3f290..08a684c8b5 100644 --- a/sentry_sdk/traces.py +++ b/sentry_sdk/traces.py @@ -479,7 +479,7 @@ def start_timestamp(self) -> "Optional[datetime]": return self._start_timestamp @property - def timestamp(self) -> "Optional[datetime]": + def end_timestamp(self) -> "Optional[datetime]": return self._end_timestamp def _is_segment(self) -> bool: @@ -699,7 +699,7 @@ def start_timestamp(self) -> "Optional[datetime]": return None @property - def timestamp(self) -> "Optional[datetime]": + def end_timestamp(self) -> "Optional[datetime]": return None diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index 33b1a33814..e04879a8ea 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -400,7 +400,7 @@ def add_query_source( return end_timestamp = ( - datetime.now(timezone.utc) if span.timestamp is None else span.timestamp + datetime.now(timezone.utc) if span.end_timestamp is None else span.end_timestamp ) duration = end_timestamp - span.start_timestamp @@ -443,7 +443,7 @@ def add_http_request_source( return end_timestamp = ( - datetime.now(timezone.utc) if span.timestamp is None else span.timestamp + datetime.now(timezone.utc) if span.end_timestamp is None else span.end_timestamp ) duration = end_timestamp - span.start_timestamp From 0177165cf32f78ca0c87248be8d0cce69e18f325 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 7 May 2026 14:05:14 +0200 Subject: [PATCH 3/7] fix --- sentry_sdk/tracing_utils.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index e04879a8ea..8986759885 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -399,9 +399,12 @@ def add_query_source( if not should_add_query_source: return - end_timestamp = ( - datetime.now(timezone.utc) if span.end_timestamp is None else span.end_timestamp - ) + if isinstance(span, StreamedSpan): + end_timestamp = span.end_timestamp + else: + end_timestamp = span.timestamp + + end_timestamp = end_timestamp or datetime.now(timezone.utc) duration = end_timestamp - span.start_timestamp threshold = client.options.get("db_query_source_threshold_ms", 0) @@ -442,9 +445,12 @@ def add_http_request_source( if not should_add_request_source: return - end_timestamp = ( - datetime.now(timezone.utc) if span.end_timestamp is None else span.end_timestamp - ) + if isinstance(span, StreamedSpan): + end_timestamp = span.end_timestamp + else: + end_timestamp = span.timestamp + + end_timestamp = end_timestamp or datetime.now(timezone.utc) duration = end_timestamp - span.start_timestamp threshold = client.options.get("http_request_source_threshold_ms", 0) From ea130a0dbd2f8da8de6f9a08651858e61e09c8d8 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 7 May 2026 14:05:50 +0200 Subject: [PATCH 4/7] fix --- sentry_sdk/_span_batcher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/_span_batcher.py b/sentry_sdk/_span_batcher.py index 762b377af9..275462b21c 100644 --- a/sentry_sdk/_span_batcher.py +++ b/sentry_sdk/_span_batcher.py @@ -168,8 +168,8 @@ def _to_transport_format(item: "StreamedSpan") -> "Any": "start_timestamp": item._start_timestamp.timestamp(), } - if item._timestamp: - res["end_timestamp"] = item._timestamp.timestamp() + if item._end_timestamp: + res["end_timestamp"] = item._end_timestamp.timestamp() if item._parent_span_id: res["parent_span_id"] = item._parent_span_id From 1e3722589e46c7f081f9b509501bcb4e8032aa67 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 7 May 2026 14:08:19 +0200 Subject: [PATCH 5/7] . --- sentry_sdk/traces.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/traces.py b/sentry_sdk/traces.py index 08a684c8b5..9d10d9a2e2 100644 --- a/sentry_sdk/traces.py +++ b/sentry_sdk/traces.py @@ -244,7 +244,7 @@ class StreamedSpan: "_parent_sampled", "_start_timestamp", "_start_timestamp_monotonic_ns", - "_timestamp", + "_end_timestamp", "_status", "_scope", "_previous_span_on_scope", From ab6e51bed8eda72475e85af5b2b4367588bd52a7 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 7 May 2026 14:15:21 +0200 Subject: [PATCH 6/7] tests --- tests/integrations/stdlib/test_httplib.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index 589a8e8e97..b93b0c840c 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -873,9 +873,9 @@ def test_no_request_source_if_duration_too_short( def add_http_request_source_with_pinned_timestamps(span): if span_streaming: span._start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0) - span._timestamp = datetime.datetime(2024, 1, 1, microsecond=99999) + span._end_timestamp = datetime.datetime(2024, 1, 1, microsecond=99999) result = add_http_request_source(span) - span._timestamp = None + span._end_timestamp = None return result else: span.start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0) @@ -947,9 +947,9 @@ def test_request_source_if_duration_over_threshold( def add_http_request_source_with_pinned_timestamps(span): if span_streaming: span._start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0) - span._timestamp = datetime.datetime(2024, 1, 1, microsecond=100001) + span._end_timestamp = datetime.datetime(2024, 1, 1, microsecond=100001) result = add_http_request_source(span) - span._timestamp = None + span._end_timestamp = None return result else: span.start_timestamp = datetime.datetime(2024, 1, 1, microsecond=0) From ea2436cd0fa58fcaf77c59dbf206fe508fcff1e3 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 7 May 2026 14:16:30 +0200 Subject: [PATCH 7/7] another test --- tests/integrations/sqlalchemy/test_sqlalchemy.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/integrations/sqlalchemy/test_sqlalchemy.py b/tests/integrations/sqlalchemy/test_sqlalchemy.py index 72c50a7f9a..d942d5fea3 100644 --- a/tests/integrations/sqlalchemy/test_sqlalchemy.py +++ b/tests/integrations/sqlalchemy/test_sqlalchemy.py @@ -939,7 +939,9 @@ def __init__(self, *args, **kwargs): if span_streaming: self.span._start_timestamp = datetime(2024, 1, 1, microsecond=0) - self.span._timestamp = datetime(2024, 1, 1, microsecond=99999) + self.span._end_timestamp = datetime( + 2024, 1, 1, microsecond=99999 + ) else: self.span.start_timestamp = datetime(2024, 1, 1, microsecond=0) self.span.timestamp = datetime(2024, 1, 1, microsecond=99999) @@ -1003,7 +1005,9 @@ def __init__(self, *args, **kwargs): if span_streaming: self.span._start_timestamp = datetime(2024, 1, 1, microsecond=0) - self.span._timestamp = datetime(2024, 1, 1, microsecond=99999) + self.span._end_timestamp = datetime( + 2024, 1, 1, microsecond=99999 + ) else: self.span.start_timestamp = datetime(2024, 1, 1, microsecond=0) self.span.timestamp = datetime(2024, 1, 1, microsecond=99999) @@ -1082,7 +1086,7 @@ def __init__(self, *args, **kwargs): self.span = span self.span._start_timestamp = datetime(2024, 1, 1, microsecond=0) - self.span._timestamp = datetime(2024, 1, 1, microsecond=101000) + self.span._end_timestamp = datetime(2024, 1, 1, microsecond=101000) def __enter__(self): return self.span