From 8b1198451526bf0d0f5be93c496c0c7c96cd5032 Mon Sep 17 00:00:00 2001 From: Delisa Mason Date: Mon, 18 Dec 2017 16:42:11 -0800 Subject: [PATCH] Add interface to tracking sessions --- android/build.gradle | 2 +- .../main/java/com/bugsnag/BugsnagReactNative.java | 12 ++++++++++++ cocoa/BugsnagReactNative.m | 7 +++++++ src/Bugsnag.js | 12 ++++++++++-- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 2f6e79f..ee93ff8 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -13,6 +13,6 @@ android { } dependencies { - compile 'com.bugsnag:bugsnag-android:4.1.4' + compile 'com.bugsnag:bugsnag-android:4.2.0' compile 'com.facebook.react:react-native:0.20.1' } diff --git a/android/src/main/java/com/bugsnag/BugsnagReactNative.java b/android/src/main/java/com/bugsnag/BugsnagReactNative.java index 3ad3887..a3b5ef1 100644 --- a/android/src/main/java/com/bugsnag/BugsnagReactNative.java +++ b/android/src/main/java/com/bugsnag/BugsnagReactNative.java @@ -199,6 +199,7 @@ private BreadcrumbType parseBreadcrumbType(String value) { private void configureRuntimeOptions(Client client, ReadableMap options) { client.setIgnoreClasses(new String[] {"com.facebook.react.common.JavascriptException"}); + Configuration config = client.getConfig(); if (options.hasKey("appVersion")) { String version = options.getString("appVersion"); if (version != null && version.length() > 0) @@ -211,6 +212,12 @@ private void configureRuntimeOptions(Client client, ReadableMap options) { client.setEndpoint(endpoint); } + if (options.hasKey("sessionsEndpoint")) { + String endpoint = options.getString("sessionsEndpoint"); + if (endpoint != null && endpoint.length() > 0) + config.setSessionEndpoint(endpoint); + } + if (options.hasKey("releaseStage")) { String releaseStage = options.getString("releaseStage"); if (releaseStage != null && releaseStage.length() > 0) @@ -225,6 +232,11 @@ private void configureRuntimeOptions(Client client, ReadableMap options) { } } + if (options.hasKey("autoCaptureSessions")) { + boolean autoCapture = options.getBoolean("autoCaptureSessions"); + config.setAutoCaptureSessions(autoCapture); + } + if (options.hasKey("codeBundleId")) { String codeBundleId = options.getString("codeBundleId"); if (codeBundleId != null && codeBundleId.length() > 0) diff --git a/cocoa/BugsnagReactNative.m b/cocoa/BugsnagReactNative.m index 6fcac5f..c26188d 100644 --- a/cocoa/BugsnagReactNative.m +++ b/cocoa/BugsnagReactNative.m @@ -207,6 +207,7 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config { NSString *releaseStage = [self parseReleaseStage:[RCTConvert NSString:options[@"releaseStage"]]]; NSArray *notifyReleaseStages = [RCTConvert NSStringArray:options[@"notifyReleaseStages"]]; NSString *notifyURLPath = [RCTConvert NSString:options[@"endpoint"]]; + NSString *sessionURLPath = [RCTConvert NSString:options[@"sessionsEndpoint"]]; NSString *appVersion = [RCTConvert NSString:options[@"appVersion"]]; NSString *codeBundleId = [RCTConvert NSString:options[@"codeBundleId"]]; BugsnagConfiguration* config = [Bugsnag bugsnagStarted] ? [Bugsnag configuration] : [BugsnagConfiguration new]; @@ -214,11 +215,17 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config { config.releaseStage = releaseStage; config.notifyReleaseStages = notifyReleaseStages; config.autoNotify = [RCTConvert BOOL:options[@"autoNotify"]]; + config.shouldAutoCaptureSessions = [RCTConvert BOOL:options[@"autoCaptureSessions"]]; [config addBeforeSendBlock:^bool(NSDictionary *_Nonnull rawEventData, BugsnagCrashReport *_Nonnull report) { return !([report.errorClass hasPrefix:@"RCTFatalException"] && [report.errorMessage hasPrefix:@"Unhandled JS Exception"]); }]; + if (sessionURLPath.length > 0) { + NSURL *sessionURL = [NSURL URLWithString:sessionURLPath]; + if (sessionURL) + config.sessionURL = sessionURL; + } if (notifyURLPath.length > 0) { NSURL *notifyURL = [NSURL URLWithString:notifyURLPath]; if (notifyURL) diff --git a/src/Bugsnag.js b/src/Bugsnag.js index b960995..095c605 100644 --- a/src/Bugsnag.js +++ b/src/Bugsnag.js @@ -129,6 +129,10 @@ export class Client { NativeClient.clearUser(); } + startSession = () => { + NativeClient.startSession(); + } + /** * Leaves a 'breadcrumb' log message. The most recent breadcrumbs * are attached to subsequent error reports. @@ -226,6 +230,7 @@ export class Configuration { this.releaseStage = undefined; this.appVersion = undefined; this.codeBundleId = undefined; + this.autoCaptureSessions = false; this.autoNotify = true; this.handlePromiseRejections = !__DEV__; // prefer banner in dev mode this.consoleBreadcrumbsEnabled = false; @@ -274,16 +279,19 @@ export class Configuration { releaseStage: this.releaseStage, notifyReleaseStages: this.notifyReleaseStages, endpoint: this.delivery.endpoint, + sessionsEndpoint: this.delivery.sessionsEndpoint, appVersion: this.appVersion, autoNotify: this.autoNotify, - version: this.version + version: this.version, + autoCaptureSessions: this.autoCaptureSessions, }; } } export class StandardDelivery { - constructor(endpoint) { + constructor(endpoint, sessionsEndpoint) { this.endpoint = endpoint || 'https://notify.bugsnag.com'; + this.sessionsEndpoint = sessionsEndpoint || 'https://sessions.bugsnag.com'; } }