Skip to content

feat(replay): Add hooks for a Hybrid SDK's own replay recorder and frames - #6829

Draft
bitsandfoxes wants to merge 11 commits into
mainfrom
spire/sentry-java-hooks-for-hybrid-sdk-session
Draft

bitsandfoxes wants to merge 11 commits into
mainfrom
spire/sentry-java-hooks-for-hybrid-sdk-session

Conversation

@bitsandfoxes

@bitsandfoxes bitsandfoxes commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Enables getsentry/sentry-unity#2948

📜 Description

A hybrid SDK sets a ReplayRecorderFactory on ReplayIntegration with setRecorderFactory, in the options callback of SentryAndroid.init. The Android SDK's session replay then records with the hybrid SDK's own Recorder. The hybrid SDK hands each frame it captures to onFrame(pixels, width, height) as RGBA bytes. Both APIs are @ApiStatus.Internal.

Diagram

Diagram source
sequenceDiagram
    participant H as Hybrid SDK
    participant A as Android SDK session replay
    H->>A: set the recorder factory (options callback)
    A->>H: create a recorder, given the frame receiver
    H-->>A: its own recorder
    A->>H: start the recorder
    H->>A: report the frame size
    A->>H: the recording size
    loop each captured frame
        H->>A: hand over the RGBA pixels
    end
    A->>A: build, encode and upload the segments
    H->>A: app paused: pause the replay
    A->>H: pause the recorder
    H->>A: app back: resume the replay
    A->>H: resume the recorder

The hybrid SDK owns its app's lifecycle. It pauses and resumes the replay through the replay controller's pause and resume, the same calls Sentry.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:

  • it starts recording at init, as the sample rates say;
  • it builds, encodes, buffers and uploads the segments;
  • it pauses itself while the device is offline or rate limited, and stops the recorder when the replay ends.

When the replay registers, it asks the factory for a recorder instead of using its own view-drawing recorder. It passes the factory the ReplayFrameReceiver that takes the frames. A recorderProvider passed to the constructor still takes precedence.

Once recording, the hybrid SDK reports its frame size through onWindowSizeChanged or onConfigurationChanged. No segment is sent until it does, and its frames must match the recording size the recorder receives.

onFrame takes 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:

  • build ReplayIntegration through its Kotlin-only constructor with reflection;
  • swap it into the options;
  • build an Android Bitmap through 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 ReplayIntegrationTest cover:

  • the factory's recorder being registered and started, with the integration passed in as its frame receiver;
  • onFrame storing a frame of the given size;
  • frames being dropped while the replay is stopped or paused, or when their byte count doesn't match their 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:

Per frame Bitmap built through JNI onFrame
Unity main thread ~0.6 ms 0.47–0.58 ms
Hand-over off the main thread 7–9 ms 2.7–3.3 ms

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

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

…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.
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 9e8b2d4

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 9e8b2d4.

Main concerns: public contract, host performance, data sent to Sentry.

Rules that block low also fired:

  • R4: a public API record changed: sentry-android-replay/api/sentry-android-replay.api

This label is a hint for reviewers, not an approval.

@sentry

sentry Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.66.0 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Dec 1, 2026
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Dec 1, 2026
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Dec 1, 2026
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Dec 1, 2026

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

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant