Skip to content

Commit

Permalink
Merge pull request #78 from appsignal/normalize-reason-string-76
Browse files Browse the repository at this point in the history
Normalize reason string
  • Loading branch information
jeffkreeftmeijer committed Jan 17, 2017
2 parents eb2348b + 8e7470e commit 8065141
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/appsignal/error_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule Appsignal.ErrorHandler do
false ->
transaction = Transaction.lookup_or_create_transaction(origin)
if transaction != nil do
submit_transaction(transaction, reason, message, stack, %{}, conn)
submit_transaction(transaction, normalize_reason(reason), message, stack, %{}, conn)
end
true ->
# ignore this event; we have already handled it.
Expand Down Expand Up @@ -211,4 +211,9 @@ defmodule Appsignal.ErrorHandler do
defp prefixed(nil, msg), do: msg
defp prefixed("", msg), do: msg
defp prefixed(pre, msg), do: pre <> ": " <> msg

@pid_or_ref_regex ~r/\<(\d+\.)+\d+\>/
def normalize_reason(reason) do
Regex.replace(@pid_or_ref_regex, reason, "<...>")
end
end
15 changes: 15 additions & 0 deletions test/appsignal/error_handler/error_matcher_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,23 @@ defmodule Appsignal.ErrorHandler.ErrorMatcherTest do
|> reason(":function_clause")
end

test "Task await" do
:proc_lib.spawn(fn() ->
Task.async(fn() ->
Process.sleep(2)
end)
|> Task.await(1)
end)
|> assert_crash_caught
|> reason_regex(~r/^{:exit, {:timeout/)
end

defp reason(reason, expected) do
assert expected == reason
end

defp reason_regex(reason, expected) do
assert reason =~ expected
end

end
15 changes: 15 additions & 0 deletions test/appsignal/error_handler/normalize_reason_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Appsignal.ErrorHandler.NormalizeReasonTest do

use ExUnit.Case

alias Appsignal.ErrorHandler

@reason_raw "{:exit, {:timeout, {Task, :await, [%Task{owner: #PID<0.178.0>, pid: #PID<0.179.0>, ref: #Reference<0.0.4.753>}, 1]}}}"
@reason_norm "{:exit, {:timeout, {Task, :await, [%Task{owner: #PID<...>, pid: #PID<...>, ref: #Reference<...>}, 1]}}}"
test "Remove pid / ref strings from reason" do

assert @reason_norm == ErrorHandler.normalize_reason(@reason_raw)

end

end

0 comments on commit 8065141

Please sign in to comment.