From 6fd13fd4bf1f87e189d0aae3fa268cf657f230a0 Mon Sep 17 00:00:00 2001 From: ruslandoga <67764432+ruslandoga@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:24:57 +0700 Subject: [PATCH] log oban errors in CE --- lib/oban_error_reporter.ex | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/oban_error_reporter.ex b/lib/oban_error_reporter.ex index a17520c1536d..6af4dc62f9ce 100644 --- a/lib/oban_error_reporter.ex +++ b/lib/oban_error_reporter.ex @@ -1,4 +1,5 @@ defmodule ObanErrorReporter do + use Plausible require Logger def handle_event(name, measurements, metadata, _) do @@ -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 @@ -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