Skip to content

Commit

Permalink
log oban errors in CE
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Oct 8, 2024
1 parent 2359cb9 commit 6fd13fd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/oban_error_reporter.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule ObanErrorReporter do
use Plausible
require Logger

def handle_event(name, measurements, metadata, _) do
Expand All @@ -22,18 +23,30 @@ defmodule ObanErrorReporter do

on_job_exception(job)

on_ce do
log_ce_error(meta, extra)
end

Sentry.capture_exception(meta.reason, stacktrace: meta.stacktrace, extra: extra)
end

defp handle_event([:oban, :notifier, :exception], _timing, meta) do
extra = Map.take(meta, ~w(channel payload)a)

on_ce do
log_ce_error(meta, extra)
end

Sentry.capture_exception(meta.reason, stacktrace: meta.stacktrace, extra: extra)
end

defp handle_event([:oban, :plugin, :exception], _timing, meta) do
extra = Map.take(meta, ~w(plugin)a)

on_ce do
log_ce_error(meta, extra)
end

Sentry.capture_exception(meta.reason, stacktrace: meta.stacktrace, extra: extra)
end

Expand Down Expand Up @@ -65,4 +78,13 @@ defmodule ObanErrorReporter do
end

defp on_job_exception(_job), do: :ignore

on_ce do
defp log_ce_error(meta, extra) do
Logger.error(
"Background job (#{inspect(extra)}) failed:\n\n " <>
Exception.format(:error, meta.reason, meta.stacktrace)
)
end
end
end

0 comments on commit 6fd13fd

Please sign in to comment.