Improve error reporting and add test
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -68,14 +68,11 @@ defmodule Mobilizon do
|
||||
|
||||
ErrorReporting.configure()
|
||||
|
||||
:ok = Oban.Telemetry.attach_default_logger()
|
||||
|
||||
:telemetry.attach_many(
|
||||
"oban-errors",
|
||||
[[:oban, :job, :exception], [:oban, :circuit, :trip]],
|
||||
&ErrorReporting.handle_event/4,
|
||||
%{}
|
||||
)
|
||||
# Only attach the telemetry logger when we aren't in an IEx shell
|
||||
unless Code.ensure_loaded?(IEx) && IEx.started?() do
|
||||
Oban.Telemetry.attach_default_logger(:info)
|
||||
ErrorReporting.attach()
|
||||
end
|
||||
|
||||
Supervisor.start_link(children, strategy: :one_for_one, name: Mobilizon.Supervisor)
|
||||
end
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user