Skip to content

Commit 5c37a8d

Browse files
Merge pull request #381 from getsentry/timeout-test
Ensure stacktrace is list in LoggerBackend
2 parents 4bba523 + 5252ca9 commit 5c37a8d

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/sentry/logger_backend.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ defmodule Sentry.LoggerBackend do
7676
end
7777

7878
case Keyword.get(meta, :crash_reason) do
79-
{reason, stacktrace} ->
79+
{reason, stacktrace} when is_list(stacktrace) ->
8080
if ignore_plug &&
8181
Enum.any?(stacktrace, fn {module, function, arity, _file_line} ->
8282
match?({^module, ^function, ^arity}, {Plug.Cowboy.Handler, :init, 2}) ||
@@ -93,6 +93,11 @@ defmodule Sentry.LoggerBackend do
9393
Sentry.capture_exception(reason, opts)
9494
end
9595

96+
{{_reason, stacktrace}, {_m, _f, args}} when is_list(stacktrace) and is_list(args) ->
97+
# Cowboy stuff
98+
# https://github.com/ninenines/cowboy/blob/master/src/cowboy_stream_h.erl#L148-L151
99+
:ok
100+
96101
reason when is_atom(reason) and not is_nil(reason) ->
97102
Sentry.capture_exception(reason, [{:event_source, :logger} | opts])
98103

test/logger_backend_test.exs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,40 @@ defmodule Sentry.LoggerBackendTest do
149149
end)
150150
end
151151

152+
test "GenServer timeout makes call to Sentry API" do
153+
self_pid = self()
154+
Process.flag(:trap_exit, true)
155+
bypass = Bypass.open()
156+
157+
Bypass.expect(bypass, fn conn ->
158+
{:ok, body, conn} = Plug.Conn.read_body(conn)
159+
json = Jason.decode!(body)
160+
161+
exception_value =
162+
List.first(json["exception"])
163+
|> Map.fetch!("value")
164+
165+
assert String.contains?(exception_value, "{:timeout, {GenServer, :call")
166+
167+
assert conn.request_path == "/api/1/store/"
168+
assert conn.method == "POST"
169+
send(self_pid, "API called")
170+
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
171+
end)
172+
173+
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
174+
175+
{:ok, pid1} = Sentry.TestGenServer.start_link(self_pid)
176+
177+
capture_log(fn ->
178+
Task.start(fn ->
179+
GenServer.call(pid1, {:sleep, 20}, 1)
180+
end)
181+
182+
assert_receive "API called"
183+
end)
184+
end
185+
152186
test "only sends one error when a Plug process crashes" do
153187
Code.compile_string("""
154188
defmodule SentryApp do

0 commit comments

Comments
 (0)