From 4c14a9db2cfac1a8ac99c099b38a085834215041 Mon Sep 17 00:00:00 2001 From: ruslandoga Date: Tue, 21 Jan 2025 15:19:03 +0300 Subject: [PATCH] replace Sentry.capture_message with Logger.error where appropriate for CE --- lib/plausible/cache/adapter.ex | 5 ++--- lib/plausible/google/http.ex | 6 +++++- lib/plausible/ingestion/counters.ex | 16 ++++++++-------- lib/plausible/ingestion/event.ex | 7 +++++-- lib/plausible/verification/diagnostics.ex | 1 + .../controllers/api/external_controller.ex | 2 +- lib/plausible_web/controllers/auth_controller.ex | 2 +- lib/plausible_web/live/sites.ex | 5 +++-- lib/plausible_web/views/email_view.ex | 1 + lib/workers/import_analytics.ex | 12 +++++++----- 10 files changed, 34 insertions(+), 23 deletions(-) diff --git a/lib/plausible/cache/adapter.ex b/lib/plausible/cache/adapter.ex index 0c77a28c9716..8f7d5fc10ae0 100644 --- a/lib/plausible/cache/adapter.ex +++ b/lib/plausible/cache/adapter.ex @@ -120,9 +120,8 @@ defmodule Plausible.Cache.Adapter do {:ok, result} catch :exit, {:timeout, _} -> - Sentry.capture_message( - "Timeout while executing with lock on key in '#{inspect(cache_name)}'", - extra: %{key: key} + Logger.error("Timeout while executing with lock on key in '#{inspect(cache_name)}'", + sentry: %{extra: %{key: key}} ) {:error, :timeout} diff --git a/lib/plausible/google/http.ex b/lib/plausible/google/http.ex index 4666cd0a4452..c9a3d1a92cf3 100644 --- a/lib/plausible/google/http.ex +++ b/lib/plausible/google/http.ex @@ -93,7 +93,11 @@ defmodule Plausible.Google.HTTP do {:error, error} {:error, %{reason: _} = e} -> - Sentry.capture_message("Error fetching Google queries", extra: %{error: inspect(e)}) + # TODO + Logger.error("Error fetching Google queries", + sentry: %{extra: %{error: inspect(e)}} + ) + {:error, :unknown_error} end end diff --git a/lib/plausible/ingestion/counters.ex b/lib/plausible/ingestion/counters.ex index ad153276619c..a72845447488 100644 --- a/lib/plausible/ingestion/counters.ex +++ b/lib/plausible/ingestion/counters.ex @@ -82,14 +82,14 @@ defmodule Plausible.Ingestion.Counters do try do {_, _} = AsyncInsertRepo.insert_all(Record, records) - catch - _, thrown -> - Sentry.capture_message( - "Caught an error when trying to flush ingest counters.", - extra: %{ - number_of_records: Enum.count(records), - error: inspect(thrown) - } + rescue + e -> + msg = Exception.format_error(e, __STACKTRACE__) + + # TODO + Logger.error("Caught an error when trying to flush ingest counters:\n " <> msg, + crash_reason: {e, __STACKTRACE__}, + extra: %{number_of_records: Enum.count(records)} ) end end diff --git a/lib/plausible/ingestion/event.ex b/lib/plausible/ingestion/event.ex index e113ae8047ca..2fd6ee7e2bce 100644 --- a/lib/plausible/ingestion/event.ex +++ b/lib/plausible/ingestion/event.ex @@ -10,6 +10,8 @@ defmodule Plausible.Ingestion.Event do alias Plausible.ClickhouseEventV2 alias Plausible.Site.GateKeeper + require Logger + defstruct domain: nil, site: nil, clickhouse_event_attrs: %{}, @@ -467,8 +469,9 @@ defmodule Plausible.Ingestion.Event do nil %Device{type: type} -> - Sentry.capture_message("Could not determine device type from UAInspector", - extra: %{type: type} + # TODO + Logger.error("Could not determine device type from UAInspector", + sentry: %{extra: %{type: type}} ) nil diff --git a/lib/plausible/verification/diagnostics.ex b/lib/plausible/verification/diagnostics.ex index d89fc65d38ad..da5a09f5bb86 100644 --- a/lib/plausible/verification/diagnostics.ex +++ b/lib/plausible/verification/diagnostics.ex @@ -363,6 +363,7 @@ defmodule Plausible.Verification.Diagnostics do end def interpret(diagnostics, url) do + # TODO Sentry.capture_message("Unhandled case for site verification", extra: %{ message: inspect(diagnostics), diff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.ex index 46622ee202d9..c25896d854a6 100644 --- a/lib/plausible_web/controllers/api/external_controller.ex +++ b/lib/plausible_web/controllers/api/external_controller.ex @@ -43,7 +43,7 @@ defmodule PlausibleWeb.Api.ExternalController do end def error(conn, _params) do - Sentry.capture_message("JS snippet error") + Logger.error("JS snippet error") send_resp(conn, 200, "") end diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex index 19315a50d62a..4de82acef051 100644 --- a/lib/plausible_web/controllers/auth_controller.ex +++ b/lib/plausible_web/controllers/auth_controller.ex @@ -476,7 +476,7 @@ defmodule PlausibleWeb.AuthController do |> redirect(external: redirect_route) _any -> - Sentry.capture_message("Google OAuth callback failed. Reason: #{inspect(params)}") + Logger.error("Google OAuth callback failed. Reason: #{inspect(params)}") conn |> put_flash( diff --git a/lib/plausible_web/live/sites.ex b/lib/plausible_web/live/sites.ex index 3eaa466770cc..9f0fa7c8101a 100644 --- a/lib/plausible_web/live/sites.ex +++ b/lib/plausible_web/live/sites.ex @@ -614,8 +614,9 @@ defmodule PlausibleWeb.Live.Sites do {:noreply, socket} else - Sentry.capture_message("Attempting to toggle pin for invalid domain.", - extra: %{domain: domain, user: socket.assigns.current_user.id} + # TODO + Logger.error("Attempting to toggle pin for invalid domain.", + sentry: %{extra: %{domain: domain, user: socket.assigns.current_user.id}} ) {:noreply, socket} diff --git a/lib/plausible_web/views/email_view.ex b/lib/plausible_web/views/email_view.ex index 1ac9a5ad4fd1..db79ccf54d2d 100644 --- a/lib/plausible_web/views/email_view.ex +++ b/lib/plausible_web/views/email_view.ex @@ -16,6 +16,7 @@ defmodule PlausibleWeb.EmailView do Calendar.strftime(date, "%-d %b %Y") end + # TODO dsn() :: nil | {String.t(), String.t(), String.t()} def sentry_link(trace_id, dsn \\ Sentry.Config.dsn()) do search_query = URI.encode_query(%{query: trace_id}) path = "/organizations/sentry/issues/" diff --git a/lib/workers/import_analytics.ex b/lib/workers/import_analytics.ex index 18c7f58f8237..c79c0adb388d 100644 --- a/lib/workers/import_analytics.ex +++ b/lib/workers/import_analytics.ex @@ -33,11 +33,13 @@ defmodule Plausible.Workers.ImportAnalytics do :ok {:error, error, error_opts} -> - Sentry.capture_message("Failed to import from #{site_import.source}", - extra: %{ - import_id: site_import.id, - site: site_import.site.domain, - error: inspect(error) + Logger.error("Failed to import from #{site_import.source}", + sentry: %{ + extra: %{ + import_id: site_import.id, + site: site_import.site.domain, + error: inspect(error) + } } )