AuditTrail.DeadLetter (audit_trail v0.1.2)

Copy Markdown

In-memory holding queue for logs that couldn't be shipped (currently only populated by AuditTrail.Shipper when the Loki adapter exhausts its retries — see shipper_retries in the README's buffer-tuning config).

Entries are retried automatically on a timer (dead_letter_redrive_interval, default 30s). This module is for inspecting/managing that queue directly — e.g. from iex in production, or an admin LiveView:

AuditTrail.DeadLetter.count()
#=> 42

AuditTrail.DeadLetter.dump()
#=> [%{event_type: "item:approved", ...}, ...]

# Loki was down, you just brought it back — don't wait for the timer
AuditTrail.DeadLetter.redrive()

# Give up on these entries entirely (e.g. Loki config changed, they'll
# never deliver)
AuditTrail.DeadLetter.clear()

Capacity is capped at max_dead_letter (default 10,000) — beyond that, new entries are dropped (logged via Logger.warning, and a [:audit_trail, :dead_letter, :dropped] telemetry event — see the README's "Telemetry" section) rather than growing unbounded.

By default this queue is ETS-backed and does not survive a node restart — entries queued when the node goes down are lost. Set dead_letter_persistent: true (see AuditTrail.Config.dead_letter_persistent?/0) to back it with :dets instead, so queued entries are reloaded from disk on the next boot. Using the Postgres or TimescaleDB adapter instead of Loki avoids needing this queue at all.

Summary

Functions

Returns a specification to start this module under a supervisor.

Discards every queued entry without attempting delivery. Irreversible.

Returns how many entries are currently queued.

Returns every entry currently queued — the raw log maps, same shape AuditTrail.Logger builds them in.

Queues entries for retry. Called by AuditTrail.Shipper on delivery failure — not typically called directly.

Manually triggers a redrive attempt right now, instead of waiting for the next scheduled tick (dead_letter_redrive_interval, default 30s). Useful right after you've confirmed Loki/the adapter is back up. Asynchronous — check count/0 afterward (with a short delay) to confirm entries drained.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

Discards every queued entry without attempting delivery. Irreversible.

count()

Returns how many entries are currently queued.

dump()

Returns every entry currently queued — the raw log maps, same shape AuditTrail.Logger builds them in.

push(entries)

Queues entries for retry. Called by AuditTrail.Shipper on delivery failure — not typically called directly.

redrive()

Manually triggers a redrive attempt right now, instead of waiting for the next scheduled tick (dead_letter_redrive_interval, default 30s). Useful right after you've confirmed Loki/the adapter is back up. Asynchronous — check count/0 afterward (with a short delay) to confirm entries drained.