Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/sentry/logger_backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ defmodule Sentry.LoggerBackend do
end

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

{{_reason, stacktrace}, {_m, _f, args}} when is_list(stacktrace) and is_list(args) ->
# Cowboy stuff
# https://github.com/ninenines/cowboy/blob/master/src/cowboy_stream_h.erl#L148-L151
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mitchellhenke, will you be adding code to capture this case in Sentry as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned in #380 (comment), but the events are for the same crash, so reporting twice would be a duplicate 🙂

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it. Thanks!

:ok

reason when is_atom(reason) and not is_nil(reason) ->
Sentry.capture_exception(reason, [{:event_source, :logger} | opts])

Expand Down
34 changes: 34 additions & 0 deletions test/logger_backend_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,40 @@ defmodule Sentry.LoggerBackendTest do
end)
end

test "GenServer timeout makes call to Sentry API" do
self_pid = self()
Process.flag(:trap_exit, true)
bypass = Bypass.open()

Bypass.expect(bypass, fn conn ->
{:ok, body, conn} = Plug.Conn.read_body(conn)
json = Jason.decode!(body)

exception_value =
List.first(json["exception"])
|> Map.fetch!("value")

assert String.contains?(exception_value, "{:timeout, {GenServer, :call")

assert conn.request_path == "/api/1/store/"
assert conn.method == "POST"
send(self_pid, "API called")
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
end)

modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")

{:ok, pid1} = Sentry.TestGenServer.start_link(self_pid)

capture_log(fn ->
Task.start(fn ->
GenServer.call(pid1, {:sleep, 20}, 1)
end)

assert_receive "API called"
end)
end

test "only sends one error when a Plug process crashes" do
Code.compile_string("""
defmodule SentryApp do
Expand Down