diff --git a/CHANGELOG.md b/CHANGELOG.md index d4f64c8c5e..fb95b51cb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Bump: sentry-android to v4.3.0 (#343) * Fix: Multiple FlutterError.onError calls in FlutterErrorIntegration (#345) +* Fix: EventProcessors were not dropping events when returning null (#353) # 4.1.0-nullsafety.0 diff --git a/dart/lib/src/scope.dart b/dart/lib/src/scope.dart index b285fbf6a5..e780714db5 100644 --- a/dart/lib/src/scope.dart +++ b/dart/lib/src/scope.dart @@ -182,7 +182,7 @@ class Scope { SentryEvent? processedEvent = event; for (final processor in _eventProcessors) { try { - processedEvent = await processor(processedEvent!, hint: hint)!; + processedEvent = await processor(processedEvent!, hint: hint); } catch (err) { _options.logger( SentryLevel.error, diff --git a/dart/lib/src/sentry_client.dart b/dart/lib/src/sentry_client.dart index 8da02d78b1..472effd40a 100644 --- a/dart/lib/src/sentry_client.dart +++ b/dart/lib/src/sentry_client.dart @@ -179,7 +179,7 @@ class SentryClient { SentryEvent? processedEvent = event; for (final processor in eventProcessors) { try { - processedEvent = await processor(processedEvent!, hint: hint)!; + processedEvent = await processor(processedEvent!, hint: hint); } catch (err) { _options.logger( SentryLevel.error, diff --git a/dart/test/scope_test.dart b/dart/test/scope_test.dart index f5c7252208..ed1b6b25a9 100644 --- a/dart/test/scope_test.dart +++ b/dart/test/scope_test.dart @@ -404,6 +404,17 @@ void main() { expect(updatedEvent?.level, SentryLevel.error); }); }); + + test('event processor drops the event', () async { + final sut = fixture.getSut(); + + sut.addEventProcessor(fixture.processor); + + final event = SentryEvent(); + var newEvent = await sut.applyToEvent(event, null); + + expect(newEvent, isNull); + }); } class Fixture { diff --git a/dart/test/sentry_client_test.dart b/dart/test/sentry_client_test.dart index 0c99b0cd85..2be85ffc9c 100644 --- a/dart/test/sentry_client_test.dart +++ b/dart/test/sentry_client_test.dart @@ -507,6 +507,14 @@ void main() { ); expect(event.fingerprint!.contains('process'), true); }); + + test('event processor drops the event', () async { + options.addEventProcessor(eventProcessorDropEvent); + final client = SentryClient(options); + await client.captureEvent(fakeEvent); + + expect((options.transport as MockTransport).called(0), true); + }); }); } @@ -523,3 +531,7 @@ SentryEvent beforeSendCallback(SentryEvent event, {dynamic hint}) { ..sdk!.addIntegration('testIntegration') ..sdk!.addPackage('test-pkg', '1.0'); } + +SentryEvent? eventProcessorDropEvent(SentryEvent event, {dynamic hint}) { + return null; +}