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

**Internal module.** Not part of TraceGuard's public API: it may change in
any release. Use the functions in `TraceGuard` instead.

A bounded record of recent report drops, and of submissions that were
accepted but are not yet stored.

It is used by `TraceGuard.report_status/1` and `TraceGuard.await_report/2`
to tell a report that was **dropped** apart from one that is **pending**
or simply **not observed**.

## What is recorded

* **Drops:** `{trace_id, reason}`, recorded when the storage facade or an
  adapter reports one (`TraceGuard.Storage.dropped/2`), including
  `reason: :lost` for submissions that were accepted but died with a
  crashed store. Nothing else about the request is stored. Reasons are
  normalized to atoms, small tuples of atoms, integers and short strings;
  anything else becomes `:other`.
* **Pending:** trace IDs submitted to an adapter that queues reports,
  removed as soon as the report is stored or dropped.

## Bounds and expiry

* At most `:max_drop_records` drop records (default 1000). The oldest is
  evicted first. Under concurrent writers, racing evictions can leave the
  count below the limit, by up to the number of concurrent writers (41 of
  50 has been observed with 64 writers). It is never above the limit for
  longer than one insert.
* A drop record expires after `:drop_record_ttl` ms (default 600_000),
  measured with the monotonic clock. Expired records are treated as absent
  on lookup and removed by a periodic sweep.
* At most `:max_drop_records` pending entries. Pending entries older than
  `:drop_record_ttl` are removed (not turned into drops: a missing outcome
  is never reported as a drop).

**An expired or evicted record means "unknown", never "not dropped".** The
absence of a record is not evidence of anything.

## Concurrency

The tables are public ETS tables owned by this process. Writers (request
processes, store processes) insert directly, so there is no mailbox in
the write path. If this process restarts, its records are lost and lookups
answer "unknown" for them.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `lookup`

```elixir
@spec lookup(String.t()) :: {:dropped, term()} | :none
```

`{:dropped, reason}` if a live drop record exists, else `:none`.

# `lost_pending`

```elixir
@spec lost_pending(module()) :: non_neg_integer()
```

For a restarted adapter: every submission still pending for `adapter` was
lost with the previous incarnation. Records each as a `:lost` drop and
returns how many there were.

# `pending`

```elixir
@spec pending(String.t(), module()) :: :ok
```

Marks `trace_id` as submitted to `adapter` and awaiting an outcome.

# `pending?`

```elixir
@spec pending?(String.t()) :: boolean()
```

True while `trace_id` was submitted and has no outcome yet.

# `record_drop`

```elixir
@spec record_drop(String.t(), term()) :: :ok
```

Records that `trace_id`'s report was dropped for `reason`.

# `resolve`

```elixir
@spec resolve(String.t()) :: :ok
```

Clears the pending mark of `trace_id` (stored, or refused synchronously).

# `sizes`

```elixir
@spec sizes() :: %{drop_records: non_neg_integer(), pending: non_neg_integer()}
```

Current table sizes.

---

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