-
Notifications
You must be signed in to change notification settings - Fork 130
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
On by default session tracking #286
Changes from 29 commits
831f63d
dceac81
b6d16bf
48e267f
b3d5420
abb08c2
4b7277d
f3922c6
26a2c37
57722ed
0645bad
8980ea3
0677b66
fda541e
e12ff70
d813cef
c89979d
ec307f1
e84d311
0ff92ec
57044de
348e095
3bf9f72
8a65049
f4bffac
19d23a4
70c6e76
00bb48b
8bd994f
d05198d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
#import "BSG_KSLogger.h" | ||
#import "BugsnagSessionTrackingPayload.h" | ||
#import "BugsnagSessionTrackingApiClient.h" | ||
#import "BugsnagLogger.h" | ||
|
||
@interface BugsnagSessionTracker () | ||
@property BugsnagConfiguration *config; | ||
|
@@ -43,6 +44,10 @@ - (instancetype)initWithConfig:(BugsnagConfiguration *)config | |
- (void)startNewSession:(NSDate *)date | ||
withUser:(BugsnagUser *)user | ||
autoCaptured:(BOOL)autoCaptured { | ||
if (self.config.sessionURL == nil) { | ||
bsg_log_err(@"The session tracking endpoint has not been set. Session tracking is disabled"); | ||
return; | ||
} | ||
|
||
_currentSession = [[BugsnagSession alloc] initWithId:[[NSUUID UUID] UUIDString] | ||
startDate:date | ||
|
@@ -58,7 +63,7 @@ - (void)startNewSession:(NSDate *)date | |
- (void)trackSession { | ||
[self.sessionStore write:self.currentSession]; | ||
self.trackedFirstSession = YES; | ||
|
||
if (self.callback) { | ||
self.callback(self.currentSession); | ||
} | ||
|
@@ -87,34 +92,41 @@ - (void)incrementHandledError { | |
} | ||
|
||
- (void)send { | ||
@synchronized (self.sessionStore) { | ||
NSMutableArray *sessions = [NSMutableArray new]; | ||
NSArray *fileIds = [self.sessionStore fileIds]; | ||
NSArray *fileIds = [self.sessionStore fileIds]; | ||
|
||
for (NSDictionary *dict in [self.sessionStore allFiles]) { | ||
[sessions addObject:[[BugsnagSession alloc] initWithDictionary:dict]]; | ||
} | ||
BugsnagSessionTrackingPayload *payload = [[BugsnagSessionTrackingPayload alloc] initWithSessions:sessions]; | ||
|
||
if (payload.sessions.count > 0) { | ||
[self.apiClient sendData:payload | ||
withPayload:[payload toJson] | ||
toURL:self.config.sessionURL | ||
headers:self.config.sessionApiHeaders | ||
onCompletion:^(id data, BOOL success, NSError *error) { | ||
|
||
if (success && error == nil) { | ||
NSLog(@"Sent sessions to Bugsnag"); | ||
|
||
for (NSString *fileId in fileIds) { | ||
[self.sessionStore deleteFileWithId:fileId]; | ||
} | ||
} else { | ||
NSLog(@"Failed to send sessions to Bugsnag: %@", error); | ||
if (fileIds.count <= 0) { | ||
return; | ||
} | ||
|
||
dispatch_semaphore_t requestSemaphore = dispatch_semaphore_create(0); | ||
NSMutableArray *sessions = [NSMutableArray new]; | ||
|
||
for (NSDictionary *dict in [self.sessionStore allFiles]) { | ||
[sessions addObject:[[BugsnagSession alloc] initWithDictionary:dict]]; | ||
} | ||
BugsnagSessionTrackingPayload *payload = [[BugsnagSessionTrackingPayload alloc] initWithSessions:sessions]; | ||
|
||
if (payload.sessions.count > 0) { | ||
[self.apiClient sendData:payload | ||
withPayload:[payload toJson] | ||
toURL:self.config.sessionURL | ||
headers:self.config.sessionApiHeaders | ||
onCompletion:^(id data, BOOL success, NSError *error) { | ||
if (success && error == nil) { | ||
NSLog(@"Sent sessions to Bugsnag"); | ||
|
||
for (NSString *fileId in fileIds) { | ||
[self.sessionStore deleteFileWithId:fileId]; | ||
} | ||
}]; | ||
} | ||
} else { | ||
NSLog(@"Failed to send sessions to Bugsnag: %@", error); | ||
} | ||
dispatch_semaphore_signal(requestSemaphore); | ||
}]; | ||
} else { | ||
dispatch_semaphore_signal(requestSemaphore); | ||
} | ||
dispatch_semaphore_wait(requestSemaphore, DISPATCH_TIME_FOREVER); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens here if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed by sending a signal to the semaphore immediately in this case. |
||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ @implementation BugsnagUser | |
- (instancetype)initWithDictionary:(NSDictionary *)dict { | ||
if (self = [super init]) { | ||
_userId = dict[@"id"]; | ||
_emailAddress = dict[@"emailAddress"]; | ||
_emailAddress = dict[@"email"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are the changes in this file related to this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This addresses an issue in the session request serialisation which was found when adding mazerunner scenarios. Currently the session request sends I can split this off into a separate PR if you think it makes more sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that makes sense, I think it would be good to have it in a separate PR to track it more easily |
||
_name = dict[@"name"]; | ||
} | ||
return self; | ||
|
@@ -34,12 +34,12 @@ + (instancetype)userWithUserId:(NSString *)userId name:(NSString *)name emailAdd | |
return [[self alloc] initWithUserId:userId name:name emailAddress:emailAddress]; | ||
} | ||
|
||
|
||
- (NSDictionary *)toJson { | ||
NSMutableDictionary *dict = [NSMutableDictionary new]; | ||
BSGDictInsertIfNotNil(dict, self.userId, @"id"); | ||
BSGDictInsertIfNotNil(dict, self.emailAddress, @"emailAddress"); | ||
BSGDictInsertIfNotNil(dict, self.emailAddress, @"email"); | ||
BSGDictInsertIfNotNil(dict, self.name, @"name"); | ||
return [NSDictionary dictionaryWithDictionary:dict]; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ - (void)setUp { | |
config.autoNotify = NO; | ||
config.apiKey = @"apiKeyHere"; | ||
config.releaseStage = @"MagicalTestingTime"; | ||
config.notifyURL = nil; | ||
[config setEndpointsForNotify:@"http://localhost:8000" sessions:@"http://localhost:8000"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The notifyURL was cleared previous, but now this is being set to localhost:8000, is this correct? Also sessions endpoint is localhost:10000 |
||
[Bugsnag startBugsnagWithConfiguration:config]; | ||
BugsnagCrashReport *report = | ||
[[BugsnagCrashReport alloc] initWithKSReport:self.rawReportData]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ - (void)testDictDeserialisation { | |
|
||
NSDictionary *dict = @{ | ||
@"id": @"test", | ||
@"emailAddress": @"[email protected]", | ||
@"email": @"[email protected]", | ||
This comment was marked as outdated.
Sorry, something went wrong. |
||
@"name": @"Tom Bombadil" | ||
}; | ||
BugsnagUser *user = [[BugsnagUser alloc] initWithDictionary:dict]; | ||
|
@@ -41,7 +41,7 @@ - (void)testPayloadSerialisation { | |
XCTAssertEqual(3, [rootNode count]); | ||
|
||
XCTAssertEqualObjects(@"test", rootNode[@"id"]); | ||
XCTAssertEqualObjects(@"[email protected]", rootNode[@"emailAddress"]); | ||
XCTAssertEqualObjects(@"[email protected]", rootNode[@"email"]); | ||
XCTAssertEqualObjects(@"Tom Bombadil", rootNode[@"name"]); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
PODS: | ||
- Bugsnag (5.15.4) | ||
- Bugsnag (5.15.6) | ||
|
||
DEPENDENCIES: | ||
- Bugsnag (from `../..`) | ||
|
||
EXTERNAL SOURCES: | ||
Bugsnag: | ||
:path: ../.. | ||
:path: "../.." | ||
|
||
SPEC CHECKSUMS: | ||
Bugsnag: 904211a0230f254808b47f3adb4b684900772962 | ||
Bugsnag: ff5f5e3059e6a9c9d27a899f3bf3774067553483 | ||
|
||
PODFILE CHECKSUM: 2107babfbfdb18f0288407b9d9ebd48cbee8661c | ||
|
||
COCOAPODS: 1.4.0 | ||
COCOAPODS: 1.5.0 |
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.