Skip to content

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

Installation support telemetry (#5790)

RobertJoonas3de4aa54d46d
diff --git a/extra/lib/plausible/installation_support/checks/installation_v2_cache_bust.ex b/extra/lib/plausible/installation_support/checks/installation_v2_cache_bust.ex
index 70cf3cc736..2e39f987a4 100644
--- a/extra/lib/plausible/installation_support/checks/installation_v2_cache_bust.ex
+++ b/extra/lib/plausible/installation_support/checks/installation_v2_cache_bust.ex
@@ -20,20 +20,24 @@ defmodule Plausible.InstallationSupport.Checks.InstallationV2CacheBust do
@impl true
def perform(%State{url: url} = state) do
- if InstallationSupport.Verification.Checks.interpret_diagnostics(state) ==
- %InstallationSupport.Result{ok?: true} do
- state
- else
- url_that_maybe_busts_cache =
- Plausible.InstallationSupport.URL.bust_url(url)
-
- state_after_cache_bust =
- Plausible.InstallationSupport.Checks.InstallationV2.perform(%{
- state
- | url: url_that_maybe_busts_cache
- })
-
- put_diagnostics(state_after_cache_bust, diagnostics_are_from_cache_bust: true)
+ case InstallationSupport.Verification.Checks.interpret_diagnostics(state, telemetry?: false) do
+ %InstallationSupport.Result{ok?: true} ->
+ state
+
+ %InstallationSupport.Result{data: %{unhandled: true}} ->
+ state
+
+ _known_installation_failure ->
+ url_that_maybe_busts_cache =
+ Plausible.InstallationSupport.URL.bust_url(url)
+
+ state_after_cache_bust =
+ Plausible.InstallationSupport.Checks.InstallationV2.perform(%{
+ state
+ | url: url_that_maybe_busts_cache
+ })
+
+ put_diagnostics(state_after_cache_bust, diagnostics_are_from_cache_bust: true)
end
end
end
diff --git a/extra/lib/plausible/installation_support/detection/checks.ex b/extra/lib/plausible/installation_support/detection/checks.ex
index 002c371c32..da9f88be2c 100644
--- a/extra/lib/plausible/installation_support/detection/checks.ex
+++ b/extra/lib/plausible/installation_support/detection/checks.ex
@@ -37,11 +37,29 @@ defmodule Plausible.InstallationSupport.Detection.Checks do
)
end
+ def telemetry_event_handled(), do: [:plausible, :detection, :handled]
+ def telemetry_event_unhandled(), do: [:plausible, :detection, :unhandled]
+
def interpret_diagnostics(%State{} = state) do
- Detection.Diagnostics.interpret(
- state.diagnostics,
- state.url
- )
+ result = Detection.Diagnostics.interpret(state.diagnostics, state.url)
+
+ case result.data do
+ %{unhandled: true, diagnostics: diagnostics, url: url} ->
+ Sentry.capture_message("Unhandled case for detection",
+ extra: %{
+ message: inspect(diagnostics),
+ url: url,
+ hash: :erlang.phash2(diagnostics)
+ }
+ )
+
+ :telemetry.execute(telemetry_event_unhandled(), %{})
+
+ _ ->
+ :telemetry.execute(telemetry_event_handled(), %{})
+ end
+
+ result
end
@unthrottled_checks 3
diff --git a/extra/lib/plausible/installation_support/detection/diagnostics.ex b/extra/lib/plausible/installation_support/detection/diagnostics.ex
index 50966bf48c..c59180a491 100644
--- a/extra/lib/plausible/installation_support/detection/diagnostics.ex
+++ b/extra/lib/plausible/installation_support/detection/diagnostics.ex
@@ -72,15 +72,11 @@ defmodule Plausible.InstallationSupport.Detection.Diagnostics do
do: unhandled_case(diagnostics, url)
defp unhandled_case(diagnostics, url) do
- Sentry.capture_message("Unhandled case for detection",
- extra: %{
- message: inspect(diagnostics),
- url: url,
- hash: :erlang.phash2(diagnostics)
- }
- )
-
- %Result{ok?: false, data: nil, errors: ["Unhandled detection case"]}
+ %Result{
+ ok?: false,
+ data: %{unhandled: true, diagnostics: diagnostics, url: url},
+ errors: ["Unhandled detection case"]
+ }
end
defp get_result(suggested_technology, diagnostics) do
diff --git a/extra/lib/plausible/installation_support/verification/checks.ex b/extra/lib/plausible/installation_support/verification/checks.ex
index 2479f011a7..17392ab942 100644
--- a/extra/lib/plausible/installation_support/verification/checks.ex
+++ b/extra/lib/plausible/installation_support/verification/checks.ex
@@ -38,11 +38,38 @@ defmodule Plausible.InstallationSupport.Verification.Checks do
)
end
- def interpret_diagnostics(%State{} = state) do
- Verification.Diagnostics.interpret(
- state.diagnostics,
- state.data_domain,
- state.url
- )
+ def telemetry_event_handled(), do: [:plausible, :verification, :handled]
+ def telemetry_event_unhandled(), do: [:plausible, :verification, :unhandled]
+
+ def interpret_diagnostics(%State{} = state, opts \\ []) do
+ telemetry? = Keyword.get(opts, :telemetry?, true)
+
+ result =
+ Verification.Diagnostics.interpret(
+ state.diagnostics,
+ state.data_domain,
+ state.url
+ )
+
+ case {telemetry?, result.data} do
+ {false, _} ->
+ :skip
+
+ {_, %{unhandled: true, diagnostics: diagnostics, url: url}} ->
+ Sentry.capture_message("Unhandled case for site verification (v2)",
+ extra: %{
+ message: inspect(diagnostics),
+ url: url,
+ hash: :erlang.phash2(diagnostics)
+ }
+ )
+
+ :telemetry.execute(telemetry_event_unhandled(), %{})
+
+ _ ->
+ :telemetry.execute(telemetry_event_handled(), %{})
+ end
+
+ result
end
end
diff --git a/extra/lib/plausible/installation_support/verification/diagnostics.ex b/extra/lib/plausible/installation_support/verification/diagnostics.ex
index d9989469f7..c0db56a2f8 100644
--- a/extra/lib/plausible/installation_support/verification/diagnostics.ex
+++ b/extra/lib/plausible/installation_support/verification/diagnostics.ex
@@ -260,15 +260,8 @@ defmodule Plausible.InstallationSupport.Verification.Diagnostics do
do: error_plausible_not_found(selected_installation_type)
def interpret(%__MODULE__{} = diagnostics, _expected_domain, url) do
- Sentry.capture_message("Unhandled case for site verification (v2)",
- extra: %{
- message: inspect(diagnostics),
- url: url,
- hash: :erlang.phash2(diagnostics)
- }
- )
-
error_plausible_not_found(diagnostics.selected_installation_type)
+ |> Map.put(:data, %{unhandled: true, diagnostics: diagnostics, url: url})
end
@message_plausible_not_found "We couldn't detect Plausible on your site"
diff --git a/lib/plausible/telemetry/plausible_metrics.ex b/lib/plausible/telemetry/plausible_metrics.ex
index cdea456839..c6b918040a 100644
--- a/lib/plausible/telemetry/plausible_metrics.ex
+++ b/lib/plausible/telemetry/plausible_metrics.ex
@@ -7,6 +7,10 @@ defmodule Plausible.PromEx.Plugins.PlausibleMetrics do
alias Plausible.Site
alias Plausible.Ingestion
+ on_ee do
+ alias Plausible.InstallationSupport
+ end
+
@impl true
def polling_metrics(opts) do
poll_rate = Keyword.get(opts, :poll_rate, 5_000)
@@ -166,8 +170,7 @@ defmodule Plausible.PromEx.Plugins.PlausibleMetrics do
metric_prefix ++ [:verification, :js_elixir_diff],
event_name:
Plausible.InstallationSupport.Checks.Installation.telemetry_event(_diff = true)
- ),
- else: nil
+ )
),
on_ee(
do:
@@ -175,8 +178,35 @@ defmodule Plausible.PromEx.Plugins.PlausibleMetrics do
metric_prefix ++ [:verification, :js_elixir_match],
event_name:
Plausible.InstallationSupport.Checks.Installation.telemetry_event(_diff = false)
- ),
- else: nil
+ )
+ ),
+ on_ee(
+ do:
+ counter(
+ metric_prefix ++ [:detection, :handled],
+ event_name: InstallationSupport.Detection.Checks.telemetry_event_handled()
+ )
+ ),
+ on_ee(
+ do:
+ counter(
+ metric_prefix ++ [:detection, :unhandled],
+ event_name: InstallationSupport.Detection.Checks.telemetry_event_unhandled()
+ )
+ ),
+ on_ee(
+ do:
+ counter(
+ metric_prefix ++ [:verification, :handled],
+ event_name: InstallationSupport.Verification.Checks.telemetry_event_handled()
+ )
+ ),
+ on_ee(
+ do:
+ counter(
+ metric_prefix ++ [:verification, :unhandled],
+ event_name: InstallationSupport.Verification.Checks.telemetry_event_unhandled()
+ )
)
]
|> Enum.reject(&is_nil/1)
diff --git a/test/plausible/installation_support/verification/checks_test.exs b/test/plausible/installation_support/verification/checks_test.exs
index c388a15329..b0eb988898 100644
--- a/test/plausible/installation_support/verification/checks_test.exs
+++ b/test/plausible/installation_support/verification/checks_test.exs
@@ -519,7 +519,7 @@ defmodule Plausible.InstallationSupport.Verification.ChecksTest do
)
|> Checks.interpret_diagnostics()
- assert 2 == :atomics.get(verification_counter, 1)
+ assert 1 == :atomics.get(verification_counter, 1)
end
end
end