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

Handle elixir exceptions in MetadataReporter #427

Merged
merged 1 commit into from
Feb 14, 2024
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
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
Loading