Skip to content

Commit

Permalink
feat: Rename session replay errorSampleRate property to `onErrorSam…
Browse files Browse the repository at this point in the history
…pleRate` (#4218)

* Rename session replay `errorSampleRate` property to `onErrorSampleRate`

* Format code

* Update CHANGELOG.md

---------

Co-authored-by: Sentry Github Bot <[email protected]>
  • Loading branch information
brustolin and getsentry-bot authored Aug 1, 2024
1 parent aa225e2 commit 61249fb
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Replay for crashes (#4171)
- Redact web view from replay (#4203)
- Add beforeCaptureViewHierarchy callback (#4210)
- Rename session replay `errorSampleRate` property to `onErrorSampleRate` (#4218)

### Fixes

Expand Down
2 changes: 1 addition & 1 deletion Samples/iOS-Swift/iOS-Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
options.debug = true

if #available(iOS 16.0, *), !args.contains("--disable-session-replay") {
options.experimental.sessionReplay = SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1, redactAllText: true, redactAllImages: true)
options.experimental.sessionReplay = SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1, redactAllText: true, redactAllImages: true)
options.experimental.sessionReplay.quality = .high
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryBaseIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ - (BOOL)shouldBeEnabledWithOptions:(SentryOptions *)options

if (integrationOptions & kIntegrationOptionEnableReplay) {
if (@available(iOS 16.0, tvOS 16.0, *)) {
if (options.experimental.sessionReplay.errorSampleRate == 0
if (options.experimental.sessionReplay.onErrorSampleRate == 0
&& options.experimental.sessionReplay.sessionSampleRate == 0) {
[self logWithOptionName:@"sessionReplaySettings"];
return NO;
Expand Down
10 changes: 5 additions & 5 deletions Sources/Sentry/SentrySessionReplayIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ - (void)startSession
{
_startedAsFullSession = [self shouldReplayFullSession:_replayOptions.sessionSampleRate];

if (!_startedAsFullSession && _replayOptions.errorSampleRate == 0) {
if (!_startedAsFullSession && _replayOptions.onErrorSampleRate == 0) {
return;
}

Expand Down Expand Up @@ -279,9 +279,9 @@ - (void)saveCurrentSessionInfo:(SentryId *)sessionId
path:(NSString *)path
options:(SentryReplayOptions *)options
{
NSDictionary *info = [[NSDictionary alloc] initWithObjectsAndKeys:sessionId.sentryIdString,
@"replayId", path.lastPathComponent, @"path",
@(options.errorSampleRate), @"errorSampleRate", nil];
NSDictionary *info = [[NSDictionary alloc]
initWithObjectsAndKeys:sessionId.sentryIdString, @"replayId", path.lastPathComponent,
@"path", @(options.onErrorSampleRate), @"errorSampleRate", nil];

NSData *data = [SentrySerialization dataWithJSONObject:info];

Expand Down Expand Up @@ -422,7 +422,7 @@ - (SentryTouchTracker *)getTouchTracker
- (BOOL)sessionReplayIsFullSession
{
return SentryDependencyContainer.sharedInstance.random.nextNumber
<= _replayOptions.errorSampleRate;
<= _replayOptions.onErrorSampleRate;
}

- (void)sessionReplayNewSegmentWithReplayEvent:(SentryReplayEvent *)replayEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class SentryReplayOptions: NSObject, SentryRedactOptions {
* to the default.
* - note: The default is 0.
*/
public var errorSampleRate: Float
public var onErrorSampleRate: Float

/**
* Indicates whether session replay should redact all text in the app
Expand Down Expand Up @@ -112,7 +112,7 @@ public class SentryReplayOptions: NSObject, SentryRedactOptions {
*/
public override init() {
self.sessionSampleRate = 0
self.errorSampleRate = 0
self.onErrorSampleRate = 0
}

/**
Expand All @@ -122,9 +122,9 @@ public class SentryReplayOptions: NSObject, SentryRedactOptions {
* - errorSampleRate Indicates the percentage in which a 30 seconds replay will be send with
* error events.
*/
public init(sessionSampleRate: Float = 0, errorSampleRate: Float = 0, redactAllText: Bool = true, redactAllImages: Bool = true) {
public init(sessionSampleRate: Float = 0, onErrorSampleRate: Float = 0, redactAllText: Bool = true, redactAllImages: Bool = true) {
self.sessionSampleRate = sessionSampleRate
self.errorSampleRate = errorSampleRate
self.onErrorSampleRate = onErrorSampleRate
self.redactAllText = redactAllText
self.redactAllImages = redactAllImages
}
Expand All @@ -134,6 +134,6 @@ public class SentryReplayOptions: NSObject, SentryRedactOptions {
let onErrorSampleRate = (dictionary["errorSampleRate"] as? NSNumber)?.floatValue ?? 0
let redactAllText = (dictionary["redactAllText"] as? NSNumber)?.boolValue ?? true
let redactAllImages = (dictionary["redactAllImages"] as? NSNumber)?.boolValue ?? true
self.init(sessionSampleRate: sessionSampleRate, errorSampleRate: onErrorSampleRate, redactAllText: redactAllText, redactAllImages: redactAllImages)
self.init(sessionSampleRate: sessionSampleRate, onErrorSampleRate: onErrorSampleRate, redactAllText: redactAllText, redactAllImages: redactAllImages)
}
}
2 changes: 1 addition & 1 deletion Sources/Swift/SentryExperimentalOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class SentryExperimentalOptions: NSObject {
/**
* Settings to configure the session replay.
*/
public var sessionReplay = SentryReplayOptions(sessionSampleRate: 0, errorSampleRate: 0)
public var sessionReplay = SentryReplayOptions(sessionSampleRate: 0, onErrorSampleRate: 0)
#endif

func validateOptions(_ options: [String: Any]?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SentrySessionReplayIntegrationTests: XCTestCase {
private func startSDK(sessionSampleRate: Float, errorSampleRate: Float, enableSwizzling: Bool = true) {
SentrySDK.start {
$0.dsn = "https://[email protected]/test"
$0.experimental.sessionReplay = SentryReplayOptions(sessionSampleRate: sessionSampleRate, errorSampleRate: errorSampleRate)
$0.experimental.sessionReplay = SentryReplayOptions(sessionSampleRate: sessionSampleRate, onErrorSampleRate: errorSampleRate)
$0.setIntegrations([SentrySessionReplayIntegration.self])
$0.enableSwizzling = enableSwizzling
$0.cacheDirectoryPath = FileManager.default.temporaryDirectory.path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class SentrySessionReplayTests: XCTestCase {
var lastReplayId: SentryId?
var currentScreen: String?

func getSut(options: SentryReplayOptions = .init(sessionSampleRate: 0, errorSampleRate: 0) ) -> SentrySessionReplay {
func getSut(options: SentryReplayOptions = .init(sessionSampleRate: 0, onErrorSampleRate: 0) ) -> SentrySessionReplay {
return SentrySessionReplay(replayOptions: options,
replayFolderPath: cacheFolder,
screenshotProvider: screenshotProvider,
Expand Down Expand Up @@ -130,7 +130,7 @@ class SentrySessionReplayTests: XCTestCase {

func testVideoSize() {
let fixture = Fixture()
let options = SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1)
let options = SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1)
let sut = fixture.getSut(options: options)
let view = fixture.rootView
view.frame = CGRect(x: 0, y: 0, width: 320, height: 900)
Expand All @@ -143,7 +143,7 @@ class SentrySessionReplayTests: XCTestCase {
func testSentReplay_FullSession() {
let fixture = Fixture()

let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1))
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1))
sut.start(rootView: fixture.rootView, fullSession: true)
XCTAssertEqual(fixture.lastReplayId, sut.sessionReplayId)

Expand Down Expand Up @@ -171,7 +171,7 @@ class SentrySessionReplayTests: XCTestCase {

func testReplayScreenNames() throws {
let fixture = Fixture()
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1))
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1))
sut.start(rootView: fixture.rootView, fullSession: true)

for i in 1...6 {
Expand All @@ -193,7 +193,7 @@ class SentrySessionReplayTests: XCTestCase {

func testDontSentReplay_NotFullSession() {
let fixture = Fixture()
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1))
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1))
sut.start(rootView: fixture.rootView, fullSession: false)

XCTAssertNil(fixture.lastReplayId)
Expand All @@ -212,7 +212,7 @@ class SentrySessionReplayTests: XCTestCase {

func testChangeReplayMode_forErrorEvent() {
let fixture = Fixture()
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1))
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1))
sut.start(rootView: fixture.rootView, fullSession: false)
XCTAssertNil(fixture.lastReplayId)
let event = Event(error: NSError(domain: "Some error", code: 1))
Expand All @@ -225,7 +225,7 @@ class SentrySessionReplayTests: XCTestCase {

func testDontChangeReplayMode_forNonErrorEvent() {
let fixture = Fixture()
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1))
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1))
sut.start(rootView: fixture.rootView, fullSession: false)

let event = Event(level: .info)
Expand All @@ -237,7 +237,7 @@ class SentrySessionReplayTests: XCTestCase {

func testChangeReplayMode_forHybridSDKEvent() {
let fixture = Fixture()
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1))
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1))
sut.start(rootView: fixture.rootView, fullSession: false)

_ = sut.captureReplay()
Expand All @@ -248,7 +248,7 @@ class SentrySessionReplayTests: XCTestCase {

func testSessionReplayMaximumDuration() {
let fixture = Fixture()
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1))
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1))
sut.start(rootView: fixture.rootView, fullSession: true)

Dynamic(sut).newFrame(nil)
Expand All @@ -264,7 +264,7 @@ class SentrySessionReplayTests: XCTestCase {
func testSaveScreenShotInBufferMode() {
let fixture = Fixture()

let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 0, errorSampleRate: 1))
let sut = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 0, onErrorSampleRate: 1))
sut.start(rootView: fixture.rootView, fullSession: false)
fixture.dateProvider.advance(by: 1)
Dynamic(sut).newFrame(nil)
Expand All @@ -276,7 +276,7 @@ class SentrySessionReplayTests: XCTestCase {
func testDealloc_CallsStop() {
let fixture = Fixture()
func sutIsDeallocatedAfterCallingMe() {
_ = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, errorSampleRate: 1))
_ = fixture.getSut(options: SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1))
}
sutIsDeallocatedAfterCallingMe()

Expand Down
6 changes: 3 additions & 3 deletions Tests/SentryTests/SentryOptionsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ - (void)assertDefaultValues:(SentryOptions *)options
XCTAssertEqual(options.enablePreWarmedAppStartTracing, NO);
XCTAssertEqual(options.attachViewHierarchy, NO);
XCTAssertEqual(options.reportAccessibilityIdentifier, YES);
XCTAssertEqual(options.experimental.sessionReplay.errorSampleRate, 0);
XCTAssertEqual(options.experimental.sessionReplay.onErrorSampleRate, 0);
XCTAssertEqual(options.experimental.sessionReplay.sessionSampleRate, 0);
#endif // SENTRY_HAS_UIKIT
#pragma clang diagnostic push
Expand Down Expand Up @@ -879,7 +879,7 @@ - (void)testSessionReplaySettingsInit
@ { @"sessionReplay" : @ { @"sessionSampleRate" : @2, @"errorSampleRate" : @4 } }
}];
XCTAssertEqual(options.experimental.sessionReplay.sessionSampleRate, 2);
XCTAssertEqual(options.experimental.sessionReplay.errorSampleRate, 4);
XCTAssertEqual(options.experimental.sessionReplay.onErrorSampleRate, 4);
}
}

Expand All @@ -888,7 +888,7 @@ - (void)testSessionReplaySettingsDefaults
if (@available(iOS 16.0, tvOS 16.0, *)) {
SentryOptions *options = [self getValidOptions:@{ @"sessionReplayOptions" : @ {} }];
XCTAssertEqual(options.experimental.sessionReplay.sessionSampleRate, 0);
XCTAssertEqual(options.experimental.sessionReplay.errorSampleRate, 0);
XCTAssertEqual(options.experimental.sessionReplay.onErrorSampleRate, 0);
}
}

Expand Down

0 comments on commit 61249fb

Please sign in to comment.