Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize reason string #78

Merged
merged 2 commits into from
Jan 17, 2017
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/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
5 changes: 0 additions & 5 deletions lib/appsignal/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,6 @@ defmodule Appsignal.Transaction do
end
end

defp ensure_headers_map(nil), do: %{}
defp ensure_headers_map(headers) when is_list(headers) do
headers |> Enum.into(%{})
end

if Appsignal.phoenix? do
@doc """
Set the request metadata, given a Plug.Conn.t.
Expand Down
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