Improve error reporting and add test

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-08-03 12:15:54 +02:00
parent ec745b3e80
commit cceb083ad7
4 changed files with 107 additions and 8 deletions

View File

@@ -7,6 +7,8 @@ defmodule Mobilizon.Service.ErrorReporting do
@callback configure :: any()
@callback attach :: any()
@callback handle_event(list(atom()), map(), map(), any()) :: any()
@spec adapter :: module() | nil
@@ -15,6 +17,14 @@ defmodule Mobilizon.Service.ErrorReporting do
if adapter && adapter.enabled?(), do: adapter, else: nil
end
def attach do
adapter = adapter()
if adapter do
adapter.attach()
end
end
@spec handle_event(list(atom()), map(), map(), any()) :: any()
def handle_event(event_name, event_measurements, event_metadata, handler_config) do
adapter = adapter()

View File

@@ -28,6 +28,16 @@ defmodule Mobilizon.Service.ErrorReporting.Sentry do
end
end
@impl ErrorReporting
def attach do
:telemetry.attach(
"oban-errors",
[:oban, :job, :exception],
&handle_event/4,
[]
)
end
@impl ErrorReporting
def handle_event([:oban, :job, :exception], measure, %{job: job} = meta, _) do
extra =
@@ -42,4 +52,6 @@ defmodule Mobilizon.Service.ErrorReporting.Sentry do
def handle_event([:oban, :circuit, :trip], _measure, meta, _) do
Sentry.capture_exception(meta.error, stacktrace: meta.stacktrace, extra: meta)
end
def handle_event(_, _, _, _), do: :ok
end