From 61bf624761ef6dcb0a51003720eb6154973ac8da Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Fri, 13 Jan 2023 18:04:09 +0100 Subject: [PATCH] Sentry cleanup (#2590) * Filter DBConnection logs for clickhouse in Sentry Removing the never matching clause btw * Exclude Plug.CSRFProtection.InvalidCSRFTokenError from Sentry * Turn common Sentry captures into logged warnings * Exclude fonts from static conf and InvalidPathError from Sentry --- lib/plausible_web/controllers/api/stats_controller.ex | 8 +++++--- lib/plausible_web/endpoint.ex | 2 +- lib/sentry_filter.ex | 11 ++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex index 20e774d54..4eab32265 100644 --- a/lib/plausible_web/controllers/api/stats_controller.ex +++ b/lib/plausible_web/controllers/api/stats_controller.ex @@ -5,6 +5,8 @@ defmodule PlausibleWeb.Api.StatsController do alias Plausible.Stats alias Plausible.Stats.{Query, Filters} + require Logger + @doc """ Returns a time-series based on given parameters. @@ -805,7 +807,7 @@ defmodule PlausibleWeb.Api.StatsController do country_entry = get_country(region_entry.country_code) Map.merge(region, %{name: region_entry.name, country_flag: country_entry.flag}) else - Sentry.capture_message("Could not find region info", extra: %{code: region[:code]}) + Logger.warning("Could not find region info - code: #{inspect(region[:code])}") Map.merge(region, %{name: region[:code]}) end end) @@ -842,7 +844,7 @@ defmodule PlausibleWeb.Api.StatsController do country_flag: country_info.flag }) else - Sentry.capture_message("Could not find city info", extra: %{code: city[:code]}) + Logger.warning("Could not find city info - code: #{inspect(city[:code])}") Map.merge(city, %{name: "N/A"}) end @@ -1173,7 +1175,7 @@ defmodule PlausibleWeb.Api.StatsController do defp get_country(code) do case Location.get_country(code) do nil -> - Sentry.capture_message("Could not find country info", extra: %{code: code}) + Logger.warning("Could not find country info - code: #{inspect(code)}") %Location.Country{ alpha_2: code, diff --git a/lib/plausible_web/endpoint.ex b/lib/plausible_web/endpoint.ex index 34078e93e..90172f0c3 100644 --- a/lib/plausible_web/endpoint.ex +++ b/lib/plausible_web/endpoint.ex @@ -13,7 +13,7 @@ defmodule PlausibleWeb.Endpoint do at: "/", from: :plausible, gzip: false, - only: ~w(css fonts images js favicon.ico robots.txt) + only: ~w(css images js favicon.ico robots.txt) plug Plug.Static, at: "/kaffy", diff --git a/lib/sentry_filter.ex b/lib/sentry_filter.ex index 84871972d..700888030 100644 --- a/lib/sentry_filter.ex +++ b/lib/sentry_filter.ex @@ -6,6 +6,8 @@ defmodule Plausible.SentryFilter do def exclude_exception?(%Sentry.CrashError{}, _source), do: true def exclude_exception?(%Phoenix.NotAcceptableError{}, _), do: true + def exclude_exception?(%Plug.CSRFProtection.InvalidCSRFTokenError{}, _), do: true + def exclude_exception?(%Plug.Static.InvalidPathError{}, _), do: true def exclude_exception?(exception, source) do Sentry.DefaultEventFilter.exclude_exception?(exception, source) @@ -14,11 +16,6 @@ defmodule Plausible.SentryFilter do @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( %{exception: [%{type: "Clickhousex.Error"}], original_exception: %{code: code}} = event ) @@ -26,6 +23,10 @@ defmodule Plausible.SentryFilter do %{event | fingerprint: ["clickhouse", "db_connection", to_string(code)]} end + def before_send(%{event_source: :logger, message: "Clickhousex.Protocol " <> _} = event) do + %{event | fingerprint: ["clickhouse", "db_connection", "protocol_error"]} + end + def before_send(event) do event end