@@ -17,10 +17,9 @@ use rmp_serde;
17
17
use serde:: { Deserialize , Serialize } ;
18
18
19
19
use crate :: envelope:: { ContentType , ItemType } ;
20
- use crate :: services:: outcome:: { DiscardReason , Outcome } ;
20
+ use crate :: services:: outcome:: DiscardReason ;
21
21
use crate :: services:: processor:: { ProcessEnvelopeState , ProcessingError , ReplayGroup } ;
22
22
use crate :: statsd:: RelayTimers ;
23
- use crate :: utils:: ItemAction ;
24
23
25
24
/// Removes replays if the feature flag is not enabled.
26
25
pub fn process (
@@ -55,64 +54,57 @@ pub fn process(
55
54
let combined_envelope_items =
56
55
project_state. has_feature ( Feature :: SessionReplayCombinedEnvelopeItems ) ;
57
56
58
- state. managed_envelope . retain_items ( |item| {
59
- // If replays aren't enabled or an item was dropped - drop the remainder of the
60
- // envelope.
61
- if !replays_enabled {
62
- return ItemAction :: DropSilently ;
63
- }
57
+ // If the replay feature is not enabled drop the items silenty.
58
+ if !replays_enabled {
59
+ state. managed_envelope . drop_items_silently ( ) ;
60
+ return Ok ( ( ) ) ;
61
+ }
64
62
63
+ for item in state. managed_envelope . envelope_mut ( ) . items_mut ( ) {
65
64
// Set the combined payload header to the value of the combined feature.
66
65
item. set_replay_combined_payload ( combined_envelope_items) ;
67
66
68
67
match item. ty ( ) {
69
68
ItemType :: ReplayEvent => {
70
- match handle_replay_event_item (
69
+ let replay_event = handle_replay_event_item (
71
70
item. payload ( ) ,
72
71
& event_id,
73
72
project_config,
74
73
client_addr,
75
74
user_agent,
76
- ) {
77
- Err ( outcome) => ItemAction :: Drop ( outcome) ,
78
- Ok ( replay_event) => {
79
- item. set_payload ( ContentType :: Json , replay_event) ;
80
- ItemAction :: Keep
81
- }
82
- }
75
+ )
76
+ . map_err ( ProcessingError :: InvalidReplay ) ?;
77
+
78
+ item. set_payload ( ContentType :: Json , replay_event) ;
83
79
}
84
80
ItemType :: ReplayRecording => {
85
- match handle_replay_recording_item (
81
+ let replay_recording = handle_replay_recording_item (
86
82
item. payload ( ) ,
87
83
& event_id,
88
84
scrubbing_enabled,
89
85
& mut scrubber,
90
- ) {
91
- Err ( outcome) => ItemAction :: Drop ( outcome) ,
92
- Ok ( replay_recording) => {
93
- item. set_payload ( ContentType :: OctetStream , replay_recording) ;
94
- ItemAction :: Keep
95
- }
96
- }
86
+ )
87
+ . map_err ( ProcessingError :: InvalidReplay ) ?;
88
+
89
+ item. set_payload ( ContentType :: OctetStream , replay_recording) ;
97
90
}
98
- ItemType :: ReplayVideo => match handle_replay_video_item (
99
- item. payload ( ) ,
100
- & event_id,
101
- project_config,
102
- client_addr,
103
- user_agent,
104
- scrubbing_enabled,
105
- & mut scrubber,
106
- ) {
107
- Err ( outcome) => ItemAction :: Drop ( outcome) ,
108
- Ok ( payload) => {
109
- item. set_payload ( ContentType :: OctetStream , payload) ;
110
- ItemAction :: Keep
111
- }
112
- } ,
113
- _ => ItemAction :: Keep ,
91
+ ItemType :: ReplayVideo => {
92
+ let replay_video = handle_replay_video_item (
93
+ item. payload ( ) ,
94
+ & event_id,
95
+ project_config,
96
+ client_addr,
97
+ user_agent,
98
+ scrubbing_enabled,
99
+ & mut scrubber,
100
+ )
101
+ . map_err ( ProcessingError :: InvalidReplay ) ?;
102
+
103
+ item. set_payload ( ContentType :: OctetStream , replay_video) ;
104
+ }
105
+ _ => { }
114
106
}
115
- } ) ;
107
+ }
116
108
117
109
Ok ( ( ) )
118
110
}
@@ -125,7 +117,7 @@ fn handle_replay_event_item(
125
117
config : & ProjectConfig ,
126
118
client_ip : Option < IpAddr > ,
127
119
user_agent : & RawUserAgentInfo < & str > ,
128
- ) -> Result < Bytes , Outcome > {
120
+ ) -> Result < Bytes , DiscardReason > {
129
121
match process_replay_event ( & payload, config, client_ip, user_agent) {
130
122
Ok ( replay) => match replay. to_json ( ) {
131
123
Ok ( json) => Ok ( json. into_bytes ( ) . into ( ) ) ,
@@ -144,12 +136,12 @@ fn handle_replay_event_item(
144
136
?event_id,
145
137
"invalid replay event"
146
138
) ;
147
- Err ( Outcome :: Invalid ( match error {
139
+ Err ( match error {
148
140
ReplayError :: NoContent => DiscardReason :: InvalidReplayEventNoPayload ,
149
141
ReplayError :: CouldNotScrub ( _) => DiscardReason :: InvalidReplayEventPii ,
150
142
ReplayError :: CouldNotParse ( _) => DiscardReason :: InvalidReplayEvent ,
151
143
ReplayError :: InvalidPayload ( _) => DiscardReason :: InvalidReplayEvent ,
152
- } ) )
144
+ } )
153
145
}
154
146
}
155
147
}
@@ -197,7 +189,7 @@ fn handle_replay_recording_item(
197
189
event_id : & Option < EventId > ,
198
190
scrubbing_enabled : bool ,
199
191
scrubber : & mut RecordingScrubber ,
200
- ) -> Result < Bytes , Outcome > {
192
+ ) -> Result < Bytes , DiscardReason > {
201
193
// XXX: Processing is there just for data scrubbing. Skip the entire expensive
202
194
// processing step if we do not need to scrub.
203
195
if !scrubbing_enabled || scrubber. is_empty ( ) {
@@ -216,7 +208,7 @@ fn handle_replay_recording_item(
216
208
Ok ( recording) => Ok ( recording. into ( ) ) ,
217
209
Err ( e) => {
218
210
relay_log:: warn!( "replay-recording-event: {e} {event_id:?}" ) ;
219
- Err ( Outcome :: Invalid ( DiscardReason :: InvalidReplayRecordingEvent ) )
211
+ Err ( DiscardReason :: InvalidReplayRecordingEvent )
220
212
}
221
213
}
222
214
}
@@ -238,7 +230,7 @@ fn handle_replay_video_item(
238
230
user_agent : & RawUserAgentInfo < & str > ,
239
231
scrubbing_enabled : bool ,
240
232
scrubber : & mut RecordingScrubber ,
241
- ) -> Result < Bytes , Outcome > {
233
+ ) -> Result < Bytes , DiscardReason > {
242
234
let ReplayVideoEvent {
243
235
replay_event,
244
236
replay_recording,
@@ -247,7 +239,7 @@ fn handle_replay_video_item(
247
239
Ok ( result) => result,
248
240
Err ( e) => {
249
241
relay_log:: warn!( "replay-video-event: {e} {event_id:?}" ) ;
250
- return Err ( Outcome :: Invalid ( DiscardReason :: InvalidReplayVideoEvent ) ) ;
242
+ return Err ( DiscardReason :: InvalidReplayVideoEvent ) ;
251
243
}
252
244
} ;
253
245
@@ -261,7 +253,7 @@ fn handle_replay_video_item(
261
253
262
254
// Verify the replay-video payload is not empty.
263
255
if replay_video. is_empty ( ) {
264
- return Err ( Outcome :: Invalid ( DiscardReason :: InvalidReplayVideoEvent ) ) ;
256
+ return Err ( DiscardReason :: InvalidReplayVideoEvent ) ;
265
257
}
266
258
267
259
match rmp_serde:: to_vec_named ( & ReplayVideoEvent {
@@ -270,6 +262,6 @@ fn handle_replay_video_item(
270
262
replay_video,
271
263
} ) {
272
264
Ok ( payload) => Ok ( payload. into ( ) ) ,
273
- Err ( _) => Err ( Outcome :: Invalid ( DiscardReason :: InvalidReplayVideoEvent ) ) ,
265
+ Err ( _) => Err ( DiscardReason :: InvalidReplayVideoEvent ) ,
274
266
}
275
267
}
0 commit comments