Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Skip UI crumbs when target or sender is nil #4211

Merged
merged 2 commits into from
Aug 1, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Replay for crashes (#4171)
- Redact web view from replay (#4203)

### Fixes

- Skip UI crumbs when target or sender is nil (#4211)

## 8.32.0

### Features
Expand Down
4 changes: 4 additions & 0 deletions Sources/Sentry/SentryBreadcrumbTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ - (void)addEnabledCrumb
#if SENTRY_HAS_UIKIT
+ (BOOL)avoidSender:(id)sender forTarget:(id)target action:(NSString *)action
{
if (sender == nil || target == nil) {
return YES;
}

if ([sender isKindOfClass:UITextField.self]) {
// This is required to avoid creating breadcrumbs for every key pressed in a text field.
// Textfield may invoke many types of event, in order to check if is a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ class SentryBreadcrumbTrackerTests: XCTestCase {
XCTAssertEqual(eventPayload?["category"] as? String, "app.background")
}

func testSkipCrumbs_WhenSenderOrTargetIsNil() throws {
let swizzlingWrapper = TestSentrySwizzleWrapper()
SentryDependencyContainer.sharedInstance().swizzleWrapper = swizzlingWrapper

let tracker = SentryBreadcrumbTracker()
tracker.start(with: delegate)
tracker.startSwizzle()

swizzlingWrapper.execute(action: "methodPressed:", target: nil, sender: self, event: nil)
swizzlingWrapper.execute(action: "methodPressed:", target: self, sender: nil, event: nil)

// The tracker adds 1 enabled crumb when being started
XCTAssertEqual(1, delegate.addCrumbInvocations.invocations.count)
}

func testTouchBreadcrumbForSessionReplay() throws {
let scope = Scope()
let client = TestClient(options: Options())
Expand Down
Loading