Skip to content

Null safety update prevents processors nulling out events #351

@mjohnsullivan

Description

@mjohnsullivan

We use the following processor to stop events being sent to Sentry in debug/development:

Future<void> initializeSentry(String release, String environment, String dsn,
        {FutureOr<void> Function() runApp, Transport transport}) =>
    Sentry.init(
      (options) => options
        ..dsn = dsn
        ..release = release
        ..environment = environment
        ..transport = transport ?? options.transport
        ..addEventProcessor(_noEventInDebug),
      appRunner: runApp,
    );

SentryEvent _noEventInDebug(SentryEvent event, {dynamic hint}) {
  return isInDebugMode || disableSentry ? null : event;
}

Prior to null safety this worked as expected, with this test passing:

class MockTransport extends Mock implements Transport {}

  test('No sentry events should be sent in debug mode', () async {
    expect(isInDebugMode, isTrue);
    expect(overrideDisableSentry, isNull);

    await initializeSentry('release', 'env', fakeDsn, transport: transport);

    expect(Sentry.isEnabled, isTrue);

    final event = SentryEvent();
    await Sentry.captureEvent(event);

    final callCount = verifyNever(
      transport.send(captureAny),
    ).callCount;

    expect(callCount, 0);
  });

However, when upgrading to null safety version of the package, this test now fails.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions