From 5b226cd393191bb1e5e28cb2230d646ef1a06186 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 | 5 ++++- lib/plausible/ingestion/counters.ex | 10 ++++++---- lib/plausible/ingestion/event.ex | 6 ++++-- lib/plausible/verification/diagnostics.ex | 12 +++++++----- .../controllers/api/external_controller.ex | 2 +- .../controllers/auth_controller.ex | 2 +- lib/plausible_web/live/sites.ex | 5 +++-- lib/plausible_web/views/email_view.ex | 18 +++++++++--------- lib/workers/import_analytics.ex | 12 +++++++----- 10 files changed, 44 insertions(+), 33 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..951da74bb209 100644 --- a/lib/plausible/google/http.ex +++ b/lib/plausible/google/http.ex @@ -93,7 +93,10 @@ defmodule Plausible.Google.HTTP do {:error, error} {:error, %{reason: _} = e} -> - Sentry.capture_message("Error fetching Google queries", extra: %{error: inspect(e)}) + 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..2feed102bff5 100644 --- a/lib/plausible/ingestion/counters.ex +++ b/lib/plausible/ingestion/counters.ex @@ -84,11 +84,13 @@ defmodule Plausible.Ingestion.Counters do {_, _} = AsyncInsertRepo.insert_all(Record, records) catch _, thrown -> - Sentry.capture_message( + Logger.error( "Caught an error when trying to flush ingest counters.", - extra: %{ - number_of_records: Enum.count(records), - error: inspect(thrown) + sentry: %{ + extra: %{ + number_of_records: Enum.count(records), + error: inspect(thrown) + } } ) end diff --git a/lib/plausible/ingestion/event.ex b/lib/plausible/ingestion/event.ex index e113ae8047ca..cf42d8a2b1b4 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,8 @@ defmodule Plausible.Ingestion.Event do nil %Device{type: type} -> - Sentry.capture_message("Could not determine device type from UAInspector", - extra: %{type: type} + 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..538723ab5119 100644 --- a/lib/plausible/verification/diagnostics.ex +++ b/lib/plausible/verification/diagnostics.ex @@ -363,11 +363,13 @@ defmodule Plausible.Verification.Diagnostics do end def interpret(diagnostics, url) do - Sentry.capture_message("Unhandled case for site verification", - extra: %{ - message: inspect(diagnostics), - url: url, - hash: :erlang.phash2(diagnostics) + Logger.error("Unhandled case for site verification", + sentry: %{ + extra: %{ + message: inspect(diagnostics), + url: url, + hash: :erlang.phash2(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..c07f261e5222 100644 --- a/lib/plausible_web/live/sites.ex +++ b/lib/plausible_web/live/sites.ex @@ -5,6 +5,7 @@ defmodule PlausibleWeb.Live.Sites do use PlausibleWeb, :live_view import PlausibleWeb.Live.Components.Pagination + require Logger alias Plausible.Sites @@ -614,8 +615,8 @@ 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} + 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..35212e0595b7 100644 --- a/lib/plausible_web/views/email_view.ex +++ b/lib/plausible_web/views/email_view.ex @@ -20,15 +20,15 @@ defmodule PlausibleWeb.EmailView do search_query = URI.encode_query(%{query: trace_id}) path = "/organizations/sentry/issues/" - if is_binary(dsn) do - dsn - |> URI.parse() - |> Map.replace(:userinfo, nil) - |> Map.replace(:path, path) - |> Map.replace(:query, search_query) - |> URI.to_string() - else - "" + case dsn do + {endpoint_uri, _public_key, _secret_key} when is_binary(endpoint_uri) -> + URI.parse(endpoint_uri) + |> Map.replace(:path, path) + |> Map.replace(:query, search_query) + |> URI.to_string() + + _ -> + "" end end end 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) + } } )