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
This commit is contained in:
Adam Rutkowski 2023-01-13 18:04:09 +01:00 committed by GitHub
parent 97a3ce72e4
commit 61bf624761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View File

@ -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,

View File

@ -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",

View File

@ -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