init static method

Future<void> init(
  1. OptionsConfiguration optionsConfiguration, {
  2. AppRunner? appRunner,
  3. @internal bool callAppRunnerInRunZonedGuarded = true,
  4. @internal RunZonedGuardedOnError? runZonedGuardedOnError,
  5. @internal SentryOptions? options,
})

Initializes the SDK passing a AppRunner callback allows to run the app within its own error zone (runZonedGuarded)

Implementation

static Future<void> init(
  OptionsConfiguration optionsConfiguration, {
  AppRunner? appRunner,
  @internal bool callAppRunnerInRunZonedGuarded = true,
  @internal RunZonedGuardedOnError? runZonedGuardedOnError,
  @internal SentryOptions? options,
}) async {
  final sentryOptions = options ?? SentryOptions();

  await _initDefaultValues(sentryOptions);

  try {
    final config = optionsConfiguration(sentryOptions);
    if (config is Future) {
      await config;
    }
    _taskQueue = DefaultTaskQueue<SentryId>(
      sentryOptions.maxQueueSize,
      sentryOptions.logger,
      sentryOptions.recorder,
    );
  } catch (exception, stackTrace) {
    sentryOptions.logger(
      SentryLevel.error,
      'Error in options configuration.',
      exception: exception,
      stackTrace: stackTrace,
    );
    if (sentryOptions.automatedTestMode) {
      rethrow;
    }
  }

  if (sentryOptions.dsn == null) {
    throw ArgumentError('DSN is required.');
  }

  await _init(sentryOptions, appRunner, callAppRunnerInRunZonedGuarded,
      runZonedGuardedOnError);
}