Skip to content

Commit f62d101

Browse files
authored
Fix crash with custom scrubber in Sentry.PlugContext (#678)
1 parent 98b1509 commit f62d101

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

lib/sentry/plug_capture.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ defmodule Sentry.PlugCapture do
7272

7373
defmacro __using__(opts) do
7474
quote do
75-
opts = unquote(Macro.escape(opts))
75+
opts = unquote(opts)
7676
default_scrubber = {unquote(__MODULE__), :default_scrubber, []}
7777

7878
scrubber =

test/plug_capture_test.exs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ defmodule Sentry.PlugCaptureTest do
3434
plug PhoenixRouter
3535
end
3636

37+
defmodule Scrubber do
38+
def scrub_conn(conn) do
39+
conn
40+
end
41+
end
42+
43+
defmodule PhoenixEndpointWithScrubber do
44+
use Sentry.PlugCapture, scrubber: {Scrubber, :scrub_conn, []}
45+
use Phoenix.Endpoint, otp_app: :sentry
46+
use Plug.Debugger, otp_app: :sentry
47+
48+
plug Plug.Parsers, parsers: [:json], pass: ["*/*"], json_decoder: Jason
49+
plug Sentry.PlugContext
50+
plug PhoenixRouter
51+
end
52+
3753
setup do
3854
bypass = Bypass.open()
3955
put_test_config(dsn: "http://public:secret@localhost:#{bypass.port}/1")
@@ -239,6 +255,33 @@ defmodule Sentry.PlugCaptureTest do
239255
|> call_phoenix_endpoint()
240256
end
241257
end
258+
259+
test "modifies conn with custom scrubber", %{bypass: bypass} do
260+
Application.put_env(:sentry, PhoenixEndpointWithScrubber,
261+
render_errors: [view: Sentry.ErrorView, accepts: ~w(html)]
262+
)
263+
264+
pid = start_supervised!(PhoenixEndpointWithScrubber)
265+
Process.link(pid)
266+
267+
Bypass.expect(bypass, fn conn ->
268+
{:ok, body, conn} = Plug.Conn.read_body(conn)
269+
270+
event = decode_event_from_envelope!(body)
271+
272+
assert event["culprit"] == "Sentry.PlugCaptureTest.PhoenixController.error/2"
273+
274+
assert List.first(event["exception"])["type"] == "RuntimeError"
275+
assert List.first(event["exception"])["value"] == "PhoenixError"
276+
277+
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
278+
end)
279+
280+
assert_raise RuntimeError, "PhoenixError", fn ->
281+
conn(:get, "/error_route")
282+
|> Plug.run([{PhoenixEndpointWithScrubber, []}])
283+
end
284+
end
242285
end
243286

244287
defp call_plug_app(conn), do: Plug.run(conn, [{Sentry.ExamplePlugApplication, []}])

0 commit comments

Comments
 (0)