install static method

DVCrashReporting? install({
  1. required String appId,
  2. required String release,
  3. required DVProcessRole role,
  4. required DVCrashStore store,
  5. required String installId,
  6. DVCrashConfig config = const DVCrashConfig(),
  7. DVCrashSink? sink,
  8. String? platform,
  9. void onDiagnostic(
    1. String code,
    2. String message
    )?,
})

Installs the reporter for appId at release in a role process.

Returns null, having said DV-CRASH-009, when config disables this build. store and installId come from the caller, because working them out needs a file system this library does not assume.

Implementation

static DVCrashReporting? install({
  required String appId,
  required String release,
  required DVProcessRole role,
  required DVCrashStore store,
  required String installId,
  DVCrashConfig config = const DVCrashConfig(),
  DVCrashSink? sink,
  String? platform,
  void Function(String code, String message)? onDiagnostic,
}) {
  const bool product = bool.fromEnvironment('dart.vm.product');
  const bool profile = bool.fromEnvironment('dart.vm.profile');
  final DVCrashBuildMode mode = product
      ? DVCrashBuildMode.release
      : profile
          ? DVCrashBuildMode.profile
          : DVCrashBuildMode.debug;
  if (!config.enabledIn(mode)) {
    _reporter = null;
    (onDiagnostic ?? dvLogCrashDiagnostic)(
      'DV-CRASH-009',
      'crash reporting is disabled for ${mode.name} builds of $appId, as '
          'dartvel.crashes declares',
    );
    return null;
  }
  final DVCrashReporting reporter = DVCrashReporting(
    store: store,
    sink: sink,
    context: () => DVCrashContext(
      release: release,
      installId: installId,
      platform: platform,
      deviceClass: 'server',
      role: role.name,
    ),
    breadcrumbs: config.breadcrumbs,
    nonFatalSampleRate: config.nonFatalSampleRate,
    fullReportsPerRelease: config.fullReportsPerRelease,
    flags: dvCrashFlagsSnapshot,
    onDiagnostic: onDiagnostic,
  )..install();
  _reporter = reporter;
  _queueSend();
  return reporter;
}