Compare commits

...

1 Commits

Author SHA1 Message Date
Karl-Aksel Puulmann da0638d198 Populate log_comment column with tags for performance analysis
These tags include information like plausible.site.id and http.route.

The tags will be exposed in system.query_log table log_comment column and can be used
for query performance analysis.

The tags are indirectly fetched from OpenTelemetry traces to avoid
duplicating data. The fetching mechanism is clunky and the best I
could figure out for now - help appreciated.
3 years ago

@ -25,4 +25,34 @@ defmodule Plausible.ClickhouseRepo do
|> Enum.to_list()
|> Keyword.values()
end
@doc """
Automatically adds tags as query log_comment setting for clickhouse queries.
These tags include information like plausible.site.id and http.route.
The tags will be exposed in system.query_log table log_comment column and can be used
for query performance analysis.
The tags are indirectly fetched from OpenTelemetry traces to avoid duplicating data.
"""
@impl true
def prepare_query(_operation, query, opts) do
setting = {:log_comment, Jason.encode!(current_trace_attributes())}
opts = Keyword.update(opts, :settings, [setting], fn settings -> [setting | settings] end)
{query, opts}
end
defp current_trace_attributes() do
try do
:ets.tab2list(:otel_span_table)
|> Enum.at(0)
|> elem(9)
|> elem(4)
rescue
_ -> %{}
end
end
end

Loading…
Cancel
Save