Remove DebugReplayInfo (#4842)

We have now better tools to debug queries 😈
This commit is contained in:
hq1 2024-11-20 09:20:35 +01:00 committed by GitHub
parent 7f783920f3
commit 7b49dd33c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 0 additions and 111 deletions

View File

@ -1,51 +0,0 @@
defmodule Plausible.DebugReplayInfo do
@moduledoc """
Function execution context (with arguments) to Sentry reports.
"""
require Logger
defmacro __using__(_) do
quote do
require Plausible.DebugReplayInfo
import Plausible.DebugReplayInfo, only: [include_sentry_replay_info: 0]
end
end
defmacro include_sentry_replay_info() do
module = __CALLER__.module
{function, arity} = __CALLER__.function
f = Function.capture(module, function, arity)
quote bind_quoted: [f: f] do
replay_info =
{f, binding()}
|> :erlang.term_to_iovec([:compressed])
|> IO.iodata_to_binary()
|> Base.encode64()
payload_size = byte_size(replay_info)
if payload_size <= 10_000 do
Sentry.Context.set_extra_context(%{
debug_replay_info: replay_info,
debug_replay_info_size: payload_size
})
else
Sentry.Context.set_extra_context(%{
debug_replay_info: :too_large,
debug_replay_info_size: payload_size
})
end
:ok
end
end
@spec deserialize(String.t()) :: any()
def deserialize(replay_info) do
replay_info
|> Base.decode64!()
|> :erlang.binary_to_term()
end
end

View File

@ -11,48 +11,37 @@ defmodule Plausible.Stats do
QueryRunner
}
use Plausible.DebugReplayInfo
def query(site, query) do
include_sentry_replay_info()
QueryRunner.run(site, query)
end
def breakdown(site, query, metrics, pagination) do
include_sentry_replay_info()
Breakdown.breakdown(site, query, metrics, pagination)
end
def aggregate(site, query, metrics) do
include_sentry_replay_info()
Aggregate.aggregate(site, query, metrics)
end
def timeseries(site, query, metrics) do
include_sentry_replay_info()
Timeseries.timeseries(site, query, metrics)
end
def current_visitors(site, duration \\ Duration.new!(minute: -5)) do
include_sentry_replay_info()
CurrentVisitors.current_visitors(site, duration)
end
on_ee do
def funnel(site, query, funnel) do
include_sentry_replay_info()
Plausible.Stats.Funnel.funnel(site, query, funnel)
end
end
def filter_suggestions(site, query, filter_name, filter_search) do
include_sentry_replay_info()
FilterSuggestions.filter_suggestions(site, query, filter_name, filter_search)
end
def custom_prop_value_filter_suggestions(site, query, prop_key, filter_search) do
include_sentry_replay_info()
FilterSuggestions.custom_prop_value_filter_suggestions(site, query, prop_key, filter_search)
end
end

View File

@ -1,49 +0,0 @@
defmodule Plausible.DebugReplayInfoTest do
use Plausible.DataCase, async: true
defmodule SampleModule do
use Plausible.DebugReplayInfo
def task(site, query, report_to) do
include_sentry_replay_info()
send(report_to, {:task_done, Sentry.Context.get_all()})
{:ok, {site, query}}
end
end
@tag :slow
test "adds replayable sentry context" do
site = insert(:site)
query = Plausible.Stats.Query.from(site, %{"period" => "day"})
{:ok, {^site, ^query}} = SampleModule.task(site, query, self())
assert_receive {:task_done, context}
assert is_integer(context.extra.debug_replay_info_size)
assert info = context.extra.debug_replay_info
{function, input} = Plausible.DebugReplayInfo.deserialize(info)
assert function == (&SampleModule.task/3)
assert input[:site] == site
assert input[:query] == query
assert input[:report_to] == self()
assert apply(function, [input[:site], input[:query], input[:report_to]])
assert_receive {:task_done, ^context}
end
test "won't add replay info, if serialized input too large" do
{:ok, _} =
SampleModule.task(
:crypto.strong_rand_bytes(10_000),
:crypto.strong_rand_bytes(10_000),
self()
)
assert_receive {:task_done, context}
assert context.extra.debug_replay_info == :too_large
assert context.extra.debug_replay_info_size > 10_000
end
end