mirror of
https://github.com/plausible/analytics.git
synced 2024-12-02 07:38:47 +03:00
c0c36646e2
* Add Custom telemetry for Plausible.Event.WriteBuffer, Plausible.Event.WriteBuffer and Cachex Signed-off-by: Manu S Ajith <neo@codingarena.in> * Rename telemetry.ex to avoid confusion with Phoenix Telemetry supervisor Signed-off-by: Manu S Ajith <neo@codingarena.in> * Remove duplicate event Signed-off-by: Manu S Ajith <neo@codingarena.in> Signed-off-by: Manu S Ajith <neo@codingarena.in>
50 lines
1.4 KiB
Elixir
50 lines
1.4 KiB
Elixir
defmodule ObanErrorReporter do
|
|
def handle_event([:oban, :job, :exception], measure, %{job: job} = meta, _) do
|
|
extra =
|
|
job
|
|
|> Map.take([:id, :args, :meta, :queue, :worker])
|
|
|> Map.merge(measure)
|
|
|
|
on_job_exception(job)
|
|
|
|
Sentry.capture_exception(meta.reason, stacktrace: meta.stacktrace, extra: extra)
|
|
end
|
|
|
|
def 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)
|
|
end
|
|
|
|
def 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)
|
|
end
|
|
|
|
defp on_job_exception(%Oban.Job{
|
|
queue: "google_analytics_imports",
|
|
args: %{"site_id" => site_id},
|
|
state: "executing",
|
|
attempt: attempt,
|
|
max_attempts: max_attempts
|
|
})
|
|
when attempt >= max_attempts do
|
|
site = Plausible.Repo.get(Plausible.Site, site_id)
|
|
|
|
if site do
|
|
Plausible.Workers.ImportGoogleAnalytics.import_failed(site)
|
|
end
|
|
end
|
|
|
|
defp on_job_exception(%Oban.Job{
|
|
queue: "google_analytics_imports",
|
|
args: %{"site_id" => site_id},
|
|
state: "executing"
|
|
}) do
|
|
Plausible.ClickhouseRepo.clear_imported_stats_for(site_id)
|
|
end
|
|
|
|
defp on_job_exception(_job), do: :ignore
|
|
end
|