diff --git a/Sources/Sentry/SentrySessionReplay.m b/Sources/Sentry/SentrySessionReplay.m index d3a921132b9..b13d6a4c201 100644 --- a/Sources/Sentry/SentrySessionReplay.m +++ b/Sources/Sentry/SentrySessionReplay.m @@ -129,12 +129,29 @@ - (void)captureReplayForEvent:(SentryEvent *)event; return; } - if ([_sentryRandom nextNumber] > _replayOptions.errorSampleRate) { + BOOL didCaptureReplay = [self captureReplay]; + if (!didCaptureReplay) { return; } - [self startFullReplay]; [self setEventContext:event]; +} + +- (BOOL)captureReplay +{ + if (!_isRunning) { + return NO; + } + + if (_isFullSession) { + return YES; + } + + if ([_sentryRandom nextNumber] > _replayOptions.errorSampleRate) { + return NO; + } + + [self startFullReplay]; NSURL *finalPath = [_urlToCache URLByAppendingPathComponent:@"replay.mp4"]; NSDate *replayStart = @@ -143,6 +160,8 @@ - (void)captureReplayForEvent:(SentryEvent *)event; [self createAndCapture:finalPath duration:_replayOptions.errorReplayDuration startedAt:replayStart]; + + return YES; } - (void)setEventContext:(SentryEvent *)event diff --git a/Sources/Sentry/include/SentrySessionReplay.h b/Sources/Sentry/include/SentrySessionReplay.h index 3aac91b620f..81282bcf95e 100644 --- a/Sources/Sentry/include/SentrySessionReplay.h +++ b/Sources/Sentry/include/SentrySessionReplay.h @@ -62,6 +62,11 @@ API_AVAILABLE(ios(16.0), tvos(16.0)) */ - (void)captureReplayForEvent:(SentryEvent *)event; +/** + * Captures a replay. This method is used by the Hybrid SDKs. + */ +- (BOOL)captureReplay; + @end NS_ASSUME_NONNULL_END diff --git a/Tests/SentryTests/Integrations/SessionReplay/SentrySessionReplayTests.swift b/Tests/SentryTests/Integrations/SessionReplay/SentrySessionReplayTests.swift index c3f1b13746f..6249ab60ddd 100644 --- a/Tests/SentryTests/Integrations/SessionReplay/SentrySessionReplayTests.swift +++ b/Tests/SentryTests/Integrations/SessionReplay/SentrySessionReplayTests.swift @@ -191,6 +191,18 @@ class SentrySessionReplayTests: XCTestCase { assertFullSession(sut, expected: false) } + @available(iOS 16.0, tvOS 16, *) + func testChangeReplayMode_forHybridSDKEvent() { + let fixture = startFixture() + let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1)) + sut.start(fixture.rootView, fullSession: false) + + sut.capture() + + expect(fixture.hub.scope.replayId) == sut.sessionReplayId.sentryIdString + assertFullSession(sut, expected: true) + } + @available(iOS 16.0, tvOS 16, *) func testSessionReplayMaximumDuration() { let fixture = startFixture()