Skip to content

Commit

Permalink
fix(replays): Lower segment_id cap to one hour (#3280)
Browse files Browse the repository at this point in the history
Lowers the segment-id limit to match the limit specified in our terms of
service.

---------

Co-authored-by: Iker Barriocanal <32816711+iker-barriocanal@users.noreply.github.com>
Co-authored-by: Joris Bayer <joris.bayer@sentry.io>
  • Loading branch information
3 people committed Jul 16, 2024
1 parent 46a5a35 commit c9bd1f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Remove experimental double-write from spans to transactions. ([#3801](https://github.com/getsentry/relay/pull/3801))
- Add feature flag to disable replay-video events. ([#3803](https://github.com/getsentry/relay/pull/3803))
- Write the envelope's Dynamic Sampling Context (DSC) into event payloads for debugging. ([#3811](https://github.com/getsentry/relay/pull/3811))
- Decrease max allowed segment_id for replays to one hour. ([#3280](https://github.com/getsentry/relay/pull/3280))
- Extract a duration light metric for spans without a transaction name tag. ([#3772](https://github.com/getsentry/relay/pull/3772))

## 24.6.0
Expand Down
16 changes: 9 additions & 7 deletions relay-event-normalization/src/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ pub fn validate(replay: &Replay) -> Result<(), ReplayError> {
.value()
.ok_or_else(|| ReplayError::InvalidPayload("missing segment_id".to_string()))?;

if segment_id > u16::MAX as u64 {
// Each segment is expected to be 5 seconds in length. We take the number of seconds in
// an hour and divide by five to get the max segment-id.
const MAX_SEGMENT_ID: u64 = 60 * 60 / 5;

if segment_id > MAX_SEGMENT_ID {
return Err(ReplayError::InvalidPayload(
"segment_id exceeded u16 limit".to_string(),
"segment_id limit exceeded".to_string(),
));
}

Expand Down Expand Up @@ -365,22 +369,20 @@ mod tests {
}

#[test]
fn test_validate_u16_segment_id() {
// Does not fit within a u16.
fn test_validate_segment_id() {
let replay_id =
Annotated::new(EventId("52df9022835246eeb317dbd739ccd059".parse().unwrap()));
let segment_id: Annotated<u64> = Annotated::new(u16::MAX as u64 + 1);
let segment_id: Annotated<u64> = Annotated::new(721);
let mut replay = Annotated::new(Replay {
replay_id,
segment_id,
..Default::default()
});
assert!(validate(replay.value_mut().as_mut().unwrap()).is_err());

// Fits within a u16.
let replay_id =
Annotated::new(EventId("52df9022835246eeb317dbd739ccd059".parse().unwrap()));
let segment_id: Annotated<u64> = Annotated::new(u16::MAX as u64);
let segment_id: Annotated<u64> = Annotated::new(720);
let mut replay = Annotated::new(Replay {
replay_id,
segment_id,
Expand Down

0 comments on commit c9bd1f8

Please sign in to comment.