# `PhoenixReplay.Session.TailSampling`
[🔗](https://github.com/elixir-vibe/phoenix_replay/blob/v0.6.2/lib/phoenix_replay/session/tail_sampling.ex#L1)

Decides whether a session is saved, from the `:keep` configuration.

A session matching `errors: true` or `slower_than: ms` is always saved.
Otherwise a session without user interaction is discarded, and the
`:rate` share of the rest is saved. See "Tail sampling" in
`PhoenixReplay.Config`.

The decision only ever turns from discard to keep as events arrive: once
a session is kept, later events cannot discard it. That lets
`PhoenixReplay.Session.Monitor` start writing a running session to
storage as soon as it is kept, observing its events incrementally with
`observe/3` and `decision/3`.

# `observation`

```elixir
@type observation() :: %{
  event?: boolean(),
  params: non_neg_integer(),
  flagged?: boolean(),
  state_keys: MapSet.t(String.t())
}
```

What `observe/3` has seen of a session's events so far.

# `reason`

```elixir
@type reason() :: :not_interactive | :not_sampled
```

# `decide`

```elixir
@spec decide(PhoenixReplay.Recording.t(), PhoenixReplay.Config.keep(), float()) ::
  :keep | {:discard, reason()}
```

Decides for a whole recording. See `decision/3`.

# `decision`

```elixir
@spec decision(observation(), PhoenixReplay.Config.keep(), float()) ::
  :keep | {:discard, reason()}
```

Decides from an observation, given a uniform `draw` in `0.0..1.0` for
`:rate`.

A session is interactive once it handled an event, navigated within the
LiveView, that is, after more than its initial `handle_params/3`, had a
form control changed, or changed client state it had reported before;
see `PhoenixReplay.Capture.State`.

# `new`

```elixir
@spec new() :: observation()
```

An observation of no events.

# `observe`

```elixir
@spec observe(
  observation(),
  [PhoenixReplay.Recording.Event.t()],
  PhoenixReplay.Config.keep()
) ::
  observation()
```

Adds `events` to an observation.

---

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