feat(session-replay-browser): migrate sampling from Java hashCode to xxHash32#1629
Merged
lewgordon-amplitude merged 4 commits intomainfrom Mar 26, 2026
Merged
feat(session-replay-browser): migrate sampling from Java hashCode to xxHash32#1629lewgordon-amplitude merged 4 commits intomainfrom
lewgordon-amplitude merged 4 commits intomainfrom
Conversation
Replace the Java-style 32-bit hashCode with xxHash32 for session ID sampling to improve uniformity at high bucket resolutions (1M+) and ensure cross-platform determinism (Web/iOS/Android). - Add pure JS xxHash32 implementation based on the official spec - Update isSessionInSample to use xxHash32(sessionId) % 1_000_000 - Add X-Sampling-Hash-Alg: xxhash32 header for server-side compat SR-1841 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Author
|
bugbot run |
Session Replay Browser E2E ResultsDetails
|
Collaborator
Author
|
@Mercy811 I wasn't sure if I should move this to core. |
Contributor
Thanks @lewgordon-amplitude, we can start with SR and move it to core later |
Mercy811
approved these changes
Mar 25, 2026
Verify that the X-Sampling-Hash-Alg: xxhash32 header is sent on track API requests, and that sampling in/out decisions are correct for known session IDs with pre-computed xxHash32 ratios. Also expand playwright testMatch from capture.spec.ts to *.spec.ts so privacy.spec.ts (added in SR-2943) is included in the test run. SR-1841 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two issues in the header test: 1. waitForRequest matched the CORS OPTIONS preflight (no X-Sampling-Hash-Alg) before the POST — fixed by predicating on POST method 2. blur alone may not guarantee a flush — added explicit sessionReplay.flush() matching the pattern used in flushRecording() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jxiwang
approved these changes
Mar 25, 2026
Collaborator
jxiwang
left a comment
There was a problem hiding this comment.
LGTM! Wonder why the lock diff is so big 🤔
Collaborator
Author
|
@jxiwang not sure. Let me check before merging. |
The lockfile was reformatted by a different pnpm environment in this worktree (multi-line → single-line resolution blocks, TypeScript peer dep re-resolution). No package changes were made, so restore to main. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Collaborator
Author
fixed! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the Java-style 32-bit hashCode with xxHash32 for session ID sampling to improve uniformity at high bucket resolutions (1M+) and ensure cross-platform determinism (Web/iOS/Android).
Implements https://amplitude.atlassian.net/wiki/spaces/IG/pages/3375071237
SR-1841
Checklist
Note
Medium Risk
Changes the core session sampling decision algorithm, which can alter which sessions are recorded at a given
sampleRateand impact event volume/coverage. Adds a new request header that backend systems may rely on for compatibility.Overview
Updates Session Replay sampling to use a new deterministic
xxHash32-based hash (hash % 1_000_000) viaisSessionInSample, replacing the previous timestamp-based sampling helper.Track requests now include
X-Sampling-Hash-Alg: xxhash32for server-side compatibility, and new unit/integration/e2e coverage is added to validate sampling decisions, determinism, and the emitted header (Playwright config now runs all*.spec.ts).Written by Cursor Bugbot for commit e4e5136. This will update automatically on new commits. Configure here.