From adb01d032bcf26a65c453f2a98bff1dfabe7e5db Mon Sep 17 00:00:00 2001 From: Nick Dowell Date: Wed, 18 May 2022 14:55:34 +0100 Subject: [PATCH] [PLAT-8476] Allow internal error reporting to be disabled (#1375) * Add BSGTelemetryOptions * Only create internal error reporter if enabled --- Bugsnag/Client/BugsnagClient.m | 8 ++++-- Bugsnag/Configuration/BugsnagConfiguration.m | 3 +++ Bugsnag/Helpers/BSGInternalErrorReporter.h | 6 +++-- .../include/Bugsnag/BugsnagConfiguration.h | 26 ++++++++++++++++--- CHANGELOG.md | 7 +++++ .../scenarios/InvalidCrashReportScenario.m | 4 ++- features/internal_error_reporting.feature | 6 +++++ 7 files changed, 51 insertions(+), 9 deletions(-) diff --git a/Bugsnag/Client/BugsnagClient.m b/Bugsnag/Client/BugsnagClient.m index a201b6465..57fc23e57 100644 --- a/Bugsnag/Client/BugsnagClient.m +++ b/Bugsnag/Client/BugsnagClient.m @@ -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); diff --git a/Bugsnag/Configuration/BugsnagConfiguration.m b/Bugsnag/Configuration/BugsnagConfiguration.m index fbd008097..d5582f427 100644 --- a/Bugsnag/Configuration/BugsnagConfiguration.m +++ b/Bugsnag/Configuration/BugsnagConfiguration.m @@ -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; } @@ -202,6 +203,8 @@ - (instancetype)initWithApiKey:(NSString *)apiKey { defaultSessionConfiguration]]; } + _telemetry = BSGTelemetryInternalErrors; + NSString *releaseStage = nil; #if DEBUG releaseStage = BSGKeyDevelopment; diff --git a/Bugsnag/Helpers/BSGInternalErrorReporter.h b/Bugsnag/Helpers/BSGInternalErrorReporter.h index 7fe456523..bb1d8a796 100644 --- a/Bugsnag/Helpers/BSGInternalErrorReporter.h +++ b/Bugsnag/Helpers/BSGInternalErrorReporter.h @@ -8,6 +8,8 @@ #import +#import "BSGDefines.h" + @class BugsnagAppWithState; @class BugsnagConfiguration; @class BugsnagDeviceWithState; @@ -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: - @@ -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; diff --git a/Bugsnag/include/Bugsnag/BugsnagConfiguration.h b/Bugsnag/include/Bugsnag/BugsnagConfiguration.h index 7198919c4..4da54448d 100644 --- a/Bugsnag/include/Bugsnag/BugsnagConfiguration.h +++ b/Bugsnag/include/Bugsnag/BugsnagConfiguration.h @@ -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. @@ -315,10 +326,6 @@ typedef id BugsnagOnSessionRef; */ @property (nonatomic) BOOL persistUser; -// ----------------------------------------------------------------------------- -// MARK: - Methods -// ----------------------------------------------------------------------------- - /** * A class defining the types of error that are reported. By default, * all properties are true. @@ -445,6 +452,17 @@ typedef id 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 // ============================================================================= diff --git a/CHANGELOG.md b/CHANGELOG.md index dd0b1a682..b1fcf4ae4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/features/fixtures/shared/scenarios/InvalidCrashReportScenario.m b/features/fixtures/shared/scenarios/InvalidCrashReportScenario.m index 9008d94a6..f8719868a 100644 --- a/features/fixtures/shared/scenarios/InvalidCrashReportScenario.m +++ b/features/fixtures/shared/scenarios/InvalidCrashReportScenario.m @@ -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]; } diff --git a/features/internal_error_reporting.feature b/features/internal_error_reporting.feature index 25dc75eb5..db521a317 100644 --- a/features/internal_error_reporting.feature +++ b/features/internal_error_reporting.feature @@ -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