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

Fix missing OS context for iOS events #958

Merged
merged 4 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 10 additions & 1 deletion flutter/lib/src/default_integrations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,19 @@ class _LoadContextsIntegrationEventProcessor extends EventProcessor {
contexts.forEach(
(key, dynamic value) {
if (value != null) {
final currentValue = eventContexts[key];
if (key == SentryRuntime.listType) {
contexts.runtimes.forEach(eventContexts.addRuntime);
} else if (eventContexts[key] == null) {
} else if (currentValue == null) {
eventContexts[key] = value;
} else {
if (key == SentryOperatingSystem.type &&
currentValue is SentryOperatingSystem &&
value is SentryOperatingSystem) {
final osMap = {...value.toJson(), ...currentValue.toJson()};
final os = SentryOperatingSystem.fromJson(osMap);
eventContexts[key] = os;
Comment on lines +194 to +199
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a quick workaround for now, the whole process of merging contexts from the Native and Dart layer should be done differently.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the issue?

Copy link
Contributor Author

@marandaneto marandaneto Jul 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#942
Flutter sets the os.theme by default, so when merging the contexts, it does not take the os from the iOS layer since we don't merge field per field recursively, but rather if the key exists or not.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I see. Yeah, that's a stupid behavior.

}
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions flutter/test/load_contexts_integrations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ void main() {
expect(fixture.options.eventProcessors.length, 1);

final e = SentryEvent();
e.contexts.operatingSystem = SentryOperatingSystem(theme: 'theme1');
final event = await fixture.options.eventProcessors.first.apply(e);

expect(fixture.called, true);
expect(event?.contexts.device?.name, 'Device1');
expect(event?.contexts.app?.name, 'test-app');
expect(event?.contexts.operatingSystem?.name, 'os1');
expect(event?.contexts.operatingSystem?.theme, 'theme1');
expect(event?.contexts.gpu?.name, 'gpu1');
expect(event?.contexts.browser?.name, 'browser1');
expect(
Expand Down