You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/platforms/elixir/integrations/plug_and_phoenix/index.mdx
+21-5Lines changed: 21 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -6,18 +6,16 @@ sidebar_order: 10
6
6
7
7
You can capture errors in [Plug](https://github.com/elixir-plug/plug) and [Phoenix](https://phoenixframework.org) applications with `Sentry.PlugContext` and `Sentry.PlugCapture`.
8
8
9
-
`Sentry.PlugContext` adds contextual metadata from the current request, which is then included in errors that are captured and reported by `Sentry.PlugCapture`.
9
+
`Sentry.PlugContext` adds contextual metadata from the current request to the reported errors that happen during Plug execution. For [Cowboy](https://hex.pm/packages/cowboy) applications, an additional plug `Sentry.PlugCapture` is required to ensure this metadata propagates properly.
10
10
11
11
## Phoenix Configuration
12
12
13
13
If you are using Phoenix, follow these steps to add the Plug integration:
14
14
15
-
1. Add `Sentry.PlugCapture` above the `use Phoenix.Endpoint` line in your endpoint file.
16
15
1. Add `Sentry.PlugContext` below `Plug.Parsers`.
17
16
18
17
```elixir {diff}
19
18
defmoduleMyAppWeb.Endpoint
20
-
+ use Sentry.PlugCapture
21
19
use Phoenix.Endpoint, otp_app: :my_app
22
20
23
21
# ...
@@ -30,6 +28,16 @@ defmodule MyAppWeb.Endpoint
30
28
+ plug Sentry.PlugContext
31
29
```
32
30
31
+
2. If you're using Cowboy, add `Sentry.PlugCapture` above the `use Phoenix.Endpoint` line in your endpoint file.
32
+
33
+
```elixir {diff}
34
+
defmodule MyAppWeb.Endpoint
35
+
+ use Sentry.PlugCapture
36
+
use Phoenix.Endpoint, otp_app: :my_app
37
+
38
+
# ...
39
+
```
40
+
33
41
If you're also using [PhoenixLiveView](https://github.com/phoenixframework/phoenix_live_view), consider also setting up your LiveViews to use the `Sentry.LiveViewHook` hook (available in the SentrySDK versions `10.5.0` and higher):
34
42
35
43
```elixir
@@ -78,18 +86,26 @@ end
78
86
79
87
If you have a non-Phoenix application, follow these steps to configure the Plug integration:
80
88
81
-
1. Add `Sentry.PlugCapture` at the top of your Plug application.
82
89
1. Add `Sentry.PlugContext` below `Plug.Parsers` (if it is in your stack).
83
90
84
91
```elixir {diff}
85
92
defmoduleMyApp.Routerdo
86
93
usePlug.Router
87
-
+useSentry.PlugCapture
88
94
89
95
# ...
90
96
91
97
plug Plug.Parsers,
92
98
parsers: [:urlencoded, :multipart]
93
99
94
100
+ plug Sentry.PlugContext
101
+
```
102
+
103
+
2. If you're using Cowboy, add `Sentry.PlugCapture` at the top of your Plug application.
0 commit comments