diff --git a/lib/error_tracker/integrations/oban.ex b/lib/error_tracker/integrations/oban.ex index be637d5..0553ae2 100644 --- a/lib/error_tracker/integrations/oban.ex +++ b/lib/error_tracker/integrations/oban.ex @@ -12,6 +12,20 @@ defmodule ErrorTracker.Integrations.Oban do It works using Oban's Telemetry events, so you don't need to modify anything on your application. + > #### A note on errors grouping {: .warning} + > + > All errors reported using `:error` or `{:error, any()}` as the output of + > your `perform/2` worker function are going to be grouped together (one group + > of those of errors per worker). + > + > The reason of that behaviour is that those errors do not generate an exception, + > so no stack trace is detected and they are stored as happening in the same + > place. + > + > If you want errors of your workers to be grouped as you may expect on other + > integrations, you should raise exceptions to report errors instead of gracefully + > returning an error value. + ### Default context By default we store some context for you on errors generated in an Oban @@ -58,9 +72,14 @@ defmodule ErrorTracker.Integrations.Oban do end def handle_event([:oban, :job, :exception], _measurements, metadata, :no_config) do - %{reason: exception, stacktrace: stacktrace} = metadata + %{reason: exception, stacktrace: stacktrace, job: job} = metadata state = Map.get(metadata, :state, :failure) + stacktrace = + if stacktrace == [], + do: [{String.to_existing_atom("Elixir." <> job.worker), :perform, 2, []}], + else: stacktrace + ErrorTracker.report(exception, stacktrace, %{state: state}) end end diff --git a/lib/error_tracker/schemas/error.ex b/lib/error_tracker/schemas/error.ex index 2c4ab45..fbfb4b9 100644 --- a/lib/error_tracker/schemas/error.ex +++ b/lib/error_tracker/schemas/error.ex @@ -32,7 +32,7 @@ defmodule ErrorTracker.Error do {source_line, source_function} = if source do - source_line = if source.line, do: "#{source.file}:#{source.line}", else: "nofile" + source_line = if source.line, do: "#{source.file}:#{source.line}", else: "(nofile)" source_function = "#{source.module}.#{source.function}/#{source.arity}" {source_line, source_function} diff --git a/lib/error_tracker/web/live/show.html.heex b/lib/error_tracker/web/live/show.html.heex index 16ecb87..b14cda4 100644 --- a/lib/error_tracker/web/live/show.html.heex +++ b/lib/error_tracker/web/live/show.html.heex @@ -48,7 +48,7 @@
(<%= line.application || @app %>)
<%= "#{sanitize_module(line.module)}.#{line.function}/#{line.arity}" %>
-                <%= if line.line, do: "#{line.file}:#{line.line}", else: "nofile" %>
+ <%= if line.line, do: "#{line.file}:#{line.line}", else: "(nofile)" %> diff --git a/test/error_tracker_test.exs b/test/error_tracker_test.exs index f8018b3..8d9ea79 100644 --- a/test/error_tracker_test.exs +++ b/test/error_tracker_test.exs @@ -40,7 +40,7 @@ defmodule ErrorTrackerTest do assert error.source_line =~ @relative_file_path else assert error.source_function == "erlang.+/2" - assert error.source_line == "nofile" + assert error.source_line == "(nofile)" end end @@ -54,7 +54,7 @@ defmodule ErrorTrackerTest do assert error.kind == to_string(UndefinedFunctionError) assert error.reason =~ "is undefined or private" assert error.source_function == Exception.format_mfa(m, f, Enum.count(a)) - assert error.source_line == "nofile" + assert error.source_line == "(nofile)" end test "reports throws" do