Connect Phoenix to Bugsink
When a Phoenix request fails, Bugsink gives you the exception, the controller frame that raised it, and the HTTP request that reached your application.
This guide adds the Elixir SDK’s Plug integration to an existing Phoenix application. You’ll configure the SDK, wrap the endpoint, and make one controller request fail to confirm that it reaches Bugsink.
To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.
Install the SDK
Add the open-source Sentry Elixir SDK and its Finch HTTP client to your Mix dependencies. Bugsink accepts the Sentry event protocol, so the SDK can send events directly to your Bugsink project:
defp deps do [ # Your existing dependencies... {:finch, "~> 0.21"}, {:sentry, "~> 14.0"} ] enddefp deps do [ # Your existing dependencies... {:finch, "~> 0.21"}, {:sentry, "~> 14.0"} ] end
Then fetch the new dependencies:
mix deps.getmix deps.get
Configure your DSN
Configure :sentry in the environment where you report production errors.
Reading the DSN from the environment keeps the project key out of source
control:
config :sentry, dsn: System.get_env("SENTRY_DSN"), environment_name: :prodconfig :sentry, dsn: System.get_env("SENTRY_DSN"), environment_name: :prod
Set SENTRY_DSN to the DSN shown by your Bugsink project when you run Phoenix:
export SENTRY_DSN=https://key@bugsink.example/1export SENTRY_DSN=https://key@bugsink.example/1
Add the Plug integration
Sentry.PlugCapture reports exceptions that escape the endpoint. Use it
before Phoenix.Endpoint so it wraps the Phoenix pipeline. PlugContext
adds the current request to the SDK scope and belongs before your router:
defmodule Inventory.Endpoint do use Sentry.PlugCapture use Phoenix.Endpoint, otp_app: :inventory plug(Sentry.PlugContext) plug(Inventory.Router) enddefmodule Inventory.Endpoint do use Sentry.PlugCapture use Phoenix.Endpoint, otp_app: :inventory plug(Sentry.PlugContext) plug(Inventory.Router) end
There is no Bugsink-specific call in a controller. The integration reports an unhandled exception as it leaves the Plug pipeline.
Send a test error
Temporarily raise an exception in a controller action you can request. This inventory action raises its domain exception when the requested product does not exist:
unless Map.has_key?(@inventory, sku) do raise ProductNotFound, "Product #{sku} is not in inventory" endunless Map.has_key?(@inventory, sku) do raise ProductNotFound, "Product #{sku} is not in inventory" end
Start Phoenix in the configured environment, then request that action once:
MIX_ENV=prod mix phx.server :::bash curl http://127.0.0.1:8080/checkout/elixir-missingMIX_ENV=prod mix phx.server :::bash curl http://127.0.0.1:8080/checkout/elixir-missing
Phoenix returns its normal 500 response, while the Plug integration reports the exception to Bugsink.
See the error in Bugsink
Open your Bugsink project. The new
Inventory.Controller.ProductNotFound issue identifies the controller frame
which raised it. Its event details also contain the GET request.
Inventory.Controller.ProductNotFound
That’s it: unhandled exceptions from the Phoenix endpoint will now be reported to Bugsink. Remove the deliberate failure; the Plug integration remains active for future request errors.
For handled exceptions, Logger messages, tags, context, breadcrumbs, releases, and shutdown behavior, continue with the plain Elixir guide.
