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

Commit d5e5d22

Browse files
authored
Fix possible release stage mismatch between sessions and error reports (#260)
2 parents ce7abc4 + b14b54a commit d5e5d22

17 files changed

Lines changed: 258 additions & 193 deletions

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,34 @@ Changelog
33

44
## 2.X.X (TBD)
55

6+
This release simplies the installation and quick setup process to do all
7+
configuration in JavaScript, provided that React Native is the primary way to
8+
interact with your app (rather than having React Native components as a part of
9+
a larger native app). [See the integration guide updated configuration
10+
instructions](https://docs.bugsnag.com/platforms/react-native/#basic-configuration).
11+
12+
For applications using React Native to serve a few components (but not the whole
13+
app), there is a new [Native integration
14+
guide](https://docs.bugsnag.com/platforms/react-native/native-integration-guide/)
15+
with additional configuration steps to ensure every crash is captured and
16+
reported.
17+
618
### Bug fixes
719

20+
* Fix possible mismatch between session release stage and error report release
21+
stage, which could result in inconsistent crash rates on the Releases
22+
dashboard as a session was assigned to an incorrect release stage.
23+
[#260](https://github.com/bugsnag/bugsnag-react-native/issues/260)
24+
825
* (android) Address javac compiler warnings and intellij inspections
926
[#250](https://github.com/bugsnag/bugsnag-react-native/issues/250)
1027

28+
* (cocoa) Upgrade bugsnag-cocoa to v5.16.2:
29+
* Fix a regression in session tracking which caused the first session HTTP
30+
request to be delivered on the calling thread when automatic session tracking
31+
is enabled
32+
[#295](https://github.com/bugsnag/bugsnag-cocoa/pull/295)
33+
1134
## 2.10.0 (2018-07-03)
1235

1336
This release alters the behaviour of the notifier to track sessions automatically.

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,23 @@ public static ReactPackage getPackage() {
4646
}
4747

4848
public static Client start(Context context) {
49-
return Bugsnag.init(context);
49+
Client client = Bugsnag.init(context);
50+
// The first session starts during JS initialization
51+
// Applications which have specific components in RN instead of the primary
52+
// way to interact with the application should instead leverage startSession
53+
// manually.
54+
client.setAutoCaptureSessions(false);
55+
return client;
5056
}
5157

5258
public static Client startWithApiKey(Context context, String APIKey) {
53-
return Bugsnag.init(context, APIKey);
59+
Client client = Bugsnag.init(context, APIKey);
60+
client.setAutoCaptureSessions(false);
61+
return client;
5462
}
5563

5664
public static Client startWithConfiguration(Context context, Configuration config) {
65+
config.setAutoCaptureSessions(false);
5766
return Bugsnag.init(context, config);
5867
}
5968

@@ -267,10 +276,11 @@ private void configureRuntimeOptions(Client client, ReadableMap options) {
267276
if (options.hasKey("autoCaptureSessions")) {
268277
boolean autoCapture = options.getBoolean("autoCaptureSessions");
269278
config.setAutoCaptureSessions(autoCapture);
270-
Activity activity = getCurrentActivity();
271-
272-
if (activity != null) {
273-
client.startFirstSession(getCurrentActivity());
279+
if (autoCapture) {
280+
// The launch event session is skipped because autoCaptureSessions
281+
// was not set when Bugsnag was first initialized. Manually sending a
282+
// session to compensate.
283+
client.startSession();
274284
}
275285
}
276286
}

cocoa/BugsnagReactNative.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
131131
if (config.apiKey.length == 0)
132132
config.apiKey = [[NSBundle mainBundle] objectForInfoDictionaryKey:BSGInfoPlistKey];
133133

134+
// The first session starts during JS initialization
135+
// Applications which have specific components in RN instead of the primary
136+
// way to interact with the application should instead leverage startSession
137+
// manually.
138+
config.shouldAutoCaptureSessions = NO;
134139
[Bugsnag startBugsnagWithConfiguration:config];
135140
}
136141

@@ -230,6 +235,7 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
230235
NSString *sessionURLPath = [RCTConvert NSString:options[@"sessionsEndpoint"]];
231236
NSString *appVersion = [RCTConvert NSString:options[@"appVersion"]];
232237
NSString *codeBundleId = [RCTConvert NSString:options[@"codeBundleId"]];
238+
233239
BugsnagConfiguration* config = [Bugsnag bugsnagStarted] ? [Bugsnag configuration] : [BugsnagConfiguration new];
234240

235241
if (apiKey.length > 0) {
@@ -267,6 +273,12 @@ + (void)startWithConfiguration:(BugsnagConfiguration *)config {
267273
[Bugsnag startBugsnagWithConfiguration:config];
268274
}
269275
[self setNotifierDetails:[RCTConvert NSString:options[@"version"]]];
276+
if (config.shouldAutoCaptureSessions) {
277+
// The launch event session is skipped because shouldAutoCaptureSessions
278+
// was not set when Bugsnag was first initialized. Manually sending a
279+
// session to compensate.
280+
[Bugsnag startSession];
281+
}
270282
}
271283

272284
- (void)setNotifierDetails:(NSString *)packageVersion {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ BugsnagBreadcrumbs *breadcrumbs;
139139

140140
/**
141141
* Determines whether app sessions should be tracked automatically. By default this value is true.
142+
* If this value is updated after +[Bugsnag start] is called, only subsequent automatic sessions
143+
* will be captured.
142144
*/
143145
@property BOOL shouldAutoCaptureSessions;
144146

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,6 @@ - (void)setApiKey:(NSString *)apiKey {
218218
}
219219
}
220220

221-
@synthesize shouldAutoCaptureSessions = _shouldAutoCaptureSessions;
222-
223-
- (BOOL)shouldAutoCaptureSessions {
224-
return _shouldAutoCaptureSessions;
225-
}
226-
227-
- (void)setShouldAutoCaptureSessions:(BOOL)shouldAutoCaptureSessions {
228-
@synchronized (self) {
229-
_shouldAutoCaptureSessions = shouldAutoCaptureSessions;
230-
231-
if (shouldAutoCaptureSessions) { // track any existing sessions
232-
BugsnagSessionTracker *sessionTracker = [Bugsnag notifier].sessionTracker;
233-
[sessionTracker onAutoCaptureEnabled];
234-
}
235-
}
236-
}
237-
238221
- (NSDictionary *)errorApiHeaders {
239222
return @{
240223
kHeaderApiPayloadVersion: @"4.0",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ - (instancetype)initWithKSReport:(NSDictionary *)report {
242242
_context = BSGParseContext(report, _metaData);
243243
_deviceState = BSGParseDeviceState(report);
244244
_device = BSGParseDevice(report);
245-
_app = BSGParseApp(report[BSGKeySystem]);
246-
_appState = BSGParseAppState(report[BSGKeySystem]);
245+
_app = BSGParseApp(report);
246+
_appState = BSGParseAppState(report[BSGKeySystem], [report valueForKeyPath:@"user.config.appVersion"]);
247247
_groupingHash = BSGParseGroupingHash(report, _metaData);
248248
_overrides = [report valueForKeyPath:@"user.overrides"];
249249
_customException = BSGParseCustomException(report, [_errorClass copy],

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@
6767
- (NSMutableDictionary *)readFile:(NSString *)path
6868
error:(NSError *__autoreleasing *)error;
6969

70-
+ (NSString *)findReportStorePath:(NSString *)customDirectory
71-
bundleName:(NSString *)bundleName;
70+
+ (NSString *)findReportStorePath:(NSString *)customDirectory;
7271

7372
- (NSString *)fileIdFromFilename:(NSString *)filename;
7473
@end

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ - (void)deleteFileWithId:(NSString *)fileId {
180180
}
181181
}
182182

183-
+ (NSString *)findReportStorePath:(NSString *)customDirectory
184-
bundleName:(NSString *)bundleName {
183+
+ (NSString *)findReportStorePath:(NSString *)customDirectory {
185184

185+
NSString *bundleName = [[NSBundle mainBundle] infoDictionary][@"CFBundleName"];
186186
NSArray *directories = NSSearchPathForDirectoriesInDomains(
187187
NSCachesDirectory, NSUserDomainMask, YES);
188188
if ([directories count] == 0) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
NSDictionary *_Nonnull BSGParseDevice(NSDictionary *_Nonnull report);
1212
NSDictionary *_Nonnull BSGParseApp(NSDictionary *_Nonnull report);
13-
NSDictionary *_Nonnull BSGParseAppState(NSDictionary *_Nonnull report);
13+
NSDictionary *_Nonnull BSGParseAppState(NSDictionary *_Nonnull report, NSString *_Nullable preferredVersion);
1414
NSDictionary *_Nonnull BSGParseDeviceState(NSDictionary *_Nonnull report);

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@
6161
}
6262

6363
NSDictionary *BSGParseApp(NSDictionary *report) {
64+
NSDictionary *system = report[BSGKeySystem];
65+
6466
NSMutableDictionary *appState = [NSMutableDictionary dictionary];
6567

66-
NSDictionary *stats = report[@"application_stats"];
68+
NSDictionary *stats = system[@"application_stats"];
6769

6870
NSInteger activeTimeSinceLaunch =
6971
[stats[@"active_time_since_launch"] doubleValue] * 1000.0;
@@ -73,23 +75,25 @@
7375
BSGDictSetSafeObject(appState, @(activeTimeSinceLaunch),
7476
@"durationInForeground");
7577

76-
BSGDictSetSafeObject(appState, report[BSGKeyExecutableName], BSGKeyName);
78+
BSGDictSetSafeObject(appState, system[BSGKeyExecutableName], BSGKeyName);
7779
BSGDictSetSafeObject(appState,
7880
@(activeTimeSinceLaunch + backgroundTimeSinceLaunch),
7981
@"duration");
8082
BSGDictSetSafeObject(appState, stats[@"application_in_foreground"],
8183
@"inForeground");
82-
BSGDictSetSafeObject(appState, report[@"CFBundleIdentifier"], BSGKeyId);
84+
BSGDictSetSafeObject(appState, system[@"CFBundleIdentifier"], BSGKeyId);
8385
return appState;
8486
}
8587

86-
NSDictionary *BSGParseAppState(NSDictionary *report) {
88+
NSDictionary *BSGParseAppState(NSDictionary *report, NSString *preferredVersion) {
8789
NSMutableDictionary *app = [NSMutableDictionary dictionary];
8890

91+
NSString *version = preferredVersion ?: report[@"CFBundleShortVersionString"];
92+
8993
BSGDictSetSafeObject(app, report[@"CFBundleVersion"], @"bundleVersion");
9094
BSGDictSetSafeObject(app, [Bugsnag configuration].releaseStage,
9195
BSGKeyReleaseStage);
92-
BSGDictSetSafeObject(app, report[@"CFBundleShortVersionString"], BSGKeyVersion);
96+
BSGDictSetSafeObject(app, version, BSGKeyVersion);
9397

9498
BSGDictSetSafeObject(app, [Bugsnag configuration].codeBundleId, @"codeBundleId");
9599

0 commit comments

Comments
 (0)