Skip to content

Commit 4a53118

Browse files
Merge pull request #315 from getsentry/fix-weird-stacktrace
coerce stacktrace
2 parents 0aaeb8e + 16fd973 commit 4a53118

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

lib/sentry/event.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ defmodule Sentry.Event do
7373

7474
message = Keyword.get(opts, :message)
7575

76-
stacktrace = Keyword.get(opts, :stacktrace, [])
76+
stacktrace =
77+
Keyword.get(opts, :stacktrace, [])
78+
|> coerce_stacktrace()
7779

7880
fingerprint = Keyword.get(opts, :fingerprint, ["{{ default }}"])
7981

@@ -238,6 +240,10 @@ defmodule Sentry.Event do
238240
Exception.format_mfa(m, f, arity_to_integer(a))
239241
end
240242

243+
def culprit_from_stacktrace([{m, f, a} | _]) do
244+
Exception.format_mfa(m, f, arity_to_integer(a))
245+
end
246+
241247
@doc """
242248
Builds a map from argument value list. For Sentry, typically the
243249
key in the map would be the name of the variable, but we don't have that
@@ -276,4 +282,7 @@ defmodule Sentry.Event do
276282
end
277283

278284
defp module_split(module), do: module_split(String.Chars.to_string(module))
285+
286+
defp coerce_stacktrace({m, f, a}), do: [{m, f, a, []}]
287+
defp coerce_stacktrace(stacktrace), do: stacktrace
279288
end

test/sentry_test.exs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,35 @@ defmodule SentryTest do
6161

6262
Bypass.pass(bypass)
6363
end
64+
65+
test "handles three element tuple as stacktrace" do
66+
bypass = Bypass.open()
67+
68+
Bypass.expect(bypass, fn conn ->
69+
assert conn.request_path == "/api/1/store/"
70+
assert conn.method == "POST"
71+
{:ok, body, conn} = Plug.Conn.read_body(conn)
72+
{:ok, json} = Jason.decode(body)
73+
assert json["culprit"] == "GenServer.call/3"
74+
assert List.first(json["exception"])["value"] == "Erlang error: :timeout"
75+
Plug.Conn.send_resp(conn, 200, ~s<{"id": "340"}>)
76+
end)
77+
78+
modify_env(
79+
:sentry,
80+
dsn: "http://public:secret@localhost:#{bypass.port}/1"
81+
)
82+
83+
Process.flag(:trap_exit, true)
84+
85+
{:ok, pid} = Sentry.TestGenServer.start_link(self())
86+
spawn_pid = spawn_link(fn -> GenServer.call(pid, {:sleep, 100}, 0) end)
87+
88+
receive do
89+
{:EXIT, ^spawn_pid, {reason, stack}} ->
90+
Sentry.capture_exception(reason, stacktrace: stack)
91+
end
92+
93+
Bypass.pass(bypass)
94+
end
6495
end

test/support/test_gen_server.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ defmodule Sentry.TestGenServer do
1919
{:ok, pid}
2020
end
2121

22+
def handle_call({:sleep, milliseconds}, _from, state) do
23+
:timer.sleep(milliseconds)
24+
{:reply, :ok, state}
25+
end
26+
2227
def handle_info(:throw, _state) do
2328
throw("I am throwing")
2429
end

0 commit comments

Comments
 (0)