Skip to content

Commit

Permalink
Add interface to tracking sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
kattrali committed Jan 9, 2018
1 parent c240d56 commit 8b11984
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
12 changes: 12 additions & 0 deletions android/src/main/java/com/bugsnag/BugsnagReactNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions cocoa/BugsnagReactNative.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,25 @@ + (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];
config.apiKey = apiKey;
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)
Expand Down
12 changes: 10 additions & 2 deletions src/Bugsnag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
}
}

Expand Down

0 comments on commit 8b11984

Please sign in to comment.