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

Commit d7c3bc7

Browse files
Merge pull request #314 from bugsnag/stop-sessions
Add stopSession() and resumeSession() to public API
2 parents 98045e1 + 009c3d2 commit d7c3bc7

44 files changed

Lines changed: 491 additions & 98 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ android {
2424
}
2525

2626
dependencies {
27-
compile 'com.bugsnag:bugsnag-android:4.11.0'
27+
compile 'com.bugsnag:bugsnag-android:4.12.0'
2828
compile 'com.facebook.react:react-native:+'
2929
}

android/src/main/java/com/bugsnag/BugsnagReactNative.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ public void startSession() {
8484
Bugsnag.startSession();
8585
}
8686

87+
@ReactMethod
88+
public void stopSession() {
89+
Bugsnag.stopSession();
90+
}
91+
92+
@ReactMethod
93+
public void resumeSession() {
94+
Bugsnag.resumeSession();
95+
}
96+
8797
@ReactMethod
8898
public void startWithOptions(ReadableMap options) {
8999
String apiKey = null;
@@ -278,7 +288,7 @@ private void configureRuntimeOptions(Client client, ReadableMap options) {
278288
// The launch event session is skipped because autoCaptureSessions
279289
// was not set when Bugsnag was first initialized. Manually sending a
280290
// session to compensate.
281-
client.startSession();
291+
client.resumeSession();
282292
}
283293
}
284294
}

cocoa/BugsnagReactNative.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@
3838
- (void)setUser:(NSDictionary *)userInfo;
3939
- (void)clearUser;
4040
- (void)startSession;
41+
- (void)stopSession;
42+
- (void)resumeSession;
4143

4244
@end

cocoa/BugsnagReactNative.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
209209
[Bugsnag startSession];
210210
}
211211

212+
RCT_EXPORT_METHOD(stopSession) {
213+
if (![Bugsnag bugsnagStarted]) {
214+
return;
215+
}
216+
[Bugsnag stopSession];
217+
}
218+
219+
RCT_EXPORT_METHOD(resumeSession) {
220+
if (![Bugsnag bugsnagStarted]) {
221+
return;
222+
}
223+
[Bugsnag resumeSession];
224+
}
225+
212226
RCT_EXPORT_METHOD(clearUser) {
213227
if (![Bugsnag bugsnagStarted]) {
214228
return;
@@ -280,7 +294,7 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
280294
// The launch event session is skipped because shouldAutoCaptureSessions
281295
// was not set when Bugsnag was first initialized. Manually sending a
282296
// session to compensate.
283-
[Bugsnag startSession];
297+
[Bugsnag resumeSession];
284298
}
285299
}
286300

cocoa/vendor/bugsnag-cocoa/Source/Bugsnag.h

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,60 @@ static NSString *_Nonnull const BugsnagSeverityInfo = @"info";
211211
(BOOL)writeBinaryImagesForUserReported;
212212

213213
/**
214-
* Manually starts tracking a new session.
214+
* Starts tracking a new session.
215215
*
216-
* Sessions automatically start when the application enters the foreground state, and end when the application exits
217-
* the foreground.If you wish to manually start sessions, simply call this method from the relevant part of your
218-
* application. Starting a new session will automatically end the previous one.
216+
* By default, sessions are automatically started when the application enters the foreground.
217+
* If you wish to manually call startSession at
218+
* the appropriate time in your application instead, the default behaviour can be disabled via
219+
* shouldAutoCaptureSessions.
220+
*
221+
* Any errors which occur in an active session count towards your application's
222+
* stability score. You can prevent errors from counting towards your stability
223+
* score by calling stopSession and resumeSession at the appropriate
224+
* time in your application.
225+
*
226+
* @see stopSession:
227+
* @see resumeSession:
219228
*/
220-
221229
+ (void)startSession;
222230

231+
/**
232+
* Stops tracking a session.
233+
*
234+
* When a session is stopped, errors will not count towards your application's
235+
* stability score. This can be advantageous if you do not wish these calculations to
236+
* include a certain type of error, for example, a crash in a background service.
237+
* You should disable automatic session tracking via shouldAutoCaptureSessions if you call this method.
238+
*
239+
* A stopped session can be resumed by calling resumeSession,
240+
* which will make any subsequent errors count towards your application's
241+
* stability score. Alternatively, an entirely new session can be created by calling startSession.
242+
*
243+
* @see startSession:
244+
* @see resumeSession:
245+
*/
246+
+ (void)stopSession;
247+
248+
/**
249+
* Resumes a session which has previously been stopped, or starts a new session if none exists.
250+
*
251+
* If a session has already been resumed or started and has not been stopped, calling this
252+
* method will have no effect. You should disable automatic session tracking via
253+
* shouldAutoCaptureSessions if you call this method.
254+
*
255+
* It's important to note that sessions are stored in memory for the lifetime of the
256+
* application process and are not persisted on disk. Therefore calling this method on app
257+
* startup would start a new session, rather than continuing any previous session.
258+
*
259+
* You should call this at the appropriate time in your application when you wish to
260+
* resume a previously started session. Any subsequent errors which occur in your application
261+
* will be reported to Bugsnag and will count towards your application's stability score.
262+
*
263+
* @see startSession:
264+
* @see stopSession:
265+
*
266+
* @return true if a previous session was resumed, false if a new session was started.
267+
*/
268+
+ (BOOL)resumeSession;
269+
223270
@end

cocoa/vendor/bugsnag-cocoa/Source/Bugsnag.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,20 @@ + (void)startSession {
226226
}
227227
}
228228

229+
+ (void)stopSession {
230+
if ([self bugsnagStarted]) {
231+
[self.notifier stopSession];
232+
}
233+
}
234+
235+
+ (BOOL)resumeSession {
236+
if ([self bugsnagStarted]) {
237+
return [self.notifier resumeSession];
238+
} else {
239+
return false;
240+
}
241+
}
242+
229243
+ (NSDateFormatter *)payloadDateFormatter {
230244
static NSDateFormatter *formatter;
231245
static dispatch_once_t onceToken;

cocoa/vendor/bugsnag-cocoa/Source/BugsnagApiClient.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@class BugsnagConfiguration;
99

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

1212
@interface BugsnagApiClient : NSObject
1313

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

2222
- (NSOperation *)deliveryOperation;
2323

24-
- (void)sendData:(id)data
25-
withPayload:(NSDictionary *)payload
26-
toURL:(NSURL *)url
27-
headers:(NSDictionary *)headers
28-
onCompletion:(RequestCompletion)onCompletion;
24+
- (void)sendItems:(NSUInteger)count
25+
withPayload:(NSDictionary *)payload
26+
toURL:(NSURL *)url
27+
headers:(NSDictionary *)headers
28+
onCompletion:(RequestCompletion)onCompletion;
2929

3030
@property(readonly) NSOperationQueue *sendQueue;
3131
@property(readonly) BugsnagConfiguration *config;

cocoa/vendor/bugsnag-cocoa/Source/BugsnagApiClient.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ - (NSOperation *)deliveryOperation {
4949
#pragma mark - Delivery
5050

5151

52-
- (void)sendData:(id)data
53-
withPayload:(NSDictionary *)payload
54-
toURL:(NSURL *)url
55-
headers:(NSDictionary *)headers
56-
onCompletion:(RequestCompletion)onCompletion {
52+
- (void)sendItems:(NSUInteger)count
53+
withPayload:(NSDictionary *)payload
54+
toURL:(NSURL *)url
55+
headers:(NSDictionary *)headers
56+
onCompletion:(RequestCompletion)onCompletion {
5757

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

6565
if (jsonData == nil) {
6666
if (onCompletion) {
67-
onCompletion(data, NO, error);
67+
onCompletion(0, NO, error);
6868
}
6969
return;
7070
}
@@ -79,7 +79,7 @@ - (void)sendData:(id)data
7979
NSURLResponse *_Nullable response,
8080
NSError *_Nullable requestErr) {
8181
if (onCompletion) {
82-
onCompletion(data, requestErr == nil, requestErr);
82+
onCompletion(count, requestErr == nil, requestErr);
8383
}
8484
}];
8585
[task resume];
@@ -92,13 +92,13 @@ - (void)sendData:(id)data
9292
returningResponse:&response
9393
error:&error];
9494
if (onCompletion) {
95-
onCompletion(data, error == nil, error);
95+
onCompletion(count, error == nil, error);
9696
}
9797
#pragma clang diagnostic pop
9898
}
9999
} @catch (NSException *exception) {
100100
if (onCompletion) {
101-
onCompletion(data, NO,
101+
onCompletion(count, NO,
102102
[NSError errorWithDomain:exception.reason
103103
code:420
104104
userInfo:@{BSGKeyException: exception}]);

cocoa/vendor/bugsnag-cocoa/Source/BugsnagCrashReport.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ NSString *_Nonnull BSGFormatSeverity(BSGSeverity severity);
3939

4040
@interface BugsnagCrashReport : NSObject
4141

42+
/**
43+
* Create a new crash report from a JSON crash report generated by
44+
* BugsnagCrashSentry
45+
*
46+
* @param report a BugsnagCrashSentry JSON report
47+
* @param metadata additional report info encoded as a string
48+
*
49+
* @return a Bugsnag crash report
50+
*/
51+
- (instancetype _Nonnull)initWithKSReport:(NSDictionary *_Nonnull)report
52+
fileMetadata:(NSString *_Nonnull)metadata;
53+
4254
/**
4355
* Create a new crash report from a JSON crash report generated by
4456
* BugsnagCrashSentry
@@ -193,6 +205,10 @@ __deprecated_msg("Use toJson: instead.");
193205
*/
194206
@property(readwrite, copy, nullable) NSDictionary *appState;
195207

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

197213
/**
198214
* Returns the enhanced error message for the thread, or nil if none exists.

0 commit comments

Comments
 (0)