Skip to content

Commit

Permalink
Merge pull request #427 from letscolife/extend-meta-reporting
Browse files Browse the repository at this point in the history
Handle elixir exceptions in MetadataReporter
  • Loading branch information
tpitale authored Feb 14, 2024
2 parents c56373c + a64fd05 commit c79e1b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/new_relic/error/metadata_reporter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,21 @@ defmodule NewRelic.Error.MetadataReporter do
end
end

defp parse_reason({exception, stacktrace}) do
type = parse_type(exception)
defp parse_reason({%type{message: message} = exception, stacktrace}) do
expected = parse_error_expected(exception)
message = Map.get(exception, :message)
type = inspect(type)
reason = "(#{type}) #{message}"

{type, reason, stacktrace, expected}
end

defp parse_type(%type{}) do
type
|> Module.split()
|> Enum.join(".")
defp parse_reason({exception, stacktrace}) do
exception = Exception.normalize(:error, exception, stacktrace)
type = inspect(exception.__struct__)
message = Exception.message(exception)
reason = "(#{type}) #{message}"

{type, reason, stacktrace, false}
end

defp parse_process_name([], [{module, _f, _a, _} | _]), do: inspect(module)
Expand Down
16 changes: 16 additions & 0 deletions test/error_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,20 @@ defmodule ErrorTest do
intrinsic[:"error.class"] == "File.Error"
end)
end

test "Catch a function clause error inside a Task" do
TestHelper.restart_harvest_cycle(Collector.TransactionErrorEvent.HarvestCycle)

:proc_lib.spawn(fn ->
Task.async(fn -> ErrorDummy.handle_call(:foo, nil, nil) end) |> Task.await()
end)

:timer.sleep(100)

events = TestHelper.gather_harvest(Collector.TransactionErrorEvent.Harvester)

assert Enum.find(events, fn [intrinsic, _, _] ->
intrinsic[:"error.class"] == "FunctionClauseError"
end)
end
end

0 comments on commit c79e1b8

Please sign in to comment.