diff --git a/lib/error_tracker/integrations/oban.ex b/lib/error_tracker/integrations/oban.ex index 77acd5a..be637d5 100644 --- a/lib/error_tracker/integrations/oban.ex +++ b/lib/error_tracker/integrations/oban.ex @@ -59,7 +59,8 @@ defmodule ErrorTracker.Integrations.Oban do def handle_event([:oban, :job, :exception], _measurements, metadata, :no_config) do %{reason: exception, stacktrace: stacktrace} = metadata + state = Map.get(metadata, :state, :failure) - ErrorTracker.report(exception, 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 26265d4..2c4ab45 100644 --- a/lib/error_tracker/schemas/error.ex +++ b/lib/error_tracker/schemas/error.ex @@ -29,12 +29,21 @@ defmodule ErrorTracker.Error do @doc false def new(kind, reason, stacktrace = %ErrorTracker.Stacktrace{}) do source = ErrorTracker.Stacktrace.source(stacktrace) - source_line = if source.file, do: "#{source.file}:#{source.line}", else: "nofile" + + {source_line, source_function} = + if source do + source_line = if source.line, do: "#{source.file}:#{source.line}", else: "nofile" + source_function = "#{source.module}.#{source.function}/#{source.arity}" + + {source_line, source_function} + else + {"-", "-"} + end params = [ kind: to_string(kind), source_line: source_line, - source_function: "#{source.module}.#{source.function}/#{source.arity}" + source_function: source_function ] fingerprint = :crypto.hash(:sha256, params |> Keyword.values() |> Enum.join()) @@ -46,4 +55,14 @@ defmodule ErrorTracker.Error do |> Ecto.Changeset.put_change(:last_occurrence_at, DateTime.utc_now()) |> Ecto.Changeset.apply_action(:new) end + + @doc """ + Returns if the Error has information of the source or not. + + Errors usually have information about in which line and function occurred, but + in some cases (like an Oban job ending with `{:error, any()}`) we cannot get + that information and no source is stored. + """ + def has_source_info?(%__MODULE__{source_function: "-", source_line: "-"}), do: false + def has_source_info?(%__MODULE__{}), do: true end diff --git a/lib/error_tracker/web/live/dashboard.html.heex b/lib/error_tracker/web/live/dashboard.html.heex index 6d6cbb3..68807fd 100644 --- a/lib/error_tracker/web/live/dashboard.html.heex +++ b/lib/error_tracker/web/live/dashboard.html.heex @@ -69,7 +69,7 @@

(<%= sanitize_module(error.kind) %>) <%= error.reason %>

-

+

<%= sanitize_module(error.source_function) %>
<%= error.source_line %> diff --git a/lib/error_tracker/web/live/show.html.heex b/lib/error_tracker/web/live/show.html.heex index 795b7fb..16ecb87 100644 --- a/lib/error_tracker/web/live/show.html.heex +++ b/lib/error_tracker/web/live/show.html.heex @@ -19,13 +19,13 @@

<%= @occurrence.reason %>
- <.section title="Source"> + <.section :if={ErrorTracker.Error.has_source_info?(@error)} title="Source">
         <%= sanitize_module(@error.source_function) %>
         <%= @error.source_line %>
- <.section title="Stacktrace"> + <.section :if={@occurrence.stacktrace.lines != []} title="Stacktrace">