Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLAT-6391] Fix OOM app info #1078

Merged
merged 2 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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