From 6bf1ecbf80cd36315c5d0bbe472296e4f9e83d1e Mon Sep 17 00:00:00 2001 From: Delisa Date: Fri, 24 Jan 2020 09:31:32 +0000 Subject: [PATCH] feat: Add a breadcrumb when the library starts (#445) --- CHANGELOG.md | 5 +++-- Source/BugsnagNotifier.m | 6 ++++++ features/breadcrumbs.feature | 15 +++++++++++++++ features/steps/ios_steps.rb | 9 +++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 features/breadcrumbs.feature diff --git a/CHANGELOG.md b/CHANGELOG.md index 9564221b9..cc5fb982f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,11 +15,12 @@ Bugsnag Notifiers on other platforms. * Swift: `try BugsnagConfiguration(_ apiKey)` * Objective C: `[[BugsnagConfiguration alloc] initWithApiKey:error:]` -[#446](https://github.com/bugsnag/bugsnag-cocoa/pull/446) + [#446](https://github.com/bugsnag/bugsnag-cocoa/pull/446) ### Enhancements -TBD +* Add a breadcrumb when Bugsnag first starts with the message "Bugsnag loaded" + [#445](https://github.com/bugsnag/bugsnag-cocoa/pull/445) ## Bug fixes diff --git a/Source/BugsnagNotifier.m b/Source/BugsnagNotifier.m index af1c28aa2..6e3bf9e91 100644 --- a/Source/BugsnagNotifier.m +++ b/Source/BugsnagNotifier.m @@ -280,6 +280,7 @@ - (id)initWithConfiguration:(BugsnagConfiguration *)initConfiguration { NSString *const kRedoOperation = @"Redo Operation"; NSString *const kTableViewSelectionChange = @"TableView Select Change"; NSString *const kAppWillTerminate = @"App Will Terminate"; +NSString *const BSGBreadcrumbLoadedMessage = @"Bugsnag loaded"; - (void)initializeNotificationNameMap { notificationNameMap = @{ @@ -411,6 +412,11 @@ - (void)start { [self.sessionTracker startNewSessionIfAutoCaptureEnabled]; + [self addBreadcrumbWithBlock:^(BugsnagBreadcrumb *_Nonnull breadcrumb) { + breadcrumb.type = BSGBreadcrumbTypeState; + breadcrumb.name = BSGBreadcrumbLoadedMessage; + }]; + // notification not received in time on initial startup, so trigger manually [self willEnterForeground:self]; } diff --git a/features/breadcrumbs.feature b/features/breadcrumbs.feature new file mode 100644 index 000000000..a821f4515 --- /dev/null +++ b/features/breadcrumbs.feature @@ -0,0 +1,15 @@ +Feature: Attaching a series of notable events leading up to errors + A breadcrumb contains supplementary data which will be sent along with + events. Breadcrumbs are intended to be pieces of information which can + lead the developer to the cause of the event being reported. + + Scenario: An app lauches and subsequently sends a manual event using notify() + When I run "HandledErrorScenario" + And I wait for a request + Then the event breadcrumbs contain "Bugsnag loaded" with type "state" + + Scenario: An app lauches and subsequently crahes + When I crash the app using "BuiltinTrapScenario" + And I relaunch the app + And I wait for a request + Then the event breadcrumbs contain "Bugsnag loaded" with type "state" diff --git a/features/steps/ios_steps.rb b/features/steps/ios_steps.rb index 237eb564d..e65509f20 100644 --- a/features/steps/ios_steps.rb +++ b/features/steps/ios_steps.rb @@ -98,6 +98,15 @@ assert_true(delta.abs < threshold_secs, "Expected current timestamp, but received #{value}") end +Then("the event breadcrumbs contain {string} with type {string}") do |string, type| + crumbs = read_key_path(find_request(0)[:body], "events.0.breadcrumbs") + assert_not_equal(0, crumbs.length, "There are no breadcrumbs on this event") + match = crumbs.detect do |crumb| + crumb["name"] == string && crumb["type"] == type + end + assert_not_nil(match, "No crumb matches the provided message and type") +end + Then("the event breadcrumbs contain {string}") do |string| crumbs = read_key_path(find_request(0)[:body], "events.0.breadcrumbs") assert_not_equal(0, crumbs.length, "There are no breadcrumbs on this event")