@@ -1524,11 +1524,65 @@ def test_rpc_web_replay_navigation(self) -> None:
15241524 assert len (logs ) == 0
15251525
15261526 def test_rpc_filters_out_events_before_replay_start (self ) -> None :
1527- """Test that events before the replay start are not logged ."""
1527+ """Test that both segment events and error events before replay start are filtered out ."""
15281528 now = datetime .now (UTC )
15291529 replay_start = now - timedelta (minutes = 1 )
1530+ trace_id = uuid .uuid4 ().hex
1531+ span_id = "1" + uuid .uuid4 ().hex [:15 ]
15301532
1531- self .store_replay (dt = replay_start )
1533+ # Create an error that occurred BEFORE replay start (should be filtered)
1534+ early_error_id = uuid .uuid4 ().hex
1535+ early_error_timestamp = (replay_start - timedelta (minutes = 3 )).timestamp ()
1536+ self .store_event (
1537+ data = {
1538+ "event_id" : early_error_id ,
1539+ "timestamp" : early_error_timestamp ,
1540+ "exception" : {
1541+ "values" : [
1542+ {
1543+ "type" : "EarlyError" ,
1544+ "value" : "This happened before replay started" ,
1545+ }
1546+ ]
1547+ },
1548+ "contexts" : {
1549+ "trace" : {
1550+ "type" : "trace" ,
1551+ "trace_id" : trace_id ,
1552+ "span_id" : span_id ,
1553+ }
1554+ },
1555+ },
1556+ project_id = self .project .id ,
1557+ )
1558+
1559+ # Create an error that occurred AFTER replay start (should be included)
1560+ late_error_id = uuid .uuid4 ().hex
1561+ late_error_timestamp = (replay_start + timedelta (minutes = 2 )).timestamp ()
1562+ self .store_event (
1563+ data = {
1564+ "event_id" : late_error_id ,
1565+ "timestamp" : late_error_timestamp ,
1566+ "exception" : {
1567+ "values" : [
1568+ {
1569+ "type" : "LateError" ,
1570+ "value" : "This happened after replay started" ,
1571+ }
1572+ ]
1573+ },
1574+ "contexts" : {
1575+ "trace" : {
1576+ "type" : "trace" ,
1577+ "trace_id" : trace_id ,
1578+ "span_id" : span_id ,
1579+ }
1580+ },
1581+ },
1582+ project_id = self .project .id ,
1583+ )
1584+
1585+ self .store_replay (dt = replay_start , segment_id = 0 , trace_ids = [trace_id ])
15321586
15331587 data = [
15341588 {
@@ -1563,5 +1617,14 @@ def test_rpc_filters_out_events_before_replay_start(self) -> None:
15631617 )
15641618
15651619 logs = response ["logs" ]
1566- assert len (logs ) == 1
1567- assert "world" in logs [0 ]
1620+ assert len (logs ) == 2
1621+
1622+ # Should include the late error and the "world" console message
1623+ assert "LateError" in logs [0 ]
1624+ assert "This happened after replay started" in logs [0 ]
1625+ assert "world" in logs [1 ]
1626+
1627+ # Should NOT include the early error or "hello" console message
1628+ assert not any ("EarlyError" in log for log in logs )
1629+ assert not any ("This happened before replay started" in log for log in logs )
1630+ assert not any ("hello" in log for log in logs )
0 commit comments