Skip to content

Commit c79e1b8

Browse files
authored
Merge pull request #427 from letscolife/extend-meta-reporting
Handle elixir exceptions in MetadataReporter
2 parents c56373c + a64fd05 commit c79e1b8

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

lib/new_relic/error/metadata_reporter.ex

+9-7
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,21 @@ defmodule NewRelic.Error.MetadataReporter do
6262
end
6363
end
6464

65-
defp parse_reason({exception, stacktrace}) do
66-
type = parse_type(exception)
65+
defp parse_reason({%type{message: message} = exception, stacktrace}) do
6766
expected = parse_error_expected(exception)
68-
message = Map.get(exception, :message)
67+
type = inspect(type)
6968
reason = "(#{type}) #{message}"
7069

7170
{type, reason, stacktrace, expected}
7271
end
7372

74-
defp parse_type(%type{}) do
75-
type
76-
|> Module.split()
77-
|> Enum.join(".")
73+
defp parse_reason({exception, stacktrace}) do
74+
exception = Exception.normalize(:error, exception, stacktrace)
75+
type = inspect(exception.__struct__)
76+
message = Exception.message(exception)
77+
reason = "(#{type}) #{message}"
78+
79+
{type, reason, stacktrace, false}
7880
end
7981

8082
defp parse_process_name([], [{module, _f, _a, _} | _]), do: inspect(module)

test/error_test.exs

+16
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,20 @@ defmodule ErrorTest do
186186
intrinsic[:"error.class"] == "File.Error"
187187
end)
188188
end
189+
190+
test "Catch a function clause error inside a Task" do
191+
TestHelper.restart_harvest_cycle(Collector.TransactionErrorEvent.HarvestCycle)
192+
193+
:proc_lib.spawn(fn ->
194+
Task.async(fn -> ErrorDummy.handle_call(:foo, nil, nil) end) |> Task.await()
195+
end)
196+
197+
:timer.sleep(100)
198+
199+
events = TestHelper.gather_harvest(Collector.TransactionErrorEvent.Harvester)
200+
201+
assert Enum.find(events, fn [intrinsic, _, _] ->
202+
intrinsic[:"error.class"] == "FunctionClauseError"
203+
end)
204+
end
189205
end

0 commit comments

Comments
 (0)