-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add options to redact or ignore view for Replay (#4228)
Added options to ReplayOptions for users to specify which classes to redact or ignore during replay. Also added functions to SentrySDK and a UIView extension to choose specific views to redact or ignore.
- Loading branch information
Showing
11 changed files
with
245 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#if canImport(UIKit) && !SENTRY_NO_UIKIT | ||
#if os(iOS) || os(tvOS) | ||
import Foundation | ||
import UIKit | ||
|
||
public extension UIView { | ||
|
||
/** | ||
* Marks this view to be redacted during replays. | ||
* - warning: This is an experimental feature and may still have bugs. | ||
*/ | ||
func sentryReplayRedact() { | ||
SentryRedactViewHelper.redactView(self) | ||
} | ||
|
||
/** | ||
* Marks this view to be ignored during redact step | ||
* of session replay. All its content will be visible in the replay. | ||
* - warning: This is an experimental feature and may still have bugs. | ||
*/ | ||
func sentryReplayIgnore() { | ||
SentryRedactViewHelper.ignoreView(self) | ||
} | ||
} | ||
|
||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,13 +42,14 @@ class SentrySessionReplayIntegrationTests: XCTestCase { | |
return try XCTUnwrap(SentrySDK.currentHub().installedIntegrations().first as? SentrySessionReplayIntegration) | ||
} | ||
|
||
private func startSDK(sessionSampleRate: Float, errorSampleRate: Float, enableSwizzling: Bool = true) { | ||
private func startSDK(sessionSampleRate: Float, errorSampleRate: Float, enableSwizzling: Bool = true, configure: ((Options) -> Void)? = nil) { | ||
SentrySDK.start { | ||
$0.dsn = "https://[email protected]/test" | ||
$0.experimental.sessionReplay = SentryReplayOptions(sessionSampleRate: sessionSampleRate, onErrorSampleRate: errorSampleRate) | ||
$0.setIntegrations([SentrySessionReplayIntegration.self]) | ||
$0.enableSwizzling = enableSwizzling | ||
$0.cacheDirectoryPath = FileManager.default.temporaryDirectory.path | ||
configure?($0) | ||
} | ||
SentrySDK.currentHub().startSession() | ||
} | ||
|
@@ -272,6 +273,30 @@ class SentrySessionReplayIntegrationTests: XCTestCase { | |
XCTAssertEqual(hub.capturedReplayRecordingVideo.count, 0) | ||
} | ||
|
||
func testMaskViewFromSDK() { | ||
class AnotherLabel: UILabel { | ||
} | ||
|
||
startSDK(sessionSampleRate: 1, errorSampleRate: 1) { options in | ||
options.experimental.sessionReplay.redactViewTypes = [AnotherLabel.self] | ||
} | ||
|
||
let redactBuilder = SentryViewPhotographer.shared.getRedactBuild() | ||
XCTAssertTrue(redactBuilder.containsRedactClass(AnotherLabel.self)) | ||
} | ||
|
||
func testIgnoreViewFromSDK() { | ||
class AnotherLabel: UILabel { | ||
} | ||
|
||
startSDK(sessionSampleRate: 1, errorSampleRate: 1) { options in | ||
options.experimental.sessionReplay.ignoreRedactViewTypes = [AnotherLabel.self] | ||
} | ||
|
||
let redactBuilder = SentryViewPhotographer.shared.getRedactBuild() | ||
XCTAssertTrue(redactBuilder.containsIgnoreClass(AnotherLabel.self)) | ||
} | ||
|
||
func createLastSessionReplay(writeSessionInfo: Bool = true, errorSampleRate: Double = 1) throws { | ||
let replayFolder = SentryDependencyContainer.sharedInstance().fileManager.sentryPath + "/replay" | ||
let jsonPath = replayFolder + "/lastreplay" | ||
|
Oops, something went wrong.