call method

  1. @override
Future<void> call(
  1. Hub hub,
  2. SentryOptions options
)
override

A Callable method for the Integration interface

Implementation

@override
Future<void> call(Hub hub, SentryOptions options) {
  final completer = Completer<void>();

  runZonedGuarded(
    () async {
      try {
        await _runner();
      } finally {
        completer.complete();
      }
    },
    (exception, stackTrace) async {
      await captureError(hub, options, exception, stackTrace);
      final onError = _onError;
      if (onError != null) {
        await onError(exception, stackTrace);
      }
    },
    zoneSpecification: ZoneSpecification(
      print: (self, parent, zone, line) {
        if (!options.enablePrintBreadcrumbs || !hub.isEnabled) {
          // early bail out, in order to better guard against the recursion
          // as described below.
          parent.print(zone, line);
          return;
        }

        if (_isPrinting) {
          // We somehow landed in a recursion.
          // This happens for example if:
          // - hub.addBreadcrumb() called print() itself
          // - This happens for example if hub.isEnabled == false and
          //   options.logger == dartLogger
          //
          // Anyway, in order to not cause a stack overflow due to recursion
          // we drop any further print() call while adding a breadcrumb.
          parent.print(
            zone,
            'Recursion during print() call. '
            'Abort adding print() call as Breadcrumb.',
          );
          return;
        }

        _isPrinting = true;

        try {
          hub.addBreadcrumb(
            Breadcrumb.console(
              message: line,
              level: SentryLevel.debug,
            ),
          );

          parent.print(zone, line);
        } finally {
          _isPrinting = false;
        }
      },
    ),
  );

  options.sdk.addIntegration('runZonedGuardedIntegration');

  return completer.future;
}