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

[PLAT-4827] Add +[Bugsnag breadcrumbs] #813

Merged
merged 2 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ typedef void (^BSGBreadcrumbConfiguration)(BugsnagBreadcrumb *_Nonnull);
*/
- (NSArray *_Nonnull)arrayValue;

/**
* Returns an array containing the current buffer of breadcrumbs.
*/
- (NSArray<BugsnagBreadcrumb *> *_Nonnull)getBreadcrumbs;

/**
* The types of breadcrumbs which will be automatically captured.
* By default, this is all types.
Expand Down
8 changes: 8 additions & 0 deletions Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,12 @@ - (NSArray *)arrayValue {
return contents;
}

- (NSArray<BugsnagBreadcrumb *> *)getBreadcrumbs {
__block NSArray *result = nil;
dispatch_barrier_sync(self.readWriteQueue, ^{
result = [NSArray arrayWithArray:self.breadcrumbs];
});
return result;
}

@end
10 changes: 10 additions & 0 deletions Bugsnag/Bugsnag.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
//

#import "Bugsnag.h"

#import "BSG_KSCrash.h"
#import "BugsnagBreadcrumbs.h"
#import "BugsnagLogger.h"
#import "BugsnagClient.h"
#import "BugsnagClientInternal.h"
Expand Down Expand Up @@ -190,6 +192,14 @@ + (void)leaveBreadcrumbWithMessage:(NSString *_Nonnull)message
}
}

+ (NSArray<BugsnagBreadcrumb *> *_Nonnull)breadcrumbs {
if ([self bugsnagStarted]) {
return [self.client.breadcrumbs getBreadcrumbs];
} else {
return @[];
}
}

+ (void)startSession {
if ([self bugsnagStarted]) {
[self.client startSession];
Expand Down
1 change: 0 additions & 1 deletion Bugsnag/Client/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ @interface BugsnagClient ()
@property (nonatomic, strong) BugsnagPluginClient *pluginClient;
@property (nonatomic) BOOL appDidCrashLastLaunch;
@property (nonatomic, strong) BugsnagMetadata *metadata;
@property(nonatomic, strong) BugsnagBreadcrumbs *breadcrumbs;
@property (nonatomic) NSString *codeBundleId;
@property(nonatomic, readwrite, strong) NSMutableArray *stateEventBlocks;
#if BSG_PLATFORM_IOS
Expand Down
2 changes: 2 additions & 0 deletions Bugsnag/Client/BugsnagClientInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#import "BugsnagClient.h"

@class BugsnagBreadcrumbs;
@class BugsnagClient;
@class BugsnagSessionTracker;
@class BugsnagConfiguration;
Expand All @@ -18,6 +19,7 @@

@interface BugsnagClient ()

@property(nonatomic, readwrite, retain) BugsnagBreadcrumbs *_Nullable breadcrumbs;
@property(nonatomic, readwrite, retain) BugsnagConfiguration *_Nullable configuration;
@property(nonatomic, readwrite, strong) BugsnagMetadata *_Nonnull state;
@property(nonatomic, readwrite, strong) BugsnagNotifier *_Nonnull notifier;
Expand Down
7 changes: 7 additions & 0 deletions Bugsnag/include/Bugsnag/Bugsnag.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@
andType:(BSGBreadcrumbType)type
NS_SWIFT_NAME(leaveBreadcrumb(_:metadata:type:));

/**
* Returns the current buffer of breadcrumbs that will be sent with captured events. This
* ordered list represents the most recent breadcrumbs to be captured up to the limit
* set in `BugsnagConfiguration.maxBreadcrumbs`
*/
+ (NSArray<BugsnagBreadcrumb *> *_Nonnull)breadcrumbs;

// =============================================================================
// MARK: - Session
// =============================================================================
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog

### Enhancements

* Add `+[Bugsnag breadcrumbs]` to allow apps to fetch the list of breadcrumbs.
[813](https://github.com/bugsnag/bugsnag-cocoa/pull/813)

* Disable JSON pretty-printing in KSCrash reports to save disk space and bandwidth.
[802](https://github.com/bugsnag/bugsnag-cocoa/pull/802)

Expand Down
11 changes: 10 additions & 1 deletion Tests/BugsnagBreadcrumbsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ + (BugsnagClient *)client;

@interface BugsnagClient ()
- (void)start;
@property(readonly, strong, nullable) BugsnagBreadcrumbs *breadcrumbs;
@end

void awaitBreadcrumbSync(BugsnagBreadcrumbs *crumbs) {
Expand Down Expand Up @@ -402,4 +401,14 @@ - (void)testCallbackFreeConstructors3 {
XCTAssertEqual([bc2[@"metaData"] count], 0);
}

- (void)testGetBreadcrumbs {
NSArray<BugsnagBreadcrumb *> *breadcrumbs = [self.crumbs getBreadcrumbs];
XCTAssertEqual(breadcrumbs[0].message, @"Launch app");
XCTAssertEqual(breadcrumbs[0].type, BSGBreadcrumbTypeManual);
XCTAssertEqual(breadcrumbs[1].message, @"Tap button");
XCTAssertEqual(breadcrumbs[1].type, BSGBreadcrumbTypeManual);
XCTAssertEqual(breadcrumbs[2].message, @"Close tutorial");
XCTAssertEqual(breadcrumbs[2].type, BSGBreadcrumbTypeManual);
}

@end
1 change: 0 additions & 1 deletion Tests/BugsnagClientTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ + (BugsnagClient *)client;
@interface BugsnagClient ()
- (void)orientationChanged:(NSNotification *)notif;
@property (nonatomic, strong) BugsnagMetadata *metadata;
@property(nonatomic, strong) BugsnagBreadcrumbs *breadcrumbs;
@end

@interface BugsnagBreadcrumb ()
Expand Down