Skip to content

fix(replays): Count malformed recording payloads instead of reporting errors - #132186

Draft
sentry-junior[bot] wants to merge 4 commits into
masterfrom
georgegritsouk/replay-1043-improve-handling-of-byte-invalid
Draft

sentry-junior[bot] wants to merge 4 commits into
masterfrom
georgegritsouk/replay-1043-improve-handling-of-byte-invalid

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

The recording consumer drops payloads whose header line can't be parsed, but it logs them with logger.exception. That makes an error event (via the internal handler) for client data we can't recover, and it puts the raw recording bytes into the event's frame vars.

The case that prompted this: a payload whose "header" is compressed bytes instead of {"segment_id":N}. json.loads decodes the bytes as UTF-8 first, so it fails with UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9c in position 1 (0x9c is the second byte of the zlib header).

Changes:

  • parse_headers and decompress_segment raise InvalidRecording(reason), a DropSilently subclass. The reasons are missing_headers, invalid_headers_json, invalid_segment_id, and invalid_body.
  • parse_recording_event catches it, reports it, and re-raises:
    • a Sentry metric, replays.consumer.recording.invalid, with a reason attribute
    • a Sentry log with the org, project, DSN key, and replay ids, the payload size, and the payload's first 8 bytes as hex
    • from the replay event, the log also carries the SDK name and version, platform, environment, replay type, and browser and OS contexts
  • parse_headers drops its now-unused replay_id argument.

Behavior is otherwise unchanged: these segments were already dropped. Rejecting them at ingest with an outcome belongs in Relay and is out of scope here.

Fixes REPLAY-1043

via George Gritsouk.

--

View Session [Sentry]

… errors

A recording whose header line isn't valid JSON (e.g. compressed bytes in
the header slot) was logged with logger.exception, creating error events
for client data we can't recover. Drop these with a
replays.consumer.recording.invalid metric tagged by reason and a warning
log instead. The same applies to bodies that are neither zlib nor JSON.

Fixes REPLAY-1043

Co-Authored-By: George Gritsouk <george.gritsouk@sentry.io>
@linear-code

linear-code Bot commented Nov 23, 2026

Copy link
Copy Markdown

REPLAY-1043

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 23, 2026

@gggritso gggritso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense, just a small o11y request

Use sentry_sdk.metrics.count instead of a Datadog counter and a warning
log, so dropped invalid recordings show up in Sentry metrics.

@gggritso gggritso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another question about telemetry

Log each dropped invalid recording to Sentry Logs with the org and project
slugs, DSN key, payload size and first bytes, and the SDK, environment,
release, replay type, browser, and OS from the replay event, so we can
trace malformed payloads back to their sender.

@gggritso gggritso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking better, a few more questions

Drop the project and organization slug lookup, plus the release and segment
id attributes, from the invalid recording log.

This branch has not been deployed

No deployments
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.

1 participant