Skip to content

Commit

Permalink
feat(replay): Expose ignore and redact classes to hybrid SDKs (#3891)
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich committed Apr 25, 2024
1 parent 0cc5400 commit d6ff82c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
31 changes: 31 additions & 0 deletions Sources/Sentry/PrivateSentrySDKOnly.mm
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,35 @@ + (NSString *__nullable)getReplayId
return replayId;
}

+ (void)addReplayIgnoreClasses:(NSArray<Class> *_Nonnull)classes
{
#if SENTRY_HAS_UIKIT && !TARGET_OS_VISION
if (@available(iOS 16.0, tvOS 16.0, *)) {
[SentryViewPhotographer.shared addIgnoreClasses:classes];
} else {
SENTRY_LOG_DEBUG(@"PrivateSentrySDKOnly.addIgnoreClasses only works with iOS 16 and newer");
}
#else
SENTRY_LOG_DEBUG(
@"PrivateSentrySDKOnly.addReplayIgnoreClasses only works with UIKit enabled and target is "
@"not visionOS. Ensure you're using the right configuration of Sentry that links UIKit.");
#endif
}

+ (void)addReplayRedactClasses:(NSArray<Class> *_Nonnull)classes
{
#if SENTRY_HAS_UIKIT && !TARGET_OS_VISION
if (@available(iOS 16.0, tvOS 16.0, *)) {
[SentryViewPhotographer.shared addRedactClasses:classes];
} else {
SENTRY_LOG_DEBUG(
@"PrivateSentrySDKOnly.addReplayRedactClasses only works with iOS 16 and newer");
}
#else
SENTRY_LOG_DEBUG(
@"PrivateSentrySDKOnly.addReplayRedactClasses only works with UIKit enabled and target is "
@"not visionOS. Ensure you're using the right configuration of Sentry that links UIKit.");
#endif
}

@end
2 changes: 2 additions & 0 deletions Sources/Sentry/include/HybridPublic/PrivateSentrySDKOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ typedef void (^SentryOnAppStartMeasurementAvailable)(

+ (void)captureReplay;
+ (NSString *__nullable)getReplayId;
+ (void)addReplayIgnoreClasses:(NSArray<Class> *_Nonnull)classes;
+ (void)addReplayRedactClasses:(NSArray<Class> *_Nonnull)classes;

@end

Expand Down
12 changes: 11 additions & 1 deletion Sources/Swift/Tools/SentryViewPhotographer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ class SentryViewPhotographer: NSObject {
guard let screenshot = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
return screenshot
}


@objc(addIgnoreClasses:)
func addIgnoreClasses(classes: [AnyClass]) {
ignoreClasses += classes
}

@objc(addRedactClasses:)
func addRedactClasses(classes: [AnyClass]) {
redactClasses += classes
}

private func mask(view: UIView, context: CGContext, options: SentryRedactOptions?) {
UIColor.black.setFill()
let maskPath = self.buildPath(view: view,
Expand Down
24 changes: 24 additions & 0 deletions Tests/SentryTests/PrivateSentrySDKOnlyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
PrivateSentrySDKOnly.captureReplay()
}

func testAddReplayIgnoreClassesShouldNotFailIfMissingReplayIntegration() {
PrivateSentrySDKOnly.addReplayIgnoreClasses([])
}

func testAddReplayRedactShouldNotFailIfMissingReplayIntegration() {
PrivateSentrySDKOnly.addReplayRedactClasses([])
}

#if canImport(UIKit)
func testCaptureReplayShouldCallReplayIntegration() {
guard #available(iOS 16.0, tvOS 16.0, *) else { return }
Expand All @@ -235,6 +243,22 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
XCTAssertEqual(PrivateSentrySDKOnly.getReplayId(), VALID_REPLAY_ID)
}

func testAddReplayIgnoreClassesShouldNotFailWhenReplayIsAvailable() {
let options = Options()
options.setIntegrations([SentrySessionReplayIntegrationTest.self])
SentrySDK.start(options: options)

PrivateSentrySDKOnly.addReplayIgnoreClasses([UILabel.self])
}

func testAddReplayRedactShouldNotFailWhenReplayIsAvailable() {
let options = Options()
options.setIntegrations([SentrySessionReplayIntegrationTest.self])
SentrySDK.start(options: options)

PrivateSentrySDKOnly.addReplayRedactClasses([UILabel.self])
}

let VALID_REPLAY_ID = "0eac7ab503354dd5819b03e263627a29"

final class SentrySessionReplayIntegrationTest: SentrySessionReplayIntegration {
Expand Down

0 comments on commit d6ff82c

Please sign in to comment.