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

Log Oban errors (and still report them to Sentry) #4657

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Changes from 1 commit
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
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