From 3f7c1ce549d955741d6fabe6b7401c8a55e462b6 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 22 Sep 2022 17:24:54 +0200 Subject: [PATCH] Aggregate DBConnection.ConnectionError in Sentry (#2260) --- config/runtime.exs | 3 ++- lib/sentry_filter.ex | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config/runtime.exs b/config/runtime.exs index cf27a6b5a..cda583797 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -224,7 +224,8 @@ config :sentry, root_source_code_path: [File.cwd!()], client: Plausible.Sentry.Client, send_max_attempts: 1, - filter: Plausible.SentryFilter + filter: Plausible.SentryFilter, + before_send_event: {Plausible.SentryFilter, :before_send} config :logger, Sentry.LoggerBackend, capture_log_messages: true, diff --git a/lib/sentry_filter.ex b/lib/sentry_filter.ex index 96210129f..7b5386fb8 100644 --- a/lib/sentry_filter.ex +++ b/lib/sentry_filter.ex @@ -1,4 +1,7 @@ defmodule Plausible.SentryFilter do + @moduledoc """ + Sentry callbacks for filtering and grouping events + """ @behaviour Sentry.EventFilter def exclude_exception?(%Sentry.CrashError{}, _source), do: true @@ -7,4 +10,16 @@ defmodule Plausible.SentryFilter do def exclude_exception?(exception, source) do Sentry.DefaultEventFilter.exclude_exception?(exception, source) end + + @spec before_send(Sentry.Event.t()) :: Sentry.Event.t() + def before_send(event) + + # https://hexdocs.pm/sentry/readme.html#fingerprinting + def before_send(%{exception: [%{type: DBConnection.ConnectionError}]} = event) do + %{event | fingerprint: ["ecto", "db_connection", "timeout"]} + end + + def before_send(event) do + event + end end