Recipes
Limiting repeated external reports
Keep per-incident handling while bounding external calls, groups and waiting.
Reporting controls are available starting with core 1.3.0.
Use a reporting rule when repeated failures would flood an external monitoring service, while your application must still handle each failure. For example, 30 failed catalogue loads can produce 30 local log entries but only one initial external report and a summary of 29 repeats. Each occurrence still receives its own policy, presentation and recovery decisions.
Run the complete example
From the package root, run:
dart run example/reporting_controls.dart
Expected output:
Local reports: 30
External first reports: 1
External summaries: 1
Repeats in summary: 29
The example uses two in-process receivers, not a monitoring account or a network
connection. It feeds 30 errors through the application boundary and calls
close, so it does not wait ten seconds for the grouping window. In a running
application a timer emits the summary when that fixed window expires.
Choose the receiver and its limits
Keep the ordinary reporters list. Add a rule referring to the exact receiver
instance you want to control; leave your local receiver without a rule:
ErrorManagerConfiguration(
environment: environment,
reporters: <ErrorReporter>[localReporter, remoteReporter],
reportingRules: <ErrorReportingRule>[
ErrorReportingRule(
reporter: remoteReporter,
grouping: const CatalogReportGrouping(),
window: const Duration(seconds: 10),
maxGroups: 128,
maxAttempts: 20,
attemptInterval: const Duration(minutes: 1),
deliveryTimeout: const Duration(seconds: 2),
),
],
)
environment, localReporter and remoteReporter above belong to the application;
the runnable example provides complete implementations. All five limits are
required and positive. These values illustrate a choice, not package defaults.
| Setting | Meaning |
|---|---|
window | Fixed lifetime of a group. Repeated errors do not extend it. |
maxGroups | Maximum retained groups for this receiver. Full groups are not evicted to admit another key. |
maxAttempts | Maximum receiver calls started in a rolling attemptInterval. Failed calls and summaries also consume attempts. |
attemptInterval | Sliding quota period, not a calendar minute reset. |
deliveryTimeout | How long the pipeline waits. The receiver's underlying work is not cancelled. |
A controlled receiver must occur exactly once in reporters and have exactly
one rule. Identity, not custom ==, determines the match. With no rules, the
existing reporting behavior is unchanged. Managers have independent counters
even when they share the same immutable configuration.
Define which errors belong together
final class CatalogReportGrouping implements ErrorReportGrouping {
const CatalogReportGrouping();
static final ErrorReportGroupKey _load = ErrorReportGroupKey('catalog.load');
@override
ErrorReportGroupKey? groupFor(final ErrorReport report) =>
report.operation == 'catalog.load' ? _load : null;
}
The callback sees only the sanitized ErrorReport. This example deliberately
uses one known operation, not arbitrary exception messages. Returning null
disables grouping for that event, but the receiver's quota and single-flight
protection still apply.
Keys are case-sensitive value objects with 1–128 characters and no surrounding whitespace. Empty or whitespace-only keys are rejected without including the bad value in the exception. The key itself is never copied into summaries or control diagnostics. Do not use personal data or unbounded request IDs as keys. The manager additionally separates sanitized category, severity and capture source, so those differences cannot disappear behind a shared application key.
Understand the first report and subsequent summaries
The first eligible event is sent immediately. Its original sanitized fields
are preserved; aggregation.kind is representative. A repeat increments a
bounded counter instead of calling that receiver again. It does not suppress
the occurrence's other reporters, Presenter, recovery controller or observers.
A summary contains only the count since the previous summary decision, opaque
groupId, sanitized UTC capture times and the first attempt's observed outcome.
Its fixed ErrorReportSummary type and message do not copy the original error
message. operation is null; context and stackTrace are empty because this
is not a new exception. Assessment/source come from the first sanitized report;
environment identity is copied from that report with at most 128 characters
per field. A custom sanitizer's blank/null identity remains hidden. A summary
never restores a raw incident ID; the shared groupId links it to the first
report. IDs are local correlations, not acknowledgments.
The first report says firstAttemptOutcome: pending; the later summary records
completed, failed, or unknown. Normal Future completion means that the
adapter returned normally, not that a provider persisted the report. A timeout
leaves the outcome unknown, even if a late completion is observed later.
If the first call failed, repeats are still grouped until the window ends;
the summary does not reconstruct the lost original description.
Counts saturate at 2,147,483,647 and set saturated; treat that count as a lower
bound. Each consumed delta resets independently, so later repeats remain visible.
A first-only group produces neither an empty summary nor an expiry timer just
to delete its metadata.
What happens when sending is not possible
| Situation | Result |
|---|---|
| Quota exhausted | Skip the report or summary; no retry queue. A rejected first report does not occupy a group slot. |
| All group slots occupied | Skip a new group, preserve existing active groups. |
| Grouping throws | Record a reporting pipeline failure and skip this receiver; never bypass its limits. |
| Receiver throws | Spend the attempt, record failure, continue other actions. |
| Receiver times out | Continue the pipeline, but reserve its physical call slot until its actual Future settles. |
| Another event arrives while that Future is pending | Skip with reporterBusy; do not retain its payload for later delivery. |
| The old Future settles | Release the slot and record a late outcome while active; do not resend automatically. |
The effective wait is the shorter of deliveryTimeout and an explicitly set
ErrorPipelineTimeouts.reporting. An unresolved receiver can stay blocked
indefinitely without blocking other receivers or UI after its wait expires.
The package cannot interrupt synchronous CPU work or control background work
that an adapter hides behind an already completed Future.
Flush and shutdown
handleError completes after its own pipeline actions, not after a grouping
window. flush inserts a barrier after currently accepted work and consumes
pending repeat deltas, including open windows. Future intake cannot keep that
barrier waiting indefinitely. Flush does not reset the window or the quota.
Skipped or failed deltas are consumed too: another flush is not a retry.
close immediately rejects new intake and stops new timers, drains accepted
work, attempts remaining summaries with the same limits and clears group state.
It is idempotent and does not close application-owned receivers or clients.
Late receiver results after shutdown are consumed without new user callbacks.
Neither method proves remote delivery. Other pipeline stages without configured
wait limits can still hold shutdown open.
Inspect decisions without exporting payloads
Rules accept ErrorReportingObserver implementations with synchronous
onEvent(ErrorReportingEvent event). Events contain rule index, opaque group
identity when relevant, typed decision and numeric metadata, not errors or keys.
Keep callbacks short. A throwing observer uses the local pipeline failure
handler and does not re-enter error capture.
manager.reportingStatistics is an immutable per-rule list. Each snapshot has
count(ErrorReportingEventKind...), group/attempt occupancy, receiver busy
state, clock validity, cumulative wait and maximum wait. Occupancy is swept
on control work; an expired quiet group can still appear until that sweep.
There is no unbounded event or latency history inside the manager.
Close clears occupancy; cumulative decision totals remain available. A cleared
slot after close does not mean application-owned network work was cancelled.
Windows and quota use a private monotonic Stopwatch, not wall-clock capture
times. Tests can inject ErrorReportingClock and coordinated Zone timers. A
negative, decreasing or throwing elapsed clock disables controlled sends for
that manager and records a failure; it cannot reopen a spent quota.
Privacy and ownership checklist
The group retains no original report, incident, exception, context or UI tree.
The receiver must re-check current consent on every actual call, including
summaries. A policy decision made for an earlier occurrence is not a durable
authorization to send later. Provider credentials, retention, persistence,
vendor mapping of aggregation, retries and delivery acknowledgments remain
application responsibilities.
ErrorPipelineFailure is an application-local channel and can contain the raw
exception thrown by an adapter. Do not forward it automatically to an external
monitor in place of sanitized ErrorReport. Reporting controls do not reduce
classification/context/sanitization costs or replace bounded intake.