Skip to content

Commit

Permalink
ref: report viewDidAppear breadcrumbs via delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed Aug 18, 2023
1 parent 01a28a9 commit c0f1495
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
17 changes: 7 additions & 10 deletions Sources/Sentry/SentryBreadcrumbTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#import "SentryDefines.h"
#import "SentryHub.h"
#import "SentryLog.h"
#import "SentrySDK+Private.h"
#import "SentryScope.h"
#import "SentrySwift.h"
#import "SentrySwizzle.h"
Expand Down Expand Up @@ -201,17 +200,15 @@ - (void)swizzleViewDidAppear

static const void *swizzleViewDidAppearKey = &swizzleViewDidAppearKey;
SEL selector = NSSelectorFromString(@"viewDidAppear:");
__weak id<SentryBreadcrumbDelegate> delegate = self.delegate;
SentrySwizzleInstanceMethod(UIViewController.class, selector, SentrySWReturnType(void),
SentrySWArguments(BOOL animated), SentrySWReplacement({
if (nil != [SentrySDK.currentHub getClient]) {
SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc] initWithLevel:kSentryLevelInfo
category:@"ui.lifecycle"];
crumb.type = @"navigation";
crumb.data = [SentryBreadcrumbTracker fetchInfoAboutViewController:self];

// Adding crumb via the SDK calls SentryBeforeBreadcrumbCallback
[SentrySDK addBreadcrumb:crumb];
}
SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc] initWithLevel:kSentryLevelInfo
category:@"ui.lifecycle"];
crumb.type = @"navigation";
crumb.data = [SentryBreadcrumbTracker fetchInfoAboutViewController:self];
[delegate addBreadcrumb:crumb];

SentrySWCallOriginal(animated);
}),
SentrySwizzleModeOncePerClassAndSuperclasses, swizzleViewDidAppearKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,19 @@ class SentryBreadcrumbTrackerTests: XCTestCase {
viewController.title = "test title"
viewController.viewDidAppear(false)

let crumbs = Dynamic(scope).breadcrumbArray.asArray as? [Breadcrumb]
let crumbs = delegate.addCrumbInvocations.invocations

XCTAssertEqual(1, crumbs?.count)
// one breadcrumb for starting the tracker, and a second one for the swizzled viewDidAppear
XCTAssertEqual(2, crumbs.count)

let lifeCycleCrumb = crumbs?[0]
XCTAssertEqual("navigation", lifeCycleCrumb?.type)
XCTAssertEqual("ui.lifecycle", lifeCycleCrumb?.category)
XCTAssertEqual("false", lifeCycleCrumb?.data?["beingPresented"] as? String)
XCTAssertEqual("UIViewController", lifeCycleCrumb?.data?["screen"] as? String)
XCTAssertEqual("test title", lifeCycleCrumb?.data?["title"] as? String)
XCTAssertEqual("false", lifeCycleCrumb?.data?["beingPresented"] as? String)
XCTAssertEqual("UINavigationController", lifeCycleCrumb?.data?["parentViewController"] as? String)
let lifeCycleCrumb = crumbs[1]
XCTAssertEqual("navigation", lifeCycleCrumb.type)
XCTAssertEqual("ui.lifecycle", lifeCycleCrumb.category)
XCTAssertEqual("false", lifeCycleCrumb.data?["beingPresented"] as? String)
XCTAssertEqual("UIViewController", lifeCycleCrumb.data?["screen"] as? String)
XCTAssertEqual("test title", lifeCycleCrumb.data?["title"] as? String)
XCTAssertEqual("false", lifeCycleCrumb.data?["beingPresented"] as? String)
XCTAssertEqual("UINavigationController", lifeCycleCrumb.data?["parentViewController"] as? String)

clearTestState()
}
Expand Down

0 comments on commit c0f1495

Please sign in to comment.