mirror of
https://github.com/plausible/analytics.git
synced 2025-03-14 10:06:38 +00:00
Log Oban errors (and still report them to Sentry) (#4657)
* log oban errors in CE * update changelog * not just ce * add comment
This commit is contained in:
@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
- Add ability to review and revoke particular logged in user sessions
|
||||
- Add ability to change password from user settings screen
|
||||
- Add error logs for background jobs plausible/analytics#4657
|
||||
|
||||
### Removed
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
defmodule ObanErrorReporter do
|
||||
use Plausible
|
||||
require Logger
|
||||
|
||||
def handle_event(name, measurements, metadata, _) do
|
||||
@ -21,20 +22,17 @@ defmodule ObanErrorReporter do
|
||||
|> Map.merge(measure)
|
||||
|
||||
on_job_exception(job)
|
||||
|
||||
Sentry.capture_exception(meta.reason, stacktrace: meta.stacktrace, extra: extra)
|
||||
capture_error(meta, extra)
|
||||
end
|
||||
|
||||
defp handle_event([:oban, :notifier, :exception], _timing, meta) do
|
||||
extra = Map.take(meta, ~w(channel payload)a)
|
||||
|
||||
Sentry.capture_exception(meta.reason, stacktrace: meta.stacktrace, extra: extra)
|
||||
capture_error(meta, extra)
|
||||
end
|
||||
|
||||
defp handle_event([:oban, :plugin, :exception], _timing, meta) do
|
||||
extra = Map.take(meta, ~w(plugin)a)
|
||||
|
||||
Sentry.capture_exception(meta.reason, stacktrace: meta.stacktrace, extra: extra)
|
||||
capture_error(meta, extra)
|
||||
end
|
||||
|
||||
defp on_job_exception(%Oban.Job{
|
||||
@ -65,4 +63,16 @@ defmodule ObanErrorReporter do
|
||||
end
|
||||
|
||||
defp on_job_exception(_job), do: :ignore
|
||||
|
||||
# Logs the error and sends it to Sentry
|
||||
defp capture_error(meta, extra) do
|
||||
Logger.error(
|
||||
# this message is ignored by Sentry
|
||||
"Background job (#{inspect(extra)}) failed:\n\n " <>
|
||||
Exception.format(:error, meta.reason, meta.stacktrace),
|
||||
# Sentry report is built entirely from crash_reason
|
||||
crash_reason: {meta.reason, meta.stacktrace},
|
||||
sentry: %{extra: extra}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user