Skip to content

Commit 36ca702

Browse files
committed
Fix Oban reporting and all state field.
There was an error when an Oban worker returned an `{:error, reason}` tuple because Oban does not return an stacktrace (makes sense, as it is not an exception by itself). Our code was not prepared for that use case. I modified it to handle it and circunvent the needed for source file and source function information. As an extra feature I have also added the reporting of the `state` of the job (which is mostly ever `failure` for us).
1 parent 67ef9f7 commit 36ca702

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/error_tracker/integrations/oban.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ defmodule ErrorTracker.Integrations.Oban do
5959

6060
def handle_event([:oban, :job, :exception], _measurements, metadata, :no_config) do
6161
%{reason: exception, stacktrace: stacktrace} = metadata
62+
state = Map.get(metadata, :state, :failure)
6263

63-
ErrorTracker.report(exception, stacktrace)
64+
ErrorTracker.report(exception, stacktrace, %{state: state})
6465
end
6566
end

lib/error_tracker/schemas/error.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ defmodule ErrorTracker.Error do
2929
@doc false
3030
def new(kind, reason, stacktrace = %ErrorTracker.Stacktrace{}) do
3131
source = ErrorTracker.Stacktrace.source(stacktrace)
32-
source_line = if source.file, do: "#{source.file}:#{source.line}", else: "nofile"
32+
33+
{source_line, source_function} =
34+
if source do
35+
source_line = if source.line, do: "#{source.file}:#{source.line}", else: "nofile"
36+
source_function = "#{source.module}.#{source.function}/#{source.arity}"
37+
38+
{source_line, source_function}
39+
else
40+
{"-", "-"}
41+
end
3342

3443
params = [
3544
kind: to_string(kind),
3645
source_line: source_line,
37-
source_function: "#{source.module}.#{source.function}/#{source.arity}"
46+
source_function: source_function
3847
]
3948

4049
fingerprint = :crypto.hash(:sha256, params |> Keyword.values() |> Enum.join())

0 commit comments

Comments
 (0)