Skip to content

Commit

Permalink
feat(replay): add captureReplay without Event param for Hybrid SDKs (
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich authored Apr 25, 2024
1 parent 07b120c commit b4f8dba
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
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

0 comments on commit b4f8dba

Please sign in to comment.