Skip to content

Add experimental Session Replay capturing on Mac#1425

Merged
tustanivsky merged 18 commits into
mainfrom
feat/session-replay-mac
Jun 10, 2026
Merged

Add experimental Session Replay capturing on Mac#1425
tustanivsky merged 18 commits into
mainfrom
feat/session-replay-mac

Conversation

@tustanivsky

@tustanivsky tustanivsky commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

This PR extends the opt-in Session Replay feature support to macOS allowing the SDK to continuously record the last several seconds of gameplay into a MP4 file and attach it to crash reports.

Example crash event with Session Replay attached (Mac).

Key Changes

  • FMacSentrySubsystem now spawns the recorder in both backend modes (Cocoa and Native). The resulting .mp4 is attached via onLastRunStatusDetermined when using the Cocoa backend and via the in-process OnCrash hook when using the Native backend.

  • FSentryBackBufferCapture now parameterizes its texture acquisition helpers over (format, flags, initial state), allowing the same FCachedTexture / FCachedTexturePool infrastructure to be shared across platforms.

  • On macOS, the capture pipeline introduces an intermediate texture between the format-conversion draw pass and the CPU-readable pool slot, as Metal does not allow RenderTargetable and CPUReadback flags on the same texture.

Engine Dependencies

In addition to AVCodecsCore, Mac builds require the experimental VTCodecs plugin (Mac-only, ships with UE 5.2+). Both must be enabled in the project for USE_SENTRY_SESSION_REPLAY to be defined (guards session replay code).

Other Considerations

  • Metal flag restrictions: VT's RHI bridge requires TexCreate_CPUReadback on the texture it receives, while Metal RHI does not allow TexCreate_CPUReadback and TexCreate_RenderTargetable to be used on the same texture. As a result, the macOS path performs one additional GPU copy from a singleton BGRA8 render-target intermediate into the CPU-readable texture from the pool.
  • VT timestamp units: Encoder->SendFrame expects timestamps in microseconds on VT (whereas NVENC treats them as opaque values), and Packet.Timestamp is returned as mach_absolute_time host-clock ticks (whereas NVENC echoes the original value unchanged). The encoder thread now performs platform-specific timestamp conversion, scaling SendFrame timestamps to microseconds on macOS and converting packet timestamps via FPlatformTime::ToMilliseconds64.

Documentation

Related items

@github-actions

github-actions Bot commented Jun 6, 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 536aa97

@tustanivsky
tustanivsky marked this pull request as ready for review June 8, 2026 06:54
Comment thread plugin-dev/Source/Sentry/Sentry.Build.cs
Comment thread plugin-dev/Source/Sentry/Private/Mac/MacSentrySubsystem.cpp
Comment thread plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.cpp
Comment thread plugin-dev/Source/Sentry/Private/SessionReplay/SentryVideoEncoder.cpp Outdated
Comment thread plugin-dev/Source/Sentry/Private/SessionReplay/SentryVideoEncoder.cpp Outdated

@JoshuaMoelans JoshuaMoelans 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.

lgtm, just a small fix on some bot-formatting + one follow-up question:
Q: could we have some tests for the session replay behaviour? I can imagine it's hard to capture actual session replays in CI, but maybe we can unit test certain parts of the flow?

Comment thread plugin-dev/Source/Sentry/Private/SessionReplay/SentryVideoEncoder.cpp Outdated
tustanivsky and others added 2 commits June 10, 2026 14:39
…der.cpp

Co-authored-by: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 536aa97. Configure here.

@tustanivsky

Copy link
Copy Markdown
Collaborator Author

Q: could we have some tests for the session replay behaviour? I can imagine it's hard to capture actual session replays in CI, but maybe we can unit test certain parts of the flow?

Testing replay capturing in CI doesn't seem particularly realistic (at least with GitHub-hosted runners) since it requires actual rendering to occur (non-null RHI) and the codec behavior is hardware-bound (NVENC requires an Nvidia GPU while VT runs only on macOS where we don't currently run checks at all).

The only component that's unit-testable in isolation is FSentryFMP4Writer as it's just byte-level muxing. That might be something we can cover in a follow-up PR though.

@tustanivsky
tustanivsky merged commit f196f5a into main Jun 10, 2026
44 of 46 checks passed
@tustanivsky
tustanivsky deleted the feat/session-replay-mac branch June 10, 2026 12:12
tustanivsky added a commit to getsentry/sentry-docs that referenced this pull request Jun 11, 2026
This PR adds macOS-specific details to the Session Replay docs for
Unreal SDK.

Related items:
- getsentry/sentry-unreal#1425
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants