Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Aggregate DBConnection.ConnectionError in Sentry (#2260)

Adam Rutkowski3f7c1ce549d9
diff --git a/config/runtime.exs b/config/runtime.exs
index cf27a6b5a8..cda583797d 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 96210129f8..7b5386fb87 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