View Source Sentry.PlugCapture (Sentry v11.0.4)
Ensures proper error reporting for Plug applications that use Cowboy.
It is intended for usage with Sentry.PlugContext, which adds relevant request
metadata to the Sentry context before errors are captured.
Only for Cowboy
Sentry.PlugCaptureis only recommended for Cowboy applications. For applications running on Bandit, which is the most recent default webserver in Phoenix,Sentry.PlugContextshould be enough, and usingSentry.PlugCapturemight result in duplicate errors.
Usage
With Phoenix
In a Phoenix application, it is important to use this module before
the Phoenix endpoint itself. It should be added to your endpoint.ex file:
defmodule MyApp.Endpoint
use Sentry.PlugCapture
use Phoenix.Endpoint, otp_app: :my_app
# ...
endWith Plug
In a Plug application, you can add this module below your router:
defmodule MyApp.PlugRouter do
use Plug.Router
use Sentry.PlugCapture
# ...
end
use Sentry.PlugCaptureWhen you
use Sentry.PlugCapture, Sentry overrides yourPlug.call/2callback and adds capturing errors and reporting to Sentry. You can still re-override that callback afteruse Sentry.PlugCaptureif you need to.
Scrubbing Sensitive Data
Since v9.1.0
Scrubbing sensitive data in
Sentry.PlugCaptureis available since v9.1.0 of this library.
Like Sentry.PlugContext, this module also supports scrubbing sensitive data
out of errors. However, this module has to do some guessing to figure
out if there are Plug.Conn structs to scrub. Right now, the strategy we
use follows these steps:
- if the error is
Phoenix.ActionClauseError, we scrub thePlug.Connstructs from theargsfield of that exception
Otherwise, we don't perform any scrubbing. To configure scrubbing, you can use the
:scrubbing option (see below).
Options
:scrubber(since v9.1.0) - a term of type{module, function, args}that will be invoked to scrub sensitive data fromPlug.Connstructs. ThePlug.Connstruct is prepended toargsbefore invoking the function, so that the final function will be called asapply(module, function, [conn | args]). The function must return aPlug.Connstruct. By default, the built-in scrubber does this:- scrubs all cookies
- scrubs sensitive headers just like
Sentry.PlugContext.default_header_scrubber/1 - scrubs sensitive body params just like
Sentry.PlugContext.default_body_scrubber/1