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

Apply beforeBreadcrumb on native iOS crumbs #1914

Merged
merged 5 commits into from
Mar 7, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- Use `recordHttpBreadcrumbs` to set iOS `enableNetworkBreadcrumbs` ([#1884](https://github.com/getsentry/sentry-dart/pull/1884))
- Apply `beforeBreadcrumb` on native iOS crumbs ([#1914](https://github.com/getsentry/sentry-dart/pull/1914))
buenaflor marked this conversation as resolved.
Show resolved Hide resolved

### Improvements

Expand Down
12 changes: 11 additions & 1 deletion flutter/lib/src/integrations/load_contexts_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,23 @@ class _LoadContextsIntegrationEventProcessor implements EventProcessor {
final breadcrumbsJson =
List<Map<dynamic, dynamic>>.from(breadcrumbsList);
final breadcrumbs = <Breadcrumb>[];
final beforeBreadcrumb = _options.beforeBreadcrumb;

for (final breadcrumbJson in breadcrumbsJson) {
final breadcrumb = Breadcrumb.fromJson(
Map<String, dynamic>.from(breadcrumbJson),
);
breadcrumbs.add(breadcrumb);

if (beforeBreadcrumb != null) {
final processedBreadcrumb = beforeBreadcrumb(breadcrumb);
if (processedBreadcrumb != null) {
breadcrumbs.add(processedBreadcrumb);
}
} else {
breadcrumbs.add(breadcrumb);
}
}

event = event.copyWith(breadcrumbs: breadcrumbs);
}

Expand Down
36 changes: 36 additions & 0 deletions flutter/test/integrations/load_contexts_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,42 @@ void main() {
expect(event.breadcrumbs!.length, 1);
expect(event.breadcrumbs!.first.message, 'event');
});

test('apply beforeBreadcrumb to native breadcrumbs', () async {
fixture.options.enableScopeSync = true;
fixture.options.beforeBreadcrumb = (breadcrumb, {hint}) {
if (breadcrumb?.message == 'native-mutated') {
return breadcrumb?.copyWith(message: 'native-mutated-applied');
} else {
return null;
}
};

final eventBreadcrumb = Breadcrumb(message: 'event');
var event = SentryEvent(breadcrumbs: [eventBreadcrumb]);

final nativeMutatedBreadcrumb = Breadcrumb(message: 'native-mutated');
final nativeDeletedBreadcrumb = Breadcrumb(message: 'native-deleted');
Map<String, dynamic> loadContexts = {
'breadcrumbs': [
nativeMutatedBreadcrumb.toJson(),
nativeDeletedBreadcrumb.toJson(),
]
};

final future = Future.value(loadContexts);
when(fixture.methodChannel.invokeMethod<dynamic>('loadContexts'))
.thenAnswer((_) => future);
// ignore: deprecated_member_use
_channel.setMockMethodCallHandler((MethodCall methodCall) async {});

final integration = LoadContextsIntegration(fixture.methodChannel);
integration.call(fixture.hub, fixture.options);
event = (await fixture.options.eventProcessors.first.apply(event))!;

expect(event.breadcrumbs!.length, 1);
expect(event.breadcrumbs!.first.message, 'native-mutated-applied');
});
});
}

Expand Down
Loading