Skip to content

Conversation

@michellewzhang
Copy link
Member

@michellewzhang michellewzhang commented Nov 6, 2025

related to: #102897

backend PR for filtering out events that occur before the replay start time, so we don't have to generate log messages for those. we filter out these events on the frontend as well -- they aren't shown as breadcrumbs.

also fix some timestamp inconsistencies in tests

@michellewzhang michellewzhang requested a review from a team as a code owner November 6, 2025 23:14
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 6, 2025
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Prematurely Emitting Pre-Start Error Events

Remaining error events are yielded without checking if they occurred before replay_start_ms. After processing all segment events, the code yields all remaining errors regardless of their timestamps, allowing error messages from before the replay started to appear in the logs.

src/sentry/replays/usecases/summarize.py#L310-L320

# Yield any remaining error messages
while error_idx < len(error_events):
error = error_events[error_idx]
if error["category"] == "error":
yield generate_error_log_message(error)
elif error["category"] == "feedback":
yield generate_feedback_log_message(error)
error_idx += 1

Fix in Cursor Fix in Web


Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Feedback breadcrumb timestamp in seconds causes filtering error

The feedback breadcrumb timestamp in the test is in seconds instead of milliseconds. The timestamp field should be float((now - timedelta(minutes=3)).timestamp() * 1000) to match the expected millisecond format for segment events, causing this feedback to be incorrectly filtered out as occurring before the replay start.

tests/sentry/replays/usecases/test_summarize.py#L1404-L1405

self.store_replay(dt=now - timedelta(minutes=10), segment_id=0, trace_ids=[trace_id])

Fix in Cursor Fix in Web


return list(generate_summary_logs(segment_data, error_events, project_id, is_mobile_replay))
return list(
generate_summary_logs(
segment_data, error_events, project_id, is_mobile_replay, replay_start
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
segment_data, error_events, project_id, is_mobile_replay, replay_start
segment_data, error_events, project_id, is_mobile_replay=is_mobile_replay, replay_start=replay_start

and same for L598 - best to be explicit w kwargs

"""
error_idx = 0
seen_feedback_ids = {error["id"] for error in error_events if error["category"] == "feedback"}
replay_start_ms = _parse_iso_timestamp_to_ms(replay_start) if replay_start else 0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
replay_start_ms = _parse_iso_timestamp_to_ms(replay_start) if replay_start else 0.0
replay_start_ms = _parse_iso_timestamp_to_ms(replay_start) if replay_start else 0.0
while error_events[error_idx]["timestamp"] < replay_start_ms:
error_idx += 1

lets you avoid the ifs below when yielding errors

Comment on lines +1533 to +1559
# Create an error that occurred BEFORE replay start (should be filtered)
early_error_id = uuid.uuid4().hex
early_error_timestamp = (replay_start - timedelta(minutes=3)).timestamp()
self.store_event(
data={
"event_id": early_error_id,
"timestamp": early_error_timestamp,
"exception": {
"values": [
{
"type": "EarlyError",
"value": "This happened before replay started",
}
]
},
"contexts": {
"trace": {
"type": "trace",
"trace_id": trace_id,
"span_id": span_id,
}
},
},
project_id=self.project.id,
)

# Create an error that occurred AFTER replay start (should be included)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would make these errors direct connected rather than trace connected, cuz the trace query already uses the replay range filter

@codecov
Copy link

codecov bot commented Nov 6, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
29528 1 29527 239
View the top 1 failed test(s) by shortest run time
tests.sentry.replays.usecases.test_summarize.RpcGetReplaySummaryLogsTestCase::test_rpc_filters_out_events_before_replay_start
Stack Traces | 15.6s run time
#x1B[1m#x1B[.../replays/usecases/test_summarize.py#x1B[0m:1620: in test_rpc_filters_out_events_before_replay_start
    assert len(logs) == 2
#x1B[1m#x1B[31mE   assert 1 == 2#x1B[0m
#x1B[1m#x1B[31mE    +  where 1 = len(["Logged: 'world' at 1762472342648.16"])#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants