# `PhoenixReplay.Capture.TelemetryEvents`
[🔗](https://github.com/elixir-vibe/phoenix_replay/blob/v0.6.2/lib/phoenix_replay/capture/telemetry_events.ex#L1)

Records telemetry events captured by the configured `PhoenixReplay.Collector`s.

Each collector is attached once, when the application starts. Its handler
runs in the process that emitted the event and handles it in a fixed
order:

  1. Finds the session of the emitting process, or of the first of its
     `$callers` that has one, so `start_async/3`, `assign_async/3` and
     `Task` work belongs to the LiveView that started it. Events no
     session claims stop here, at the cost of one ETS lookup per process.
  2. Lets the collector capture or skip the event.
  3. Passes captured metadata through the session's
     `PhoenixReplay.Sanitizer`. Text such as SQL is masked later, when
     the recording is saved, by the session's `PhoenixReplay.Redactor`.
  4. Records a `:telemetry` event, unless the collector reached its
     `:limit` for the session, in which case the event is counted as
     dropped.

`:telemetry` permanently detaches a handler that raises, so a collector
that raises is reported with `[:phoenix_replay, :collector, :exception]`
instead; see `PhoenixReplay.Telemetry`.

# `attach`

```elixir
@spec attach(PhoenixReplay.Config.t(), term()) :: :ok
```

Attaches the configured collectors. Called by `PhoenixReplay.Capture.Handlers`.

Handlers are identified by `{prefix, index}`.

# `callers`

```elixir
@spec callers() :: [pid()]
```

The `$callers` of the current process, which `Task` sets.

# `detach`

```elixir
@spec detach(term()) :: :ok
```

Detaches the collectors attached with `prefix`.

# `handle_event`

```elixir
@spec handle_event([atom()], map(), map(), {module(), keyword(), pos_integer()}) ::
  :ok
```

Handles a telemetry event for a collector.

---

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