Skip to content

Commit 19eeac5

Browse files
ericapisaniclaude
andcommitted
ref: Simplify end timestamp calculation in add_http_request_source
Remove start_timestamp_monotonic_ns from StreamedSpan and NoOpStreamedSpan, and simplify the end timestamp fallback in add_http_request_source to use datetime.now(timezone.utc) directly. The monotonic-based calculation added complexity without meaningful benefit over the UTC fallback. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9d2546f commit 19eeac5

2 files changed

Lines changed: 3 additions & 22 deletions

File tree

sentry_sdk/traces.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,6 @@ def sampled(self) -> "Optional[bool]":
464464
def start_timestamp(self) -> "Optional[datetime]":
465465
return self._start_timestamp
466466

467-
@property
468-
def start_timestamp_monotonic_ns(self) -> "Optional[int]":
469-
return self._start_timestamp_monotonic_ns
470-
471467
@property
472468
def timestamp(self) -> "Optional[datetime]":
473469
return self._timestamp
@@ -682,10 +678,6 @@ def sampled(self) -> "Optional[bool]":
682678
def start_timestamp(self) -> "Optional[datetime]":
683679
return None
684680

685-
@property
686-
def start_timestamp_monotonic_ns(self) -> "Optional[int]":
687-
return None
688-
689681
@property
690682
def timestamp(self) -> "Optional[datetime]":
691683
return None

sentry_sdk/tracing_utils.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
filename_for_module,
2525
logger,
2626
match_regex_list,
27-
nanosecond_time,
2827
qualname_from_function,
2928
safe_repr,
3029
to_string,
@@ -369,19 +368,9 @@ def add_http_request_source(
369368
if not should_add_request_source:
370369
return
371370

372-
if span.timestamp is None:
373-
if (
374-
isinstance(span, sentry_sdk.traces.StreamedSpan)
375-
and span.start_timestamp_monotonic_ns is not None
376-
):
377-
elapsed = nanosecond_time() - span.start_timestamp_monotonic_ns
378-
end_timestamp = span.start_timestamp + timedelta(
379-
microseconds=elapsed / 1000
380-
)
381-
else:
382-
end_timestamp = datetime.now(timezone.utc)
383-
else:
384-
end_timestamp = span.timestamp
371+
end_timestamp = (
372+
datetime.now(timezone.utc) if span.timestamp is None else span.timestamp
373+
)
385374

386375
duration = end_timestamp - span.start_timestamp
387376
threshold = client.options.get("http_request_source_threshold_ms", 0)

0 commit comments

Comments
 (0)