Skip to content

Commit

Permalink
[PLAT-8476] Allow internal error reporting to be disabled (#1375)
Browse files Browse the repository at this point in the history
* Add BSGTelemetryOptions
* Only create internal error reporter if enabled
  • Loading branch information
nickdowell committed May 18, 2022
1 parent 96f738f commit adb01d0
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 9 deletions.
8 changes: 6 additions & 2 deletions Bugsnag/Client/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,17 @@ - (instancetype)initWithConfiguration:(BugsnagConfiguration *)configuration {
NSDictionary *systemInfo = [BSG_KSSystemInfo systemInfo];
[self.metadata addMetadata:BSGParseAppMetadata(@{@"system": systemInfo}) toSection:BSGKeyApp];
[self.metadata addMetadata:BSGParseDeviceMetadata(@{@"system": systemInfo}) toSection:BSGKeyDevice];

BSGInternalErrorReporter.sharedInstance = [[BSGInternalErrorReporter alloc] initWithDataSource:self];
}
return self;
}

- (void)start {
if (self.configuration.telemetry & BSGTelemetryInternalErrors) {
BSGInternalErrorReporter.sharedInstance = [[BSGInternalErrorReporter alloc] initWithDataSource:self];
} else {
bsg_log_debug(@"Internal error reporting was disable in config");
}

[self.configuration validate];

BSGRunContextInit(BSGFileLocations.current.runContext.fileSystemRepresentation);
Expand Down
3 changes: 3 additions & 0 deletions Bugsnag/Configuration/BugsnagConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ - (nonnull id)copyWithZone:(nullable __attribute__((unused)) NSZone *)zone {
[copy setOnBreadcrumbBlocks:self.onBreadcrumbBlocks];
[copy setOnSendBlocks:self.onSendBlocks];
[copy setOnSessionBlocks:self.onSessionBlocks];
[copy setTelemetry:self.telemetry];
return copy;
}

Expand Down Expand Up @@ -202,6 +203,8 @@ - (instancetype)initWithApiKey:(NSString *)apiKey {
defaultSessionConfiguration]];
}

_telemetry = BSGTelemetryInternalErrors;

NSString *releaseStage = nil;
#if DEBUG
releaseStage = BSGKeyDevelopment;
Expand Down
6 changes: 4 additions & 2 deletions Bugsnag/Helpers/BSGInternalErrorReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import <Foundation/Foundation.h>

#import "BSGDefines.h"

@class BugsnagAppWithState;
@class BugsnagConfiguration;
@class BugsnagDeviceWithState;
Expand All @@ -17,7 +19,7 @@
NS_ASSUME_NONNULL_BEGIN

/// Returns a concise desription of the error including its domain, code, and debug description or localizedDescription.
FOUNDATION_EXPORT NSString *BSGErrorDescription(NSError *error);
BSG_PRIVATE NSString *BSGErrorDescription(NSError *error);

// MARK: -

Expand All @@ -35,7 +37,7 @@ FOUNDATION_EXPORT NSString *BSGErrorDescription(NSError *error);

@interface BSGInternalErrorReporter : NSObject

@property (class, nonatomic) BSGInternalErrorReporter *sharedInstance;
@property (class, nullable, nonatomic) BSGInternalErrorReporter *sharedInstance;

/// Runs the block immediately if sharedInstance exists, otherwise runs the block once sharedInstance has been created.
+ (void)performBlock:(void (^)(BSGInternalErrorReporter *))block;
Expand Down
26 changes: 22 additions & 4 deletions Bugsnag/include/Bugsnag/BugsnagConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ typedef NS_ENUM(NSInteger, BSGThreadSendPolicy) {
BSGThreadSendPolicyNever = 2
};

/**
* Types of telemetry that may be sent to Bugsnag for product improvement purposes.
*/
typedef NS_OPTIONS(NSUInteger, BSGTelemetryOptions) {

/**
* Errors within the Bugsnag SDK.
*/
BSGTelemetryInternalErrors = (1UL << 0),
};

/**
* Setting `BugsnagConfiguration.appHangThresholdMillis` to this value disables the reporting of
* app hangs that ended before the app was terminated.
Expand Down Expand Up @@ -315,10 +326,6 @@ typedef id<NSObject> BugsnagOnSessionRef;
*/
@property (nonatomic) BOOL persistUser;

// -----------------------------------------------------------------------------
// MARK: - Methods
// -----------------------------------------------------------------------------

/**
* A class defining the types of error that are reported. By default,
* all properties are true.
Expand Down Expand Up @@ -445,6 +452,17 @@ typedef id<NSObject> BugsnagOnSessionRef;
BSG_DEPRECATED_WITH_REPLACEMENT("removeOnBreadcrumb:")
NS_SWIFT_NAME(removeOnBreadcrumb(block:));

// =============================================================================
// MARK: - Telemetry
// =============================================================================

/**
* The types of telemetry that may be sent to Bugsnag for product improvement purposes.
*
* By default all types of telemetry are enabled.
*/
@property (nonatomic) BSGTelemetryOptions telemetry;

// =============================================================================
// MARK: - Plugins
// =============================================================================
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## TBD

### Enhancements

* Add `configuration.telemetry` to allow sending of internal errors to be disabled.
[#1375](https://github.com/bugsnag/bugsnag-cocoa/pull/1375)

## 6.17.1 (2022-05-18)

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ @implementation InvalidCrashReportScenario
- (void)startBugsnag {
self.config.autoTrackSessions = NO;
self.config.onCrashHandler = CrashHandler;

if ([self.eventMode isEqualToString:@"internalErrorsDisabled"]) {
self.config.telemetry &= ~BSGTelemetryInternalErrors;
}
[super startBugsnag];
}

Expand Down
6 changes: 6 additions & 0 deletions features/internal_error_reporting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ Feature: Internal error reporting
And the event "unhandled" is false
And the exception "errorClass" equals "JSON parsing error"
And the exception "message" matches "NSCocoaErrorDomain 3840: No string key for value in object around .+\."

Scenario: Internal errors are not sent if disabled
When I run "InvalidCrashReportScenario" and relaunch the crashed app
And I set the app to "internalErrorsDisabled" mode
And I configure Bugsnag for "InvalidCrashReportScenario"
Then I should receive no requests

0 comments on commit adb01d0

Please sign in to comment.