# `Faulty.Integrations.Plug`
[🔗](https://github.com/Hermanverschooten/faulty/blob/main/lib/faulty/integrations/plug.ex#L2)

Integration with Plug applications.

## How to use it

### Plug applications

The way to use this integration is by adding it to either your `Plug.Builder`
or `Plug.Router`:

```elixir
defmodule MyApp.Router do
  use Plug.Router
  use Faulty.Integrations.Plug

  ...
end
```

### Phoenix applications

There is a particular use case which can be useful when running a Phoenix
web application.

If you want to record exceptions that may occur in your application's endpoint
before reaching your router (for example, in any plug like the ones decoding
cookies of body contents) you may want to add this integration too:

```elixir
defmodule MyApp.Endpoint do
  use Phoenix.Endpoint
  use Faulty.Integrations.Plug

  ...
end
```

### Default context

By default we store some context for you on errors generated during a Plug
request:

* `request.host`: the `conn.host` value.

* `request.ip`: the IP address that initiated the request. It includes parsing
proxy headers

* `request.method`: the HTTP method of the request.

* `request.path`: the path of the request.

* `request.query`: the query string of the request.

* `request.params`: parsed params of the request (only available if they have
been fetched and parsed as part of the Plug pipeline).

* `request.headers`: headers received on the request. All headers are included
by default except for the `Cookie` ones, as they may include large and
sensitive content like sessions. Sensitive headers such as `Authorization` and
`X-Api-Key` have their value replaced, see `Faulty.Scrubber`.

---

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