Skip to content

Commit

Permalink
Merge pull request #754 from bugsnag/release-v6.1.1
Browse files Browse the repository at this point in the history
Release v6.1.1
  • Loading branch information
tomlongridge authored Jul 16, 2020
2 parents 2fd7c67 + 43d33eb commit 9251dc0
Show file tree
Hide file tree
Showing 35 changed files with 632 additions and 1,016 deletions.
4 changes: 2 additions & 2 deletions Bugsnag.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Bugsnag",
"version": "6.1.0",
"version": "6.1.1",
"summary": "The Bugsnag crash reporting framework for Apple platforms.",
"homepage": "https://bugsnag.com",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
},
"source": {
"git": "https://github.com/bugsnag/bugsnag-cocoa.git",
"tag": "v6.1.0"
"tag": "v6.1.1"
},
"frameworks": [
"Foundation",
Expand Down
19 changes: 2 additions & 17 deletions Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ typedef void (^BSGBreadcrumbConfiguration)(BugsnagBreadcrumb *_Nonnull);

- (instancetype _Nonnull)initWithConfiguration:(BugsnagConfiguration *_Nonnull)config;

/**
* The maximum number of breadcrumbs. Resizable.
*/
@property(assign, readwrite) NSUInteger capacity;

/** Number of breadcrumbs accumulated */
@property(assign, readonly) NSUInteger count;

/**
* Path where breadcrumbs are persisted on disk
*/
Expand All @@ -43,17 +35,10 @@ typedef void (^BSGBreadcrumbConfiguration)(BugsnagBreadcrumb *_Nonnull);
- (void)addBreadcrumbWithBlock:
(void (^_Nonnull)(BugsnagBreadcrumb *_Nonnull))block;

/** Breadcrumb object for a particular index or nil */
- (BugsnagBreadcrumb *_Nullable)objectAtIndexedSubscript:(NSUInteger)index;

/**
* Serializable array representation of breadcrumbs, represented as nested
* strings in the format:
* [[timestamp,message]...]
*
* returns nil if empty
* Generates an array of dictionaries representing the current buffer of breadcrumbs.
*/
- (NSArray *_Nullable)arrayValue;
- (NSArray *_Nonnull)arrayValue;

/**
* The types of breadcrumbs which will be automatically captured.
Expand Down
90 changes: 21 additions & 69 deletions Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@ @interface BugsnagBreadcrumbs ()

@implementation BugsnagBreadcrumbs

NSUInteger BreadcrumbsDefaultCapacity = 25;

- (instancetype)initWithConfiguration:(BugsnagConfiguration *)config {
static NSString *const BSGBreadcrumbCacheFileName = @"bugsnag_breadcrumbs.json";
if (self = [super init]) {
_config = config;
_breadcrumbs = [NSMutableArray new];
_capacity = BreadcrumbsDefaultCapacity;
_enabledBreadcrumbTypes = BSGEnabledBreadcrumbTypeAll;
_breadcrumbs = [NSMutableArray arrayWithCapacity:config.maxBreadcrumbs];
_readWriteQueue = dispatch_queue_create("com.bugsnag.BreadcrumbRead",
DISPATCH_QUEUE_SERIAL);
NSString *cacheDir = [NSSearchPathForDirectoriesInDomains(
Expand All @@ -59,14 +55,17 @@ - (void)addBreadcrumb:(NSString *)breadcrumbMessage {

- (void)addBreadcrumbWithBlock:
(void (^_Nonnull)(BugsnagBreadcrumb *_Nonnull))block {
if (self.capacity == 0) {
if (self.config.maxBreadcrumbs == 0) {
return;
}
BugsnagBreadcrumb *crumb = [BugsnagBreadcrumb breadcrumbWithBlock:block];

if (crumb != nil && [self shouldSendBreadcrumb:crumb]) {
[self resizeToFitCapacity:self.capacity - 1];
dispatch_barrier_sync(self.readWriteQueue, ^{
if ((self.breadcrumbs.count > 0) &&
(self.breadcrumbs.count == self.config.maxBreadcrumbs)) {
[self.breadcrumbs removeObjectAtIndex:0];
}
[self.breadcrumbs addObject:crumb];
// Serialize crumbs to disk inside barrier to avoid simultaneous
// access to the file
Expand Down Expand Up @@ -116,73 +115,26 @@ - (NSArray *)cachedBreadcrumbs {
return [cache isKindOfClass:[NSArray class]] ? cache : nil;
}

@synthesize capacity = _capacity;

- (NSUInteger)capacity {
@synchronized (self) {
return _capacity;
}
}

- (void)setCapacity:(NSUInteger)capacity {
@synchronized (self) {
if (capacity == _capacity) {
return;
}
[self resizeToFitCapacity:capacity];
[self willChangeValueForKey:NSStringFromSelector(@selector(capacity))];
_capacity = MIN(100, capacity);
[self didChangeValueForKey:NSStringFromSelector(@selector(capacity))];
}
}

- (NSUInteger)count {
return self.breadcrumbs.count;
}

- (BugsnagBreadcrumb *)objectAtIndexedSubscript:(NSUInteger)index {
if (index < [self count]) {
__block BugsnagBreadcrumb *crumb = nil;
dispatch_barrier_sync(self.readWriteQueue, ^{
crumb = self.breadcrumbs[index];
});
return crumb;
}
return nil;
}

- (NSArray *)arrayValue {
if ([self count] == 0) {
return nil;
}
__block NSMutableArray *contents =
[[NSMutableArray alloc] initWithCapacity:[self count]];
__block NSMutableArray *contents;
dispatch_barrier_sync(self.readWriteQueue, ^{
for (BugsnagBreadcrumb *crumb in self.breadcrumbs) {
NSDictionary *objectValue = [crumb objectValue];
NSError *error = nil;
@try {
if (![NSJSONSerialization isValidJSONObject:objectValue]) {
bsg_log_err(@"Unable to serialize breadcrumb: Not a valid "
@"JSON object");
continue;
}
[contents addObject:objectValue];
} @catch (NSException *exception) {
contents = [[NSMutableArray alloc] initWithCapacity:self.breadcrumbs.count];
for (BugsnagBreadcrumb *crumb in self.breadcrumbs) {
NSDictionary *objectValue = [crumb objectValue];
NSError *error = nil;
@try {
if (![NSJSONSerialization isValidJSONObject:objectValue]) {
bsg_log_err(@"Unable to serialize breadcrumb: Not a valid "
@"JSON object");
continue;
}
[contents addObject:objectValue];
} @catch (NSException *exception) {
bsg_log_err(@"Unable to serialize breadcrumb: %@", error);
}
}
}
}
});
return contents;
}

- (void)resizeToFitCapacity:(NSUInteger)capacity {
if ([self count] > capacity) {
dispatch_barrier_sync(self.readWriteQueue, ^{
[self.breadcrumbs
removeObjectsInRange:NSMakeRange(0, self.count - capacity)];
});
}
}

@end
3 changes: 1 addition & 2 deletions Bugsnag/BugsnagCrashSentry.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ - (void)reportUserException:(NSString *)reportName
callbackOverrides:overrides
eventOverrides:eventOverrides
metadata:metadata
config:config
terminateProgram:NO];
config:config];
}

@end
16 changes: 8 additions & 8 deletions Bugsnag/Client/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ @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 All @@ -312,7 +313,6 @@ @interface BugsnagConfiguration ()
@property(readonly, retain, nullable) NSURL *notifyURL;
@property(readwrite, retain, nullable) BugsnagMetadata *metadata;
@property(readwrite, retain, nullable) BugsnagMetadata *config;
@property(readonly, strong, nullable) BugsnagBreadcrumbs *breadcrumbs;
- (BOOL)shouldRecordBreadcrumbType:(BSGBreadcrumbType)type;
@end

Expand Down Expand Up @@ -413,6 +413,8 @@ - (id)initWithConfiguration:(BugsnagConfiguration *)initConfiguration {
BSGWriteSessionCrashData(session);
}];

self.breadcrumbs = [[BugsnagBreadcrumbs alloc] initWithConfiguration:self.configuration];

// Start with a copy of the configuration metadata
self.metadata = [[configuration metadata] deepCopy];
// sync initial state
Expand Down Expand Up @@ -919,7 +921,7 @@ - (void)notifyOutOfMemoryEvent {
static NSString *const BSGOutOfMemoryErrorClass = @"Out Of Memory";
static NSString *const BSGOutOfMemoryMessageFormat = @"The app was likely terminated by the operating system while in the %@";
NSMutableDictionary *lastLaunchInfo = [[self.oomWatchdog lastBootCachedFileInfo] mutableCopy];
NSArray *crumbs = [self.configuration.breadcrumbs cachedBreadcrumbs];
NSArray *crumbs = [self.breadcrumbs cachedBreadcrumbs];
if (crumbs.count > 0) {
lastLaunchInfo[@"breadcrumbs"] = crumbs;
}
Expand Down Expand Up @@ -990,7 +992,7 @@ - (void)notify:(NSException *)exception
handledState:handledState
user:self.user
metadata:metadata
breadcrumbs:[NSArray arrayWithArray:self.configuration.breadcrumbs.breadcrumbs]
breadcrumbs:[NSArray arrayWithArray:self.breadcrumbs.breadcrumbs]
errors:errors
threads:threads
session:self.sessionTracker.runningSession];
Expand Down Expand Up @@ -1086,14 +1088,12 @@ - (BugsnagError *)generateError:(NSException *)exception

- (void)addBreadcrumbWithBlock:
(void (^_Nonnull)(BugsnagBreadcrumb *_Nonnull))block {
[self.configuration.breadcrumbs addBreadcrumbWithBlock:block];
[self.breadcrumbs addBreadcrumbWithBlock:block];
[self serializeBreadcrumbs];
}

- (void)serializeBreadcrumbs {
BugsnagBreadcrumbs *crumbs = self.configuration.breadcrumbs;
NSArray *arrayValue = crumbs.count == 0 ? nil : [crumbs arrayValue];
[self.state addMetadata:arrayValue
[self.state addMetadata:[self.breadcrumbs arrayValue]
withKey:BSGKeyBreadcrumbs
toSection:BSTabCrash];
}
Expand Down Expand Up @@ -1548,7 +1548,7 @@ - (NSDictionary *)collectDeviceWithState {
}

- (NSArray *)collectBreadcrumbs {
NSMutableArray *crumbs = self.configuration.breadcrumbs.breadcrumbs;
NSMutableArray *crumbs = self.breadcrumbs.breadcrumbs;
NSMutableArray *data = [NSMutableArray new];

for (BugsnagBreadcrumb *crumb in crumbs) {
Expand Down
40 changes: 24 additions & 16 deletions Bugsnag/Configuration/BugsnagConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ @interface BugsnagConfiguration ()
* Meta-information about the state of Bugsnag
*/
@property(readwrite, retain, nullable) BugsnagMetadata *config;

/**
* Rolling snapshots of user actions leading up to a crash report
*/
@property(readonly, strong, nullable) BugsnagBreadcrumbs *breadcrumbs;
@end

// =============================================================================
Expand Down Expand Up @@ -122,7 +117,6 @@ - (nonnull id)copyWithZone:(nullable NSZone *)zone {
[copy setAutoDetectErrors:self.autoDetectErrors];
[copy setAutoTrackSessions:self.autoTrackSessions];
[copy setBundleVersion:self.bundleVersion];
// Skip breadcrumbs - none should have been set
[copy setConfig:[[BugsnagMetadata alloc] initWithDictionary:[[self.config toDictionary] mutableCopy]]];
[copy setContext:self.context];
[copy setEnabledBreadcrumbTypes:self.enabledBreadcrumbTypes];
Expand Down Expand Up @@ -220,7 +214,8 @@ - (instancetype _Nonnull)initWithApiKey:(NSString *_Nonnull)apiKey
_plugins = [NSMutableSet new];
_enabledReleaseStages = nil;
_redactedKeys = [NSSet setWithArray:@[@"password"]];
_breadcrumbs = [[BugsnagBreadcrumbs alloc] initWithConfiguration:self];
_enabledBreadcrumbTypes = BSGEnabledBreadcrumbTypeAll;
_maxBreadcrumbs = 25;
_autoTrackSessions = YES;
_sendThreads = BSGThreadSendPolicyAlways;
// Default to recording all error types
Expand Down Expand Up @@ -455,16 +450,23 @@ -(void)deletePersistedUserData {
// MARK: - Properties: Getters and Setters
// -----------------------------------------------------------------------------

@synthesize maxBreadcrumbs = _maxBreadcrumbs;

- (NSUInteger)maxBreadcrumbs {
return self.breadcrumbs.capacity;
@synchronized (self) {
return _maxBreadcrumbs;
}
}

- (void)setMaxBreadcrumbs:(NSUInteger)capacity {
if (capacity <= 100) {
self.breadcrumbs.capacity = capacity;
} else {
bsg_log_err(@"Invalid configuration value detected. Option maxBreadcrumbs "
"should be an integer between 0-100. Supplied value is %lu", (unsigned long) capacity);
- (void)setMaxBreadcrumbs:(NSUInteger)maxBreadcrumbs {
@synchronized (self) {
if (maxBreadcrumbs <= 100) {
_maxBreadcrumbs = maxBreadcrumbs;
} else {
bsg_log_err(@"Invalid configuration value detected. Option maxBreadcrumbs "
"should be an integer between 0-100. Supplied value is %lu",
(unsigned long) maxBreadcrumbs);
}
}
}

Expand Down Expand Up @@ -547,12 +549,18 @@ - (void)setEnabledReleaseStages:(NSSet<NSString *> *)newReleaseStages

// MARK: - enabledBreadcrumbTypes

@synthesize enabledBreadcrumbTypes = _enabledBreadcrumbTypes;

- (BSGEnabledBreadcrumbType)enabledBreadcrumbTypes {
return self.breadcrumbs.enabledBreadcrumbTypes;
@synchronized (self) {
return _enabledBreadcrumbTypes;
}
}

- (void)setEnabledBreadcrumbTypes:(BSGEnabledBreadcrumbType)enabledBreadcrumbTypes {
self.breadcrumbs.enabledBreadcrumbTypes = enabledBreadcrumbTypes;
@synchronized (self) {
_enabledBreadcrumbTypes = enabledBreadcrumbTypes;
}
}

// MARK: -
Expand Down
16 changes: 3 additions & 13 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@
* @param eventOverrides the Bugsnag Error Payload, for handled errors only
* @param metadata additional information to attach to the report
* @param config delivery options
* @param terminateProgram If true, do not return from this function call.
* Terminate the program instead.
*/
- (void)reportUserException:(NSString *)name
reason:(NSString *)reason
Expand All @@ -109,8 +107,7 @@
callbackOverrides:(NSDictionary *)overrides
eventOverrides:(NSDictionary *)eventOverrides
metadata:(NSDictionary *)metadata
config:(NSDictionary *)config
terminateProgram:(BOOL)terminateProgram;
config:(NSDictionary *)config;

/**
* Collects a trace of all the threads running in application, if the user has
Expand All @@ -122,22 +119,15 @@
*/
- (NSArray<BugsnagThread *> *)captureThreads:(NSException *)exc depth:(int)depth;

/** If YES, user reported exceptions will suspend all threads during report
* generation. All threads will be suspended while generating a crash report for
* a user reported exception.
*
* Default: YES
*/
@property(nonatomic, readwrite, assign) BOOL suspendThreadsForUserReported;

/** If YES, reports will be sent even if a debugger is attached
*
* Default: NO
*/
@property(nonatomic, readwrite, assign) BOOL reportWhenDebuggerIsAttached;

/**
* If YES, thread traces will be collected with each report.
* The methodology used for tracing threads.
* The value will be equal to an enum value from BSGThreadSendPolicy
*/
@property(nonatomic, readwrite, assign) int threadTracingEnabled;

Expand Down
Loading

0 comments on commit 9251dc0

Please sign in to comment.