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

v1.7.0 release candidate: new developer config options #167

Merged
merged 3 commits into from
Jun 27, 2019
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
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

The change log has moved to this repo's [GitHub Releases Page](https://github.com/rollbar/rollbar-ios/releases).

## Release Notes Tagging Conventions

1. Every entry within the PackageReleaseNotes element is expected to be started with
at least one of the tags listed:

feat: A new feature
fix: A bug fix
docs: Documentation only changes
style: Changes that do not affect the meaning of the code
refactor: A code change that neither a bug fix nor a new feature
perf: A code change that improves performance
test: Adding or modifying unit test code
chore: Changes to the build process or auxiliary tools and libraries such as documentation generation, etc.

2. Every entry within the PackageReleaseNotes element is expected to be tagged with
EITHER
"resolve #GITHUB_ISSUE_NUMBER:" - meaning completely addresses the GitHub issue
OR
"ref #GITHUB_ISSUE_NUMBER:" - meaning relevant to the GitHub issue
depending on what is more appropriate in each case.

## Release Notes

**1.7.0**

- feat: ref #162: Implement the standardized Development Configuration Options.
- feat: resolve #163: Add developer option: transmit.
- feat: resolve #164: Add a developer config option: logPayload.

**1.6.0**

- resolve #157: Ability to customize client.ios.code_version
Expand Down
45 changes: 27 additions & 18 deletions Rollbar/RollbarConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,51 @@ typedef NS_ENUM(NSUInteger, CaptureIpType) {

- (NSDictionary *)customData;

// Developer options:
@property (nonatomic) BOOL enabled;
@property (nonatomic) BOOL transmit;
@property (nonatomic) BOOL logPayload;
@property (readonly, nonatomic, copy) NSString *logPayloadFile;

// Rollbar project endpoint/destination:
@property (nonatomic, copy) NSString *accessToken;
@property (nonatomic, copy) NSString *environment;
@property (nonatomic, copy) NSString *endpoint;

// HTTP proxy:
@property (nonatomic) BOOL httpProxyEnabled;
@property (nonatomic, copy) NSString *httpProxy;
@property (nonatomic) NSNumber *httpProxyPort;

// HTTPS proxy:
@property (nonatomic) BOOL httpsProxyEnabled;
@property (nonatomic, copy) NSString *httpsProxy;
@property (nonatomic) NSNumber *httpsProxyPort;

// Logging options:
@property (nonatomic, copy) NSString *crashLevel;
@property (nonatomic, copy) NSString *logLevel;
@property (readonly, nonatomic) NSUInteger maximumReportsPerMinute;
@property (readonly, nonatomic) BOOL shouldCaptureConnectivity;

@property (readonly, nonatomic, copy) NSString *personId;
@property (readonly, nonatomic, copy) NSString *personUsername;
@property (readonly, nonatomic, copy) NSString *personEmail;

@property (readonly, nonatomic, copy) NSString *codeVersion;

@property (nonatomic) BOOL telemetryEnabled;
@property (nonatomic) BOOL scrubViewInputsTelemetry;
@property (nonatomic, strong) NSMutableSet *telemetryViewInputsToScrub;

// Modify payload
@property (readonly, nonatomic, copy) void (^payloadModification)(NSMutableDictionary *payload);

// Payload content related:
// ========================
// Decides whether or not to send payload. Returns true to ignore, false to send
@property (readonly, nonatomic, copy) BOOL (^checkIgnore)(NSDictionary *payload);

// Modify payload
@property (readonly, nonatomic, copy) void (^payloadModification)(NSMutableDictionary *payload);
// Fields to scrub from the payload
@property (readonly, nonatomic, strong) NSMutableSet *scrubFields;

// Fields to not scrub from the payload even if they mention among scrubFields:
@property (readonly, nonatomic, strong) NSMutableSet *scrubWhitelistFields;
@property (readonly, nonatomic) CaptureIpType captureIp;

// ID to link request between client/server
@property (readonly, nonatomic, copy) NSString *requestId;
// Telemetry:
@property (nonatomic) BOOL telemetryEnabled;
@property (nonatomic) BOOL scrubViewInputsTelemetry;
@property (nonatomic, strong) NSMutableSet *telemetryViewInputsToScrub;

@property (readonly, nonatomic) CaptureIpType captureIp;
@property (readonly, nonatomic, copy) NSString *codeVersion;

@property (readonly, nonatomic, copy) NSString *serverHost;
@property (readonly, nonatomic, copy) NSString *serverRoot;
Expand All @@ -102,4 +103,12 @@ typedef NS_ENUM(NSUInteger, CaptureIpType) {
@property (readonly, nonatomic, copy) NSString *notifierVersion;
@property (readonly, nonatomic, copy) NSString *framework;

// Person/user tracking:
@property (readonly, nonatomic, copy) NSString *personId;
@property (readonly, nonatomic, copy) NSString *personUsername;
@property (readonly, nonatomic, copy) NSString *personEmail;

// ID to link request between client/server
@property (readonly, nonatomic, copy) NSString *requestId;

@end
19 changes: 19 additions & 0 deletions Rollbar/RollbarConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ - (id)init {
_logLevel = @"info";

_enabled = true;
_transmit = true;
_logPayload = false;
_logPayloadFile = @"rollbar.payloads";

self.telemetryEnabled = false;
_maximumReportsPerMinute = 60;
[self setCaptureLogAsTelemetryData:false];
Expand Down Expand Up @@ -104,6 +108,21 @@ - (void)setEnabled:(BOOL)enabled {
[self save];
}

- (void)setTransmit:(BOOL)transmit {
_transmit = transmit;
[self save];
}

- (void)setLogPayload:(BOOL)logPayload {
_logPayload = logPayload;
[self save];
}

- (void)setLogPayloadFile:(NSString *)logPayloadFile {
_logPayloadFile = logPayloadFile;
[self save];
}

- (void)setHttpProxyEnabled:(BOOL)httpProxyEnabled {
_httpProxyEnabled = httpProxyEnabled;
[self save];
Expand Down
48 changes: 48 additions & 0 deletions Rollbar/RollbarNotifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

static NSString *QUEUED_ITEMS_FILE_NAME = @"rollbar.items";
static NSString *STATE_FILE_NAME = @"rollbar.state";
static NSString *PAYLOADS_FILE_NAME = @"rollbar.payloads";

static NSUInteger MAX_RETRY_COUNT = 5;

static NSString *queuedItemsFilePath = nil;
static NSString *stateFilePath = nil;
static NSMutableDictionary *queueState = nil;
static NSString *payloadsFilePath = nil;

static RollbarThread *rollbarThread = nil;
static RollbarReachability *reachability = nil;
Expand All @@ -44,19 +46,38 @@ - (id)initWithAccessToken:(NSString*)accessToken
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
NSUserDomainMask,
YES);
// define expected file paths:
NSString *cachesDirectory =
[paths objectAtIndex:0];
if (nil != self.configuration.logPayloadFile
&& self.configuration.logPayloadFile.length > 0) {

payloadsFilePath =
[cachesDirectory stringByAppendingPathComponent:self.configuration.logPayloadFile];
}
else {

payloadsFilePath =
[cachesDirectory stringByAppendingPathComponent:PAYLOADS_FILE_NAME];
}
queuedItemsFilePath =
[cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME];
stateFilePath =
[cachesDirectory stringByAppendingPathComponent:STATE_FILE_NAME];

// either create or overwrite the payloads log file:
[[NSFileManager defaultManager] createFileAtPath:payloadsFilePath
contents:nil
attributes:nil];

// create the queued items file if does not exist already:
if (![[NSFileManager defaultManager] fileExistsAtPath:queuedItemsFilePath]) {
[[NSFileManager defaultManager] createFileAtPath:queuedItemsFilePath
contents:nil
attributes:nil];
}

// create state tracking file if does not exist already:
if ([[NSFileManager defaultManager] fileExistsAtPath:stateFilePath]) {
NSData *stateData = [NSData dataWithContentsOfFile:stateFilePath];
if (stateData) {
Expand Down Expand Up @@ -495,6 +516,15 @@ - (BOOL)sendItem:(NSDictionary*)payload
error:nil
safe:true];

if (YES == self.configuration.logPayload) {
// append-save this jsonPayload into the payloads log file:
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:payloadsFilePath];
[fileHandle seekToEndOfFile];
[fileHandle writeData:jsonPayload];
[fileHandle writeData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding]];
[fileHandle closeFile];
}

BOOL success = [self sendPayload:jsonPayload];
if (!success) {
NSUInteger retryCount = [queueState[@"retry_count"] unsignedIntegerValue];
Expand Down Expand Up @@ -523,6 +553,18 @@ - (BOOL)sendPayload:(NSData*)payload {
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:self.configuration.accessToken forHTTPHeaderField:@"X-Rollbar-Access-Token"];
[request setHTTPBody:payload];

if (YES == self.configuration.logPayload) {
NSString *payloadString = [[NSString alloc]initWithData:payload
encoding:NSUTF8StringEncoding
];
NSLog(@"%@", payloadString);
//TODO: if self.configuration.logPayloadFile is defined, save the payload into the file...
}

if (NO == self.configuration.transmit) {
return YES; // we just successfully shortcircuit here...
}

__block BOOL result = NO;
if (IS_IOS7_OR_HIGHER) {
Expand Down Expand Up @@ -573,6 +615,12 @@ - (BOOL)sendPayload:(NSData*)payload {
- (BOOL)checkPayloadResponse:(NSURLResponse*)response
error:(NSError*)error
data:(NSData*)data {

NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSDictionary *httpHeaders = [httpResponse allHeaderFields];
//TODO: lookup rate limiting headers and afjust reporting rate accordingly...


if (error) {
RollbarLog(@"There was an error reporting to Rollbar");
RollbarLog(@"Error: %@", [error localizedDescription]);
Expand Down
26 changes: 26 additions & 0 deletions RollbarTests/RollbarTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ - (void)setUp {
RollbarClearLogFile();
if (!Rollbar.currentConfiguration) {
[Rollbar initWithAccessToken:@""];

// [Rollbar initWithAccessToken:@"2ffc7997ed864dda94f63e7b7daae0f3"];
// Rollbar.currentConfiguration.accessToken = @"2ffc7997ed864dda94f63e7b7daae0f3";
// Rollbar.currentConfiguration.environment = @"unit-tests";
// Rollbar.currentConfiguration.transmit = YES;

}
}

Expand All @@ -23,6 +29,26 @@ - (void)tearDown {
[super tearDown];
}

- (void)testRollbarTransmit {

Rollbar.currentConfiguration.accessToken = @"2ffc7997ed864dda94f63e7b7daae0f3";
Rollbar.currentConfiguration.environment = @"unit-tests";
Rollbar.currentConfiguration.transmit = YES;

Rollbar.currentConfiguration.transmit = YES;
[Rollbar critical:@"Transmission test YES"];
[NSThread sleepForTimeInterval:2.0f];

Rollbar.currentConfiguration.transmit = NO;
[Rollbar critical:@"Transmission test NO"];
[NSThread sleepForTimeInterval:2.0f];

Rollbar.currentConfiguration.transmit = YES;
//Rollbar.currentConfiguration.enabled = NO;
[Rollbar critical:@"Transmission test YES2"];
[NSThread sleepForTimeInterval:2.0f];
}

- (void)testNotification {
NSDictionary *notificationText = @{
@"error": @[@"testing-error-with-message", [NSException exceptionWithName:@"testing-error" reason:@"testing-error-2" userInfo:nil]],
Expand Down