Thank you for your help
After I turn off the default debug message and set my own telemetry event receiver, it works now.
defmodule MyApp.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
def start(_type, _args) do
:telemetry.attach(
"my-app-handler",
[:my_app, :repo, :query],
&MyApp.Telemetry.handle_event/4,
%{}
)
.
.
defmodule MyApp.Telemetry do
require Logger
def handle_event([:my_app, :repo, :query], measurements, metadata, _config) do
Logger.info(fn ->
to_iodata(measurements, metadata)
end)
end
def to_iodata(measurements, metadata) do
%{
query_time: query_time,
decode_time: decode_time,
queue_time: queue_time
} = measurements
%{
params: params,
query: query,
result: result,
source: source
} = metadata
params = Enum.map(params, &decode_value/1)
[
"QUERY",
?\s,
ok_error(result),
ok_source(source),
time("db", query_time, true),
time("decode", decode_time, false),
time("queue", queue_time, false),
?\n,
query,
?\s,
inspect(params, charlists: false)
]
end
defp decode_value(value) when is_list(value) do
Enum.map(value, &decode_value/1)
end
defp decode_value(binary) when is_binary(binary) do
case Ecto.UUID.cast(binary) do
{:ok, uuid} -> uuid
:error -> binary
end
end
defp decode_value(%Ecto.Query.Tagged{value: value}), do: value
defp decode_value(value), do: value
## Helpers
defp ok_error({:ok, _}), do: "OK"
defp ok_error({:error, _}), do: "ERROR"
defp ok_source(nil), do: ""
defp ok_source(source), do: " source=#{inspect(source)}"
defp time(_label, nil, _force), do: []
defp time(label, time, force) do
us = System.convert_time_unit(time, :native, :microsecond)
ms = div(us, 100) / 10
if force or ms > 0 do
[?\s, label, ?=, :io_lib_format.fwrite_g(ms), ?m, ?s]
else
[]
end
end
end
And this is the result
SELECT t0."id", t0."completed_at", t0."description", t0."gitlab_project_id", t0."is_completed", t0."mr_id", t0."position", t0."stage_id", t0."story_id", t0."tags", t0."title", t0."created_by", t0."updated_by", t0."created_at", t0."updated_at" FROM "tasks" AS t0 WHERE (t0."story_id" = ANY($1)) [["0738f062-fdbc-45b1-a25f-7955a6496996", "2b15858a-2344-4a58-9066-cfc3a0a00edc"]]