Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #314 from bugsnag/stop-sessions
Browse files Browse the repository at this point in the history
Add stopSession() and resumeSession() to public API
  • Loading branch information
fractalwrench committed Mar 5, 2019
2 parents 98045e1 + 009c3d2 commit d7c3bc7
Show file tree
Hide file tree
Showing 44 changed files with 491 additions and 98 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ android {
}

dependencies {
compile 'com.bugsnag:bugsnag-android:4.11.0'
compile 'com.bugsnag:bugsnag-android:4.12.0'
compile 'com.facebook.react:react-native:+'
}
12 changes: 11 additions & 1 deletion android/src/main/java/com/bugsnag/BugsnagReactNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ public void startSession() {
Bugsnag.startSession();
}

@ReactMethod
public void stopSession() {
Bugsnag.stopSession();
}

@ReactMethod
public void resumeSession() {
Bugsnag.resumeSession();
}

@ReactMethod
public void startWithOptions(ReadableMap options) {
String apiKey = null;
Expand Down Expand Up @@ -278,7 +288,7 @@ private void configureRuntimeOptions(Client client, ReadableMap options) {
// The launch event session is skipped because autoCaptureSessions
// was not set when Bugsnag was first initialized. Manually sending a
// session to compensate.
client.startSession();
client.resumeSession();
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions cocoa/BugsnagReactNative.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
- (void)setUser:(NSDictionary *)userInfo;
- (void)clearUser;
- (void)startSession;
- (void)stopSession;
- (void)resumeSession;

@end
16 changes: 15 additions & 1 deletion cocoa/BugsnagReactNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
[Bugsnag startSession];
}

RCT_EXPORT_METHOD(stopSession) {
if (![Bugsnag bugsnagStarted]) {
return;
}
[Bugsnag stopSession];
}

RCT_EXPORT_METHOD(resumeSession) {
if (![Bugsnag bugsnagStarted]) {
return;
}
[Bugsnag resumeSession];
}

RCT_EXPORT_METHOD(clearUser) {
if (![Bugsnag bugsnagStarted]) {
return;
Expand Down Expand Up @@ -280,7 +294,7 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
// The launch event session is skipped because shouldAutoCaptureSessions
// was not set when Bugsnag was first initialized. Manually sending a
// session to compensate.
[Bugsnag startSession];
[Bugsnag resumeSession];
}
}

Expand Down
57 changes: 52 additions & 5 deletions cocoa/vendor/bugsnag-cocoa/Source/Bugsnag.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,60 @@ static NSString *_Nonnull const BugsnagSeverityInfo = @"info";
(BOOL)writeBinaryImagesForUserReported;

/**
* Manually starts tracking a new session.
* Starts tracking a new session.
*
* Sessions automatically start when the application enters the foreground state, and end when the application exits
* the foreground.If you wish to manually start sessions, simply call this method from the relevant part of your
* application. Starting a new session will automatically end the previous one.
* By default, sessions are automatically started when the application enters the foreground.
* If you wish to manually call startSession at
* the appropriate time in your application instead, the default behaviour can be disabled via
* shouldAutoCaptureSessions.
*
* Any errors which occur in an active session count towards your application's
* stability score. You can prevent errors from counting towards your stability
* score by calling stopSession and resumeSession at the appropriate
* time in your application.
*
* @see stopSession:
* @see resumeSession:
*/

+ (void)startSession;

/**
* Stops tracking a session.
*
* When a session is stopped, errors will not count towards your application's
* stability score. This can be advantageous if you do not wish these calculations to
* include a certain type of error, for example, a crash in a background service.
* You should disable automatic session tracking via shouldAutoCaptureSessions if you call this method.
*
* A stopped session can be resumed by calling resumeSession,
* which will make any subsequent errors count towards your application's
* stability score. Alternatively, an entirely new session can be created by calling startSession.
*
* @see startSession:
* @see resumeSession:
*/
+ (void)stopSession;

/**
* Resumes a session which has previously been stopped, or starts a new session if none exists.
*
* If a session has already been resumed or started and has not been stopped, calling this
* method will have no effect. You should disable automatic session tracking via
* shouldAutoCaptureSessions if you call this method.
*
* It's important to note that sessions are stored in memory for the lifetime of the
* application process and are not persisted on disk. Therefore calling this method on app
* startup would start a new session, rather than continuing any previous session.
*
* You should call this at the appropriate time in your application when you wish to
* resume a previously started session. Any subsequent errors which occur in your application
* will be reported to Bugsnag and will count towards your application's stability score.
*
* @see startSession:
* @see stopSession:
*
* @return true if a previous session was resumed, false if a new session was started.
*/
+ (BOOL)resumeSession;

@end
14 changes: 14 additions & 0 deletions cocoa/vendor/bugsnag-cocoa/Source/Bugsnag.m
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,20 @@ + (void)startSession {
}
}

+ (void)stopSession {
if ([self bugsnagStarted]) {
[self.notifier stopSession];
}
}

+ (BOOL)resumeSession {
if ([self bugsnagStarted]) {
return [self.notifier resumeSession];
} else {
return false;
}
}

+ (NSDateFormatter *)payloadDateFormatter {
static NSDateFormatter *formatter;
static dispatch_once_t onceToken;
Expand Down
12 changes: 6 additions & 6 deletions cocoa/vendor/bugsnag-cocoa/Source/BugsnagApiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@class BugsnagConfiguration;

typedef void (^RequestCompletion)(id data, BOOL success, NSError *error);
typedef void (^RequestCompletion)(NSUInteger reportCount, BOOL success, NSError *error);

@interface BugsnagApiClient : NSObject

Expand All @@ -21,11 +21,11 @@ typedef void (^RequestCompletion)(id data, BOOL success, NSError *error);

- (NSOperation *)deliveryOperation;

- (void)sendData:(id)data
withPayload:(NSDictionary *)payload
toURL:(NSURL *)url
headers:(NSDictionary *)headers
onCompletion:(RequestCompletion)onCompletion;
- (void)sendItems:(NSUInteger)count
withPayload:(NSDictionary *)payload
toURL:(NSURL *)url
headers:(NSDictionary *)headers
onCompletion:(RequestCompletion)onCompletion;

@property(readonly) NSOperationQueue *sendQueue;
@property(readonly) BugsnagConfiguration *config;
Expand Down
18 changes: 9 additions & 9 deletions cocoa/vendor/bugsnag-cocoa/Source/BugsnagApiClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ - (NSOperation *)deliveryOperation {
#pragma mark - Delivery


- (void)sendData:(id)data
withPayload:(NSDictionary *)payload
toURL:(NSURL *)url
headers:(NSDictionary *)headers
onCompletion:(RequestCompletion)onCompletion {
- (void)sendItems:(NSUInteger)count
withPayload:(NSDictionary *)payload
toURL:(NSURL *)url
headers:(NSDictionary *)headers
onCompletion:(RequestCompletion)onCompletion {

@try {
NSError *error = nil;
Expand All @@ -64,7 +64,7 @@ - (void)sendData:(id)data

if (jsonData == nil) {
if (onCompletion) {
onCompletion(data, NO, error);
onCompletion(0, NO, error);
}
return;
}
Expand All @@ -79,7 +79,7 @@ - (void)sendData:(id)data
NSURLResponse *_Nullable response,
NSError *_Nullable requestErr) {
if (onCompletion) {
onCompletion(data, requestErr == nil, requestErr);
onCompletion(count, requestErr == nil, requestErr);
}
}];
[task resume];
Expand All @@ -92,13 +92,13 @@ - (void)sendData:(id)data
returningResponse:&response
error:&error];
if (onCompletion) {
onCompletion(data, error == nil, error);
onCompletion(count, error == nil, error);
}
#pragma clang diagnostic pop
}
} @catch (NSException *exception) {
if (onCompletion) {
onCompletion(data, NO,
onCompletion(count, NO,
[NSError errorWithDomain:exception.reason
code:420
userInfo:@{BSGKeyException: exception}]);
Expand Down
16 changes: 16 additions & 0 deletions cocoa/vendor/bugsnag-cocoa/Source/BugsnagCrashReport.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ NSString *_Nonnull BSGFormatSeverity(BSGSeverity severity);

@interface BugsnagCrashReport : NSObject

/**
* Create a new crash report from a JSON crash report generated by
* BugsnagCrashSentry
*
* @param report a BugsnagCrashSentry JSON report
* @param metadata additional report info encoded as a string
*
* @return a Bugsnag crash report
*/
- (instancetype _Nonnull)initWithKSReport:(NSDictionary *_Nonnull)report
fileMetadata:(NSString *_Nonnull)metadata;

/**
* Create a new crash report from a JSON crash report generated by
* BugsnagCrashSentry
Expand Down Expand Up @@ -193,6 +205,10 @@ __deprecated_msg("Use toJson: instead.");
*/
@property(readwrite, copy, nullable) NSDictionary *appState;

/**
* If YES, a complete report was not able to be obtained at generation time
*/
@property (readonly, nonatomic, getter=isIncomplete) BOOL incomplete;

/**
* Returns the enhanced error message for the thread, or nil if none exists.
Expand Down
Loading

0 comments on commit d7c3bc7

Please sign in to comment.