# `TraceGuard.ReportStore`
[🔗](https://github.com/HataluliRandima/trace_guard/blob/v0.1.0/lib/trace_guard/report_store.ex#L1)

The default `TraceGuard.Storage` adapter: a bounded, in-memory store of
finished (already redacted) reports in one GenServer.

## Bounds

* **Retained reports:** at most `:max_reports`; the oldest is evicted first.
* **Queued submissions:** at most `:max_pending_reports`. Admission happens
  in the *submitting* process, before anything is sent: each store
  incarnation publishes its pid and an `:atomics` counter once (in
  `:persistent_term`). A submitter increments the counter and only sends
  if the result is within the limit; the store decrements it as it takes
  each submission. When the limit is reached, `put/2` returns
  `{:error, :overloaded}` immediately and nothing is sent. The store's
  mailbox therefore never holds more than `:max_pending_reports`
  submissions, however many requests fail at once. (Reads are synchronous
  calls and add at most one message per waiting caller.)
* **Waiting:** `put/2` never waits. Reads wait at most the facade's
  `:timeout`, else `:call_timeout` (adapter option, default 5000 ms), and
  return `{:error, :unavailable}` instead of exiting.

## Outcomes

* `{:ok, :queued}` means admitted; `[:trace_guard, :report, :stored]` is
  emitted once it is retained.
* `{:error, :overloaded}`: the queue is full; the report is not kept.
* `{:error, :unavailable}`: no live store (for example while it restarts).

## Restarts

The store is supervised. A restart loses the retained reports and any
admitted submissions still queued. Those submissions are recorded as drops
with reason `:lost` (by trace ID, see `TraceGuard.DropLog`) and counted in
the `:lost` statistic. The new
incarnation starts with an empty queue and a fresh admission counter.
Nothing is written to disk or sent over the network.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
