Repository navigation
feat(replay): Add hooks for a Hybrid SDK's own replay recorder and frames - #6829
Draft
bitsandfoxes wants to merge 11 commits into
Draft
bitsandfoxes wants to merge 11 commits into
bitsandfoxes wants to merge 11 commits into
Conversation
…frames Hybrid SDKs, such as Unity, capture the screen themselves. A recorder factory set on ReplayIntegration replaces the replay's own recorder, and onFrame takes frames as RGBA pixels, copied into a reused bitmap on the replay's thread.
Contributor
|
Contributor
PR risk: mediumFor commit Main concerns: public contract, host performance, data sent to Sentry. Rules that block low also fired:
This label is a hint for reviewers, not an approval. |
📲 Install BuildsAndroid
|
This branch has not been deployed
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.
Enables getsentry/sentry-unity#2948
📜 Description
A hybrid SDK sets a
ReplayRecorderFactoryonReplayIntegrationwithsetRecorderFactory, in the options callback ofSentryAndroid.init. The Android SDK's session replay then records with the hybrid SDK's ownRecorder. The hybrid SDK hands each frame it captures toonFrame(pixels, width, height)as RGBA bytes. Both APIs are@ApiStatus.Internal.Diagram source
The hybrid SDK owns its app's lifecycle. It pauses and resumes the replay through the replay controller's
pauseandresume, the same callsSentry.replay()makes. The replay then ends or starts a segment and pauses or resumes the recorder.The Android SDK's session replay does everything else, just as it does with its own recorder:
When the replay registers, it asks the factory for a recorder instead of using its own view-drawing recorder. It passes the factory the
ReplayFrameReceiverthat takes the frames. ArecorderProviderpassed to the constructor still takes precedence.Once recording, the hybrid SDK reports its frame size through
onWindowSizeChangedoronConfigurationChanged. No segment is sent until it does, and its frames must match the recording size the recorder receives.onFrametakes the frame's timestamp on the caller's thread. On the replay's existing executor, it then copies the pixels into one bitmap, reused while the size stays the same, and stores it the same way as the replay's own screenshots. It drops frames that arrive while the replay is paused or stopped. It also drops frames whose byte count doesn't match their size, and logs an error. No thread is added, and the caller's thread does nothing beyond the call.💡 Motivation and Context
Hybrid SDKs such as Unity draw their screen themselves, often into a surface the Android view hierarchy can't see. To record a session replay of it, they have to:
ReplayIntegrationthrough its Kotlin-only constructor with reflection;Bitmapthrough JNI for every frame.That path is fragile, and it does its JNI work on the hybrid SDK's threads. These hooks give hybrid SDKs a supported way in. getsentry/sentry-unity#2948 uses them.
💚 How did you test it?
Unit tests in
ReplayIntegrationTestcover:onFramestoring a frame of the given size;On a Pixel 6 (Android 16), sentry-unity's Unity of Bugs sample recorded with these APIs, its recorder rewritten to use them. Per frame:
onFrame📝 Checklist
sendDefaultPIIis enabled.The replay carries whatever frames the hybrid SDK hands in. Masking them is that SDK's job, because the Android SDK can't see what they show. The APIs are internal, so they need no docs or wizard changes.
🔮 Next steps