Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
static NSString *const DFK_PERSON = @"person";
static NSString *const DFK_NOTIFIER = @"notifier";
static NSString *const DFK_TELEMETRY = @"telemetry";
static NSString *const DFK_CRASH_REPORTING_ENABLED = @"crashReportingEnabled";
static NSString *const DFK_CUSTOM = @"custom";

#pragma mark - class implementation
Expand Down Expand Up @@ -128,6 +129,7 @@ - (instancetype)initWithAccessToken:(nullable NSString *)token
DFK_HTTPS_PROXY : [RollbarProxy new].jsonFriendlyData,
DFK_DATA_SCRUBBER : [RollbarScrubbingOptions new].jsonFriendlyData,
DFK_TELEMETRY : [RollbarTelemetryOptions new].jsonFriendlyData,
DFK_CRASH_REPORTING_ENABLED : [NSNumber numberWithBool:YES],
DFK_NOTIFIER : [[RollbarModule alloc] initWithName:NOTIFIER_NAME
version:NOTIFIER_VERSION]
.jsonFriendlyData,
Expand All @@ -152,6 +154,7 @@ - (instancetype)init {
DFK_HTTPS_PROXY : [RollbarProxy new].jsonFriendlyData,
DFK_DATA_SCRUBBER : [RollbarScrubbingOptions new].jsonFriendlyData,
DFK_TELEMETRY : [RollbarTelemetryOptions new].jsonFriendlyData,
DFK_CRASH_REPORTING_ENABLED : [NSNumber numberWithBool:YES],
DFK_NOTIFIER : [[RollbarModule alloc] initWithName:NOTIFIER_NAME
version:NOTIFIER_VERSION]
.jsonFriendlyData,
Expand Down Expand Up @@ -233,6 +236,13 @@ - (RollbarTelemetryOptions *)telemetry {
return [[RollbarTelemetryOptions alloc] initWithDictionary:data];
}

#pragma mark - Crash reporting

- (BOOL)isCrashReportingEnabled {
NSNumber *result = [self safelyGetNumberByKey:DFK_CRASH_REPORTING_ENABLED];
return result ? [result boolValue] : YES;
}

#pragma mark - Custom data

- (NSDictionary<NSString *, id> *)customData {
Expand Down Expand Up @@ -303,6 +313,7 @@ - (instancetype)init {

@dynamic checkIgnoreRollbarData;
@dynamic modifyRollbarData;
@dynamic isCrashReportingEnabled;

- (void)setCheckIgnoreRollbarData:
(BOOL (^)(RollbarData *_Nonnull))checkIgnoreRollbarData {
Expand Down Expand Up @@ -427,6 +438,13 @@ - (void)setTelemetry:(RollbarTelemetryOptions *)value {
[self setDataTransferObject:[value mutableCopy] forKey:DFK_TELEMETRY];
}

#pragma mark - Crash reporting

- (void)setIsCrashReportingEnabled:(BOOL)value {
[self setNumber:[NSNumber numberWithBool:value]
forKey:DFK_CRASH_REPORTING_ENABLED];
}

#pragma mark - Convenience Methods

- (void)setPersonId:(nonnull NSString *)personId
Expand Down
12 changes: 8 additions & 4 deletions RollbarNotifier/Sources/RollbarNotifier/RollbarInfrastructure.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@interface RollbarInfrastructure ()
@property (readwrite, strong) id<RollbarLogger> logger;
@property (readwrite, strong) RollbarConfig *configuration;
@property (readwrite, strong) RollbarCrashCollector *collector;
@property (readwrite, strong, nullable) RollbarCrashCollector *collector;
@end

@implementation RollbarInfrastructure
Expand Down Expand Up @@ -46,9 +46,13 @@ - (nonnull instancetype)configureWith:(nonnull RollbarConfig *)config {

[[RollbarTelemetry sharedInstance] configureWithOptions:config.telemetry];

self.collector = [[RollbarCrashCollector alloc] init];
[self.collector install];
[self.collector sendAllReports];
if (config.isCrashReportingEnabled) {
self.collector = [[RollbarCrashCollector alloc] init];
[self.collector install];
[self.collector sendAllReports];
} else {
self.collector = nil;
}

// Create RollbarThread and begin processing persisted occurrences
if ([[RollbarThread sharedInstance] active]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ typedef RollbarData *_Nonnull(^RollbarModifyData)(RollbarData *rollbarData);
/// Telemetry related settings
@property (nonnull, nonatomic, readonly, strong) RollbarTelemetryOptions *telemetry;

/// Whether Rollbar should enable automatic crash reporting
@property (nonatomic, readonly) BOOL isCrashReportingEnabled;

#pragma mark - Custom data

@property (nonatomic, readonly, strong) NSDictionary<NSString *, id> *customData;
Expand Down Expand Up @@ -136,6 +139,9 @@ NS_DESIGNATED_INITIALIZER;
/// Telemetry related settings
@property (nonnull, nonatomic, readwrite, strong) RollbarMutableTelemetryOptions *telemetry;

/// Whether Rollbar should enable automatic crash reporting
@property (nonatomic, readwrite) BOOL isCrashReportingEnabled;

#pragma mark - Custom data

@property (nonatomic, readwrite, strong) NSMutableDictionary<NSString *, id> *customData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ - (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

- (void)testCrashReportingEnabled {

RollbarMutableConfig *mutable = [RollbarMutableConfig new];
XCTAssertTrue(mutable.isCrashReportingEnabled);

mutable.isCrashReportingEnabled = NO;
XCTAssertFalse(mutable.isCrashReportingEnabled);

NSString *content = [mutable serializeToJSONString];
XCTAssertNotNil(content);
XCTAssertTrue([content containsString:@"crashReportingEnabled"]);

RollbarConfig *immutable = [mutable copy];
XCTAssertNotNil(immutable);
XCTAssertFalse(immutable.isCrashReportingEnabled);

RollbarMutableConfig *mutableCopy = [immutable mutableCopy];
XCTAssertFalse(mutableCopy.isCrashReportingEnabled);

RollbarConfig *configWithoutCrashReportingOption =
[[RollbarConfig alloc] initWithDictionary:@{}];
XCTAssertTrue(configWithoutCrashReportingOption.isCrashReportingEnabled);
}

- (void)testRollbarDestination {

NSString *defaultMutable = [[RollbarMutableDestination new] serializeToJSONString];
Expand Down
19 changes: 19 additions & 0 deletions docs/SDK Intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ Rollbar.initWithConfiguration(config)
//OR Rollbar.initWithConfiguration(config, crashCollector: crashCollector)
```

Automatic crash reporting is enabled by default. To disable it while keeping
manual logging available, update the configuration before initializing Rollbar:

#### Objective-C

```Obj-C
RollbarMutableConfig *config = [RollbarMutableConfig new];
config.isCrashReportingEnabled = NO;
[Rollbar initWithConfiguration:config];
```

#### Swift

```Swift
let config = RollbarMutableConfig()
config.isCrashReportingEnabled = false
Rollbar.initWithConfiguration(config)
```

### Start Logging using the Shared Notifier

#### Objective-C
Expand Down
Loading