Skip to content

Commit

Permalink
feat: reports exception stacktrace frames (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy authored Jun 11, 2024
1 parent dab2954 commit 5e3535f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
24 changes: 21 additions & 3 deletions lib/tower_rollbar/rollbar/item.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,27 @@ defmodule TowerRollbar.Rollbar.Item do
}
end

defp frames(_stacktrace) do
# TODO: implement
[]
defp frames(stacktrace) do
stacktrace
|> Enum.map(fn {m, f, a, location} ->
frame = %{
"method" => Exception.format_mfa(m, f, a)
}

frame =
if location[:file] do
Map.put(frame, "filename", to_string(location[:file]))
else
frame
end

if location[:line] do
Map.put(frame, "lineno", location[:line])
else
frame
end
end)
|> Enum.reverse()
end

defp environment do
Expand Down
23 changes: 22 additions & 1 deletion test/tower_rollbar/rollbar/item_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,28 @@ defmodule TowerRollbar.Rollbar.ItemTest do
"level" => "error",
"body" => %{
"trace" => %{
"frames" => [],
"frames" => [
%{
"method" => _,
"filename" => "lib/ex_unit/runner.ex",
"lineno" => _
},
%{
"method" => _,
"filename" => "timer.erl",
"lineno" => _
},
%{
"method" => _,
"filename" => "lib/ex_unit/runner.ex",
"lineno" => _
},
%{
"method" => ~s(TowerRollbar.Rollbar.ItemTest."test from_exception"/1),
"filename" => "test/tower_rollbar/rollbar/item_test.exs",
"lineno" => 12
}
],
"exception" => %{
"class" => "RuntimeError",
"message" => "a test"
Expand Down

0 comments on commit 5e3535f

Please sign in to comment.