report method

Future<bool> report(
  1. ReportEvent event
)

Reports (delivers) a pre-built ReportEvent via the configured pipeline, respecting policy. Returns true if at least one reporter successfully delivered the event.

On delivery failure or when rate-limited, the event is persisted to the outbox.

Implementation

Future<bool> report(ReportEvent event) async {
  final cfg = _ensureConfig();

  // Basic policy gate: severity threshold and handled/unhandled allowance.
  if (!cfg.policy.shouldSend(event, cfg.environment)) {
    return false;
  }

  // Sampling (0..1). If sampling < 1.0, probabilistically drop.
  if (cfg.policy.sampling < 1.0 && _rng.nextDouble() > cfg.policy.sampling) {
    return false;
  }

  // Dedupe: drop events with the same primary fingerprint within the dedupe window.
  final primaryFingerprint = _primaryFingerprintOf(event);
  if (primaryFingerprint != null &&
      _dedupeIndex.isDuplicate(primaryFingerprint)) {
    return false;
  }

  // Rate-limit: if the window is saturated, persist to outbox for later.
  if (!_rateLimiter.allow()) {
    await _outbox.enqueue(event);
    return false;
  }

  // Attempt delivery.
  final ok = await _pipeline!.send(event);
  if (!ok) {
    await _outbox.enqueue(event);
  }
  return ok;
}