Skip to content

fix: Add helper for syncing a unity session to native reports #333

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

Merged
merged 2 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion Source/BugsnagNotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#import "BugsnagConfiguration.h"
#import "BugsnagMetaData.h"

@class BSGConnectivity;
@class BSGConnectivity, BugsnagSessionTracker;

@interface BugsnagNotifier : NSObject <BugsnagMetaDataDelegate>

Expand All @@ -38,6 +38,7 @@
@property(nonatomic, readwrite, retain) BugsnagMetaData *_Nonnull state;
@property(nonatomic, readwrite, retain) NSDictionary *_Nonnull details;
@property(nonatomic, readwrite, retain) NSLock *_Nonnull metaDataLock;
@property(nonatomic, readonly) BugsnagSessionTracker *_Nonnull sessionTracker;

@property(nonatomic) BSGConnectivity *_Nonnull networkReachable;
@property(readonly) BOOL started;
Expand Down
2 changes: 1 addition & 1 deletion Source/BugsnagNotifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void BSGWriteSessionCrashData(BugsnagSession *session) {
@interface BugsnagNotifier ()
@property(nonatomic) BugsnagCrashSentry *crashSentry;
@property(nonatomic) BugsnagErrorReportApiClient *errorReportApiClient;
@property(nonatomic) BugsnagSessionTracker *sessionTracker;
@property(nonatomic, readwrite) BugsnagSessionTracker *sessionTracker;
@end

@implementation BugsnagNotifier
Expand Down
6 changes: 6 additions & 0 deletions Source/BugsnagSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

- (_Nonnull instancetype)initWithDictionary:(NSDictionary *_Nonnull)dict;

- (_Nonnull instancetype)initWithId:(NSString *_Nonnull)sessionId
startDate:(NSDate *_Nonnull)startDate
user:(BugsnagUser *_Nullable)user
handledCount:(NSUInteger)handledCount
unhandledCount:(NSUInteger)unhandledCount;

- (NSDictionary *_Nonnull)toJson;

@property(readonly) NSString *_Nonnull sessionId;
Expand Down
15 changes: 15 additions & 0 deletions Source/BugsnagSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ - (instancetype)initWithDictionary:(NSDictionary *_Nonnull)dict {
return self;
}

- (_Nonnull instancetype)initWithId:(NSString *_Nonnull)sessionId
startDate:(NSDate *_Nonnull)startDate
user:(BugsnagUser *_Nullable)user
handledCount:(NSUInteger)handledCount
unhandledCount:(NSUInteger)unhandledCount {
if (self = [super init]) {
_sessionId = sessionId;
_startedAt = startDate;
_unhandledCount = unhandledCount;
_handledCount = handledCount;
_user = user;
}
return self;
}

- (NSDictionary *)toJson {
NSMutableDictionary *dict = [NSMutableDictionary new];
BSGDictInsertIfNotNil(dict, self.sessionId, kBugsnagSessionId);
Expand Down
11 changes: 11 additions & 0 deletions Source/BugsnagSessionTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ typedef void (^SessionTrackerCallback)(BugsnagSession *newSession);
*/
- (void)startNewSessionIfAutoCaptureEnabled;

/**
Update the details of the current session to account for externally reported
session information. Current session details are included in subsequent crash
reports.
*/
- (void)registerExistingSession:(NSString *)sessionId
startedAt:(NSDate *)startedAt
user:(BugsnagUser *)user
handledCount:(NSUInteger)handledCount
unhandledCount:(NSUInteger)unhandledCount;

/**
Handle the app foregrounding event. If more than 30s has elapsed since being
sent to the background, records a new session if session auto-capture is
Expand Down
15 changes: 15 additions & 0 deletions Source/BugsnagSessionTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ - (void)startNewSessionWithAutoCaptureValue:(BOOL)isAutoCaptured {
[self.apiClient deliverSessionsInStore:self.sessionStore];
}

- (void)registerExistingSession:(NSString *)sessionId
startedAt:(NSDate *)startedAt
user:(BugsnagUser *)user
handledCount:(NSUInteger)handledCount
unhandledCount:(NSUInteger)unhandledCount {
self.currentSession = [[BugsnagSession alloc] initWithId:sessionId
startDate:startedAt
user:user
handledCount:handledCount
unhandledCount:unhandledCount];
if (self.callback) {
self.callback(self.currentSession);
}
}

#pragma mark - Handling events

- (void)handleAppBackgroundEvent {
Expand Down