Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions Sources/Sentry/SentrySessionReplay.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -143,6 +160,8 @@ - (void)captureReplayForEvent:(SentryEvent *)event;
[self createAndCapture:finalPath
duration:_replayOptions.errorReplayDuration
startedAt:replayStart];

return YES;
}

- (void)setEventContext:(SentryEvent *)event
Expand Down
5 changes: 5 additions & 0 deletions Sources/Sentry/include/SentrySessionReplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down