Skip to content

Commit

Permalink
Merge pull request #1078 from bugsnag/nickdowell/fix-oom-app-info
Browse files Browse the repository at this point in the history
[PLAT-6391] Fix OOM app info
  • Loading branch information
nickdowell committed Apr 22, 2021
2 parents 06d4823 + af342cf commit a91c9a1
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 12 deletions.
3 changes: 0 additions & 3 deletions .buildkite/pipeline.yml
Expand Up @@ -138,7 +138,6 @@ steps:
docker-compose#v3.3.0:
run: cocoa-maze-runner
command:
- "features/app_hangs.feature"
- "features/barebone_tests.feature"
- "--app=/app/build/iOSTestApp.ipa"
- "--farm=bs"
Expand All @@ -165,7 +164,6 @@ steps:
docker-compose#v3.3.0:
run: cocoa-maze-runner
command:
- "features/app_hangs.feature"
- "features/barebone_tests.feature"
- "--app=/app/build/iOSTestApp.ipa"
- "--farm=bs"
Expand All @@ -192,7 +190,6 @@ steps:
commands:
- bundle install
- bundle exec maze-runner
features/app_hangs.feature
features/barebone_tests.feature
--farm=local
--os=macos
Expand Down
7 changes: 7 additions & 0 deletions Bugsnag/Client/BugsnagClient+OutOfMemory.m
Expand Up @@ -11,6 +11,7 @@
#import "BugsnagAppWithState+Private.h"
#import "BugsnagBreadcrumbs.h"
#import "BugsnagClient+Private.h"
#import "BugsnagConfiguration+Private.h"
#import "BugsnagDeviceWithState+Private.h"
#import "BugsnagError+Private.h"
#import "BugsnagEvent+Private.h"
Expand All @@ -27,6 +28,12 @@ - (BugsnagEvent *)generateOutOfMemoryEvent {
app.dsymUuid = appDict[BSGKeyMachoUUID];
app.isLaunching = [self.stateMetadataFromLastLaunch[BSGKeyApp][BSGKeyIsLaunching] boolValue];

if (self.configMetadataFromLastLaunch) {
[app setValuesFromConfiguration:
[[BugsnagConfiguration alloc] initWithDictionaryRepresentation:
(NSDictionary * _Nonnull)self.configMetadataFromLastLaunch]];
}

NSDictionary *deviceDict = self.systemState.lastLaunchState[SYSTEMSTATE_KEY_DEVICE];
BugsnagDeviceWithState *device = [BugsnagDeviceWithState deviceFromJson:deviceDict];
device.manufacturer = @"Apple";
Expand Down
2 changes: 2 additions & 0 deletions Bugsnag/Payload/BugsnagApp+Private.h
Expand Up @@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN

+ (void)populateFields:(BugsnagApp *)app dictionary:(NSDictionary *)event config:(BugsnagConfiguration *)config codeBundleId:(NSString *)codeBundleId;

- (void)setValuesFromConfiguration:(BugsnagConfiguration *)configuration;

- (NSDictionary *)toDict;

@end
Expand Down
23 changes: 19 additions & 4 deletions Bugsnag/Payload/BugsnagApp.m
Expand Up @@ -61,12 +61,27 @@ + (void)populateFields:(BugsnagApp *)app
{
NSDictionary *system = event[BSGKeySystem];
app.id = system[@"CFBundleIdentifier"];
app.bundleVersion = config.bundleVersion ?: system[@"CFBundleVersion"];
app.bundleVersion = system[@"CFBundleVersion"];
app.dsymUuid = system[@"app_uuid"];
app.version = config.appVersion ?: system[@"CFBundleShortVersionString"];
app.releaseStage = config.releaseStage;
app.version = system[@"CFBundleShortVersionString"];
app.codeBundleId = [event valueForKeyPath:@"user.state.app.codeBundleId"] ?: codeBundleId;
app.type = config.appType;
[app setValuesFromConfiguration:config];
}

- (void)setValuesFromConfiguration:(BugsnagConfiguration *)configuration
{
if (configuration.appType) {
self.type = configuration.appType;
}
if (configuration.appVersion) {
self.version = configuration.appVersion;
}
if (configuration.bundleVersion) {
self.bundleVersion = configuration.bundleVersion;
}
if (configuration.releaseStage) {
self.releaseStage = configuration.releaseStage;
}
}

- (NSDictionary *)toDict
Expand Down
1 change: 1 addition & 0 deletions Bugsnag/Payload/BugsnagAppWithState+Private.h
Expand Up @@ -7,6 +7,7 @@
//

#import "BugsnagAppWithState.h"
#import "BugsnagApp+Private.h"

@class BugsnagConfiguration;

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,9 @@ Changelog

### Bug fixes

* Fix `app` properties in OOMs for apps that override `appType`, `appVersion`, `bundleVersion` or `releaseStage` in their config.
[#1078](https://github.com/bugsnag/bugsnag-cocoa/pull/1078)

* `event.threads` will now be empty, rather than containing a single thread, if `sendThreads` dictates that threads should not be sent.
[#1077](https://github.com/bugsnag/bugsnag-cocoa/pull/1077)

Expand Down
9 changes: 4 additions & 5 deletions features/barebone_tests.feature
Expand Up @@ -178,17 +178,16 @@ Feature: Barebone tests

And I wait to receive an error
Then the error is an OOM event
And the event "app.bundleVersion" is not null
And the event "app.bundleVersion" equals "321.123"
And the event "app.dsymUUIDs" is not null
And the event "app.id" equals the platform-dependent string:
| ios | com.bugsnag.iOSTestApp |
| macos | com.bugsnag.macOSTestApp |
And the event "app.inForeground" is true
And the event "app.isLaunching" is true
And the event "app.type" equals the platform-dependent string:
| ios | iOS |
| macos | macOS |
And the event "app.version" is not null
And the event "app.releaseStage" equals "staging"
And the event "app.type" equals "vanilla"
And the event "app.version" equals "3.2.1"
And the event "breadcrumbs.0.name" equals "Bugsnag loaded"
And the event "breadcrumbs.1.name" equals "Memory Warning"
And the event "device.id" is not null
Expand Down
4 changes: 4 additions & 0 deletions features/fixtures/shared/scenarios/OOMScenario.m
Expand Up @@ -24,6 +24,10 @@ - (void)startBugsnag {
self.config.autoTrackSessions = YES;
self.config.enabledErrorTypes.ooms = YES;
self.config.launchDurationMillis = 0; // Ensure isLaunching will be true for the OOM, no matter how long it takes to occur.
self.config.appType = @"vanilla";
self.config.appVersion = @"3.2.1";
self.config.bundleVersion = @"321.123";
self.config.releaseStage = @"staging";
[self.config addMetadata:@{@"bar": @"foo"} toSection:@"custom"];
[self.config setUser:@"foobar" withEmail:@"foobar@example.com" andName:@"Foo Bar"];
[self.config addOnSendErrorBlock:^BOOL(BugsnagEvent *event) {
Expand Down

0 comments on commit a91c9a1

Please sign in to comment.