Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Revert "Sentry context in live views (#3672)" (#3673)
hq1c87b165aefb1
diff --git a/extra/lib/plausible_web/live/funnel_settings.ex b/extra/lib/plausible_web/live/funnel_settings.exindex 2a00a028b6..cf98c3ddc4 100644--- a/extra/lib/plausible_web/live/funnel_settings.ex+++ b/extra/lib/plausible_web/live/funnel_settings.ex@@ -2,8 +2,9 @@ defmodule PlausibleWeb.Live.FunnelSettings do@moduledoc """LiveView allowing listing, creating and deleting funnels."""- use PlausibleWeb, :live_view+ use Phoenix.LiveViewuse Phoenix.HTML+ use PlausibleWeb.Live.Flashuse Plausible.Funneldiff --git a/extra/lib/plausible_web/live/funnel_settings/form.ex b/extra/lib/plausible_web/live/funnel_settings/form.exindex 37e7525edc..be01598161 100644--- a/extra/lib/plausible_web/live/funnel_settings/form.ex+++ b/extra/lib/plausible_web/live/funnel_settings/form.ex@@ -5,7 +5,7 @@ defmodule PlausibleWeb.Live.FunnelSettings.Form doto allow building searchable funnel definitions out of list of goals available."""- use PlausibleWeb, :live_view+ use Phoenix.LiveViewuse Plausible.Funnelimport PlausibleWeb.Live.Components.Formdiff --git a/lib/plausible_web.ex b/lib/plausible_web.exindex 649b33ee4e..4c2cb6b4b0 100644--- a/lib/plausible_web.ex+++ b/lib/plausible_web.ex@@ -1,19 +1,4 @@defmodule PlausibleWeb do- def live_view(opts \\ []) do- quote do- use Plausible- use Phoenix.LiveView, global_prefixes: ~w(x-)- use PlausibleWeb.Live.Flash-- unless :no_sentry_context in unquote(opts) do- use PlausibleWeb.Live.SentryContext- end-- alias PlausibleWeb.Router.Helpers, as: Routes- alias Phoenix.LiveView.JS- end- end-def controller doquote douse Phoenix.Controller, namespace: PlausibleWeb@@ -101,8 +86,4 @@ defmodule PlausibleWeb dodefmacro __using__(which) when is_atom(which) doapply(__MODULE__, which, [])end-- defmacro __using__([{which, opts}]) when is_atom(which) do- apply(__MODULE__, which, [List.wrap(opts)])- endenddiff --git a/lib/plausible_web/endpoint.ex b/lib/plausible_web/endpoint.exindex 5b6c6f9306..c4a1fa247e 100644--- a/lib/plausible_web/endpoint.ex+++ b/lib/plausible_web/endpoint.ex@@ -17,12 +17,7 @@ defmodule PlausibleWeb.Endpoint dosocket("/live", Phoenix.LiveView.Socket,websocket: [check_origin: true,- connect_info: [- :peer_data,- :uri,- :user_agent,- session: {__MODULE__, :runtime_session_opts, []}- ]+ connect_info: [session: {__MODULE__, :runtime_session_opts, []}]])diff --git a/lib/plausible_web/live/choose_plan.ex b/lib/plausible_web/live/choose_plan.exindex 24dbc74941..4a8ee85a13 100644--- a/lib/plausible_web/live/choose_plan.ex+++ b/lib/plausible_web/live/choose_plan.ex@@ -2,7 +2,7 @@ defmodule PlausibleWeb.Live.ChoosePlan do@moduledoc """LiveView for upgrading to a plan, or changing an existing plan."""- use PlausibleWeb, :live_view+ use Phoenix.LiveViewuse Phoenix.HTMLrequire Plausible.Billing.Subscription.Statusdiff --git a/lib/plausible_web/live/goal_settings.ex b/lib/plausible_web/live/goal_settings.exindex 081066f30e..6a9bef179b 100644--- a/lib/plausible_web/live/goal_settings.ex+++ b/lib/plausible_web/live/goal_settings.ex@@ -2,8 +2,9 @@ defmodule PlausibleWeb.Live.GoalSettings do@moduledoc """LiveView allowing listing, creating and deleting goals."""- use PlausibleWeb, :live_view+ use Phoenix.LiveViewuse Phoenix.HTML+ use PlausibleWeb.Live.Flashalias Plausible.{Sites, Goals}diff --git a/lib/plausible_web/live/goal_settings/form.ex b/lib/plausible_web/live/goal_settings/form.exindex c016131502..285d1bd2d7 100644--- a/lib/plausible_web/live/goal_settings/form.ex+++ b/lib/plausible_web/live/goal_settings/form.ex@@ -2,7 +2,8 @@ defmodule PlausibleWeb.Live.GoalSettings.Form do@moduledoc """Live view for the goal creation form"""- use PlausibleWeb, :live_view+ use Phoenix.LiveView+ use Plausibleimport PlausibleWeb.Live.Components.Formalias PlausibleWeb.Live.Components.ComboBoxdiff --git a/lib/plausible_web/live/plugins/api/settings.ex b/lib/plausible_web/live/plugins/api/settings.exindex 53e46b078a..82b287ddd8 100644--- a/lib/plausible_web/live/plugins/api/settings.ex+++ b/lib/plausible_web/live/plugins/api/settings.ex@@ -2,9 +2,9 @@ defmodule PlausibleWeb.Live.Plugins.API.Settings do@moduledoc """LiveView allowing listing, creating and revoking Plugins API tokens."""-- use PlausibleWeb, :live_view+ use Phoenix.LiveViewuse Phoenix.HTML+ use PlausibleWeb.Live.Flashalias Plausible.Sitesalias Plausible.Plugins.API.Tokensdiff --git a/lib/plausible_web/live/plugins/api/token_form.ex b/lib/plausible_web/live/plugins/api/token_form.exindex 3e641fceda..5180b177bc 100644--- a/lib/plausible_web/live/plugins/api/token_form.ex+++ b/lib/plausible_web/live/plugins/api/token_form.ex@@ -2,7 +2,7 @@ defmodule PlausibleWeb.Live.Plugins.API.TokenForm do@moduledoc """Live view for the goal creation form"""- use PlausibleWeb, live_view: :no_sentry_context+ use Phoenix.LiveViewimport PlausibleWeb.Live.Components.Formalias Plausible.Repodiff --git a/lib/plausible_web/live/props_settings.ex b/lib/plausible_web/live/props_settings.exindex b850d656be..d48c6fee39 100644--- a/lib/plausible_web/live/props_settings.ex+++ b/lib/plausible_web/live/props_settings.ex@@ -3,8 +3,9 @@ defmodule PlausibleWeb.Live.PropsSettings doLiveView allowing listing, allowing and disallowing custom event properties."""- use PlausibleWeb, :live_view+ use Phoenix.LiveViewuse Phoenix.HTML+ use PlausibleWeb.Live.Flashalias PlausibleWeb.Live.Components.ComboBoxdiff --git a/lib/plausible_web/live/props_settings/form.ex b/lib/plausible_web/live/props_settings/form.exindex a1cc47d6a8..8e715a1b75 100644--- a/lib/plausible_web/live/props_settings/form.ex+++ b/lib/plausible_web/live/props_settings/form.ex@@ -2,7 +2,7 @@ defmodule PlausibleWeb.Live.PropsSettings.Form do@moduledoc """Live view for the custom props creation form"""- use PlausibleWeb, :live_view+ use Phoenix.LiveViewimport PlausibleWeb.Live.Components.Formalias PlausibleWeb.Live.Components.ComboBoxdiff --git a/lib/plausible_web/live/register_form.ex b/lib/plausible_web/live/register_form.exindex 619504318d..258c6b52a3 100644--- a/lib/plausible_web/live/register_form.ex+++ b/lib/plausible_web/live/register_form.ex@@ -3,13 +3,17 @@ defmodule PlausibleWeb.Live.RegisterForm doLiveView for registration form."""- use PlausibleWeb, :live_view+ use Phoenix.LiveViewuse Phoenix.HTML+ use Plausible+import PlausibleWeb.Live.Components.Formalias Plausible.Authalias Plausible.Repo+ alias PlausibleWeb.Router.Helpers, as: Routes+def mount(params, _session, socket) dosocket =assign_new(socket, :invitation, fn ->diff --git a/lib/plausible_web/live/reset_password_form.ex b/lib/plausible_web/live/reset_password_form.exindex 6b757d4ec0..49451afbcd 100644--- a/lib/plausible_web/live/reset_password_form.ex+++ b/lib/plausible_web/live/reset_password_form.ex@@ -3,7 +3,7 @@ defmodule PlausibleWeb.Live.ResetPasswordForm doLiveView for password reset form."""- use PlausibleWeb, :live_view+ use Phoenix.LiveViewuse Phoenix.HTMLimport PlausibleWeb.Live.Components.Formdiff --git a/lib/plausible_web/live/sentry_context.ex b/lib/plausible_web/live/sentry_context.exdeleted file mode 100644index 7511ddd80c..0000000000--- a/lib/plausible_web/live/sentry_context.ex+++ /dev/null@@ -1,76 +0,0 @@-defmodule PlausibleWeb.Live.SentryContext do- @moduledoc """- This module tries to supply LiveViews with some common Sentry context- (without it, there is practically none).-- Use via `use PlausibleWeb.Live.SentryContext` in your LiveView module,- or preferably via `use PlausibleWeb, :live_view`.-- In case you have multiple LiveViews, there is `use PlausibleWeb, live_view: :no_sentry_context`- exposed that allows you to skip using this module. This is because- only the root LiveView has access to `connect_info` and an exception will be- thrown otherwise.- """-- defmacro __using__(_) do- quote do- on_mount PlausibleWeb.Live.SentryContext- end- end-- def on_mount(:default, _params, session, socket) do- peer = Phoenix.LiveView.get_connect_info(socket, :peer_data)- uri = Phoenix.LiveView.get_connect_info(socket, :uri)-- user_agent =- Phoenix.LiveView.get_connect_info(socket, :user_agent)-- socket_host =- case socket.host_uri do- :not_mounted_at_router -> :not_mounted_at_router- %URI{host: host} -> host- end-- request_context =- %{- host: socket_host,- env: %{- "REMOTE_ADDR" => get_ip(peer),- "REMOTE_PORT" => peer && peer.port,- "SEVER_NAME" => uri && uri.host- }- }-- request_context =- if user_agent do- Map.merge(request_context, %{- headers: %{- "User-Agent" => user_agent- }- })- else- request_context- end-- Sentry.Context.set_request_context(request_context)-- user_id = session["current_user_id"]-- if user_id do- Sentry.Context.set_user_context(%{- id: user_id- })- end-- {:cont, socket}- end-- defp get_ip(%{address: addr}) do- case :inet.ntoa(addr) do- {:error, _} -> ""- address -> to_string(address)- end- end-- defp get_ip(_), do: ""-enddiff --git a/lib/plausible_web/live/sites.ex b/lib/plausible_web/live/sites.exindex 3ef7f2f198..b9e37a5194 100644--- a/lib/plausible_web/live/sites.ex+++ b/lib/plausible_web/live/sites.ex@@ -3,7 +3,11 @@ defmodule PlausibleWeb.Live.Sites doLiveView for sites index."""- use PlausibleWeb, :live_view+ use Phoenix.LiveView, global_prefixes: ~w(x-)+ use PlausibleWeb.Live.Flash+ use Plausible++ alias Phoenix.LiveView.JSuse Phoenix.HTMLimport PlausibleWeb.Components.Generic@@ -14,6 +18,7 @@ defmodule PlausibleWeb.Live.Sites doalias Plausible.Sitealias Plausible.Sitesalias Plausible.Site.Memberships.Invitations+ alias PlausibleWeb.Router.Helpers, as: Routesdef mount(params, %{"current_user_id" => user_id}, socket) douri =diff --git a/test/plausible_web/live/sentry_context_test.exs b/test/plausible_web/live/sentry_context_test.exsdeleted file mode 100644index feb0446bba..0000000000--- a/test/plausible_web/live/sentry_context_test.exs+++ /dev/null@@ -1,78 +0,0 @@-defmodule PlausibleWeb.Live.SentryContextTest do- use PlausibleWeb.ConnCase, async: true- import Phoenix.LiveViewTest-- defmodule SampleLV do- use PlausibleWeb, :live_view-- def mount(_params, %{"test" => test_pid}, socket) do- socket = assign(socket, test_pid: test_pid)- {:ok, socket}- end-- def render(assigns) do- ~H"""- ok computer- """- end-- def handle_event("get_sentry_context", _params, socket) do- context = Sentry.Context.get_all()- send(socket.assigns.test_pid, {:context, context})- {:noreply, socket}- end- end-- describe "sentry context" do- test "basic shape", %{conn: conn} do- context_hook(conn)- assert_receive {:context, context}-- assert %{- extra: %{},- request: %{- env: %{- "REMOTE_ADDR" => "127.0.0.1",- "REMOTE_PORT" => port,- "SEVER_NAME" => "www.example.com"- },- host: :not_mounted_at_router- },- user: %{},- tags: %{},- breadcrumbs: []- } = context-- assert is_integer(port)- end-- test "user-agent is included", %{conn: conn} do- conn- |> put_req_header("user-agent", "Firefox")- |> context_hook()-- assert_receive {:context, context}- assert context.request.headers["User-Agent"] == "Firefox"- end-- test "user_id is included", %{conn: conn} do- context_hook(conn, %{"current_user_id" => 172})-- assert_receive {:context, context}- assert context.user.id == 172- end- end-- defp context_hook(conn, extra_session \\ %{}) do- lv = get_liveview(conn, extra_session)- assert render(lv) =~ "ok computer"- render_hook(lv, :get_sentry_context, %{})- end-- defp get_liveview(conn, extra_session) do- {:ok, lv, _html} =- live_isolated(conn, SampleLV, session: Map.merge(%{"test" => self()}, extra_session))-- lv- end-end