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

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

Attaches TraceGuard's handlers to selected `:telemetry` events.

| Telemetry event                              | Timeline event                    |
| -------------------------------------------- | --------------------------------- |
| `[:phoenix, :endpoint, :start]`              | `phoenix.endpoint.start`          |
| `[:phoenix, :endpoint, :stop]`               | `phoenix.endpoint.stop`           |
| `[:phoenix, :router_dispatch, :start]`       | `phoenix.router_dispatch.start`   |
| `[:phoenix, :router_dispatch, :stop]`        | `phoenix.router_dispatch.stop`    |
| `[:phoenix, :router_dispatch, :exception]`   | `phoenix.router_dispatch.exception` + failure |
| `[:phoenix, :error_rendered]`                | `phoenix.error_rendered` + failure (fallback) |
| `prefix ++ [:query]` per configured Ecto repo | `ecto.query`                     |

## Metadata filtering

Telemetry metadata routinely contains the whole `Plug.Conn`, Ecto query
parameters, results and options. Handlers never store metadata maps
wholesale: each handler copies an explicit allow-list of fields, converted
to plain strings and numbers.

## Safety

Handlers run synchronously in the emitting (request) process. They only
touch that process's dictionary, do no I/O, and rescue every error;
`:telemetry` permanently detaches handlers that raise, which would silently
disable tracing.

# `attach`

```elixir
@spec attach() :: :ok
```

Attaches (or re-attaches) the handlers for the current configuration.

Idempotent and safe to call concurrently: detach + attach is not atomic in
`:telemetry`, so callers are serialized with a node-local lock.

# `detach`

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

Detaches TraceGuard's handlers.

# `events`

```elixir
@spec events(TraceGuard.Config.t()) :: [[atom()]]
```

The telemetry events TraceGuard attaches to for the given configuration.

---

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