sentry v4.0.0 Sentry.Plug

Provides basic funcitonality to handle Plug.ErrorHandler

Usage

Add the following to your router.ex:

use Plug.ErrorLogger
use Sentry.Plug

Sending Post Body Params

In order to send post body parameters you should first scrub them of sensitive information. By default, they will be scrubbed with Sentry.Plug.default_body_scrubber/1. It can be overridden by passing the body_scrubber option, which accepts a Plug.Conn and returns a map to send. Setting :body_scrubber to nil will not send any data back. If you would like to make use of Sentry’s default scrubber behavior in a custom scrubber, it can be called directly. An example configuration may look like the following:

def scrub_params(conn) do
  # Makes use of the default body_scrubber to avoid sending password
  # and credit card information in plain text.  To also prevent sending
  # our sensitive "my_secret_field" and "other_sensitive_data" fields,
  # we simply drop those keys.
  Sentry.Plug.default_body_scrubber(conn)
  |> Map.drop(["my_secret_field", "other_sensitive_data"])
end

Then pass it into Sentry.Plug:

use Sentry.Plug, body_scrubber: &scrub_params/1

You can also pass it in as a {module, fun} like so:

use Sentry.Plug, body_scrubber: {MyModule, :scrub_params}

Please Note: If you are sending large files you will want to scrub them out.

Headers Scrubber

By default Sentry will scrub Authorization and Authentication headers from all requests before sending them. It can be configured similarly to the body params scrubber, but is configured with the :header_scrubber key.

def scrub_headers(conn) do
  # default is: Sentry.Plug.default_header_scrubber(conn)
  #
  # We do not want to include Content-Type or User-Agent in reported
  # headers, so we drop them.
  Enum.into(conn.req_headers, %{})
  |> Map.drop(["content-type", "user-agent"])
end

Then pass it into Sentry.Plug:

use Sentry.Plug, header_scrubber: &scrub_headers/1

It can also be passed in as a {module, fun} like so:

use Sentry.Plug, header_scrubber: {MyModule, :scrub_headers}

To configure scrubbing body and header data, we can set both configuration keys:

use Sentry.Plug, header_scrubber: &scrub_headers/1, body_scrubber: &scrub_params/1

Including Request Identifiers

If you’re using Phoenix, Plug.RequestId, or another method to set a request ID response header, and would like to include that information with errors reported by Sentry.Plug, the :request_id_header option allows you to set which header key Sentry should check. It will default to “x-request-id”, which Plug.RequestId (and therefore Phoenix) also default to.

use Sentry.Plug, request_id_header: "application-request-id"

Summary

Functions

build_request_interface_data(conn, opts)
build_request_interface_data(Plug.Conn.t, keyword) :: map
default_body_scrubber(conn)
default_body_scrubber(Plug.Conn.t) :: map
default_header_scrubber(conn)
default_header_scrubber(Plug.Conn.t) :: map