pull/3971/merge
Karl-Aksel Puulmann 3 years ago committed by GitHub
commit 9ad83cedf5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -100,6 +100,7 @@ defmodule Plausible.Application do
opts = [strategy: :one_for_one, name: Plausible.Supervisor]
setup_request_logging()
setup_sentry()
setup_opentelemetry()
@ -175,6 +176,15 @@ defmodule Plausible.Application do
end
end
def setup_request_logging() do
:telemetry.attach(
"plausible-request-logging",
[:phoenix, :router_dispatch, :stop],
&Plausible.RequestLogger.log_request/4,
%{}
)
end
def setup_sentry() do
Logger.add_backend(Sentry.LoggerBackend)

@ -0,0 +1,19 @@
defmodule Plausible.RequestLogger do
@moduledoc """
Custom request logger which:
- Includes query parameters on the same line
- Includes request duration on the same line
"""
require Logger
def log_request(_, %{duration: duration}, %{conn: conn}, _) do
duration_ms = System.convert_time_unit(duration, :native, :millisecond)
path = path_with_params(conn.request_path, conn.query_string)
Logger.info("(#{conn.status}) #{conn.method} #{path} took #{duration_ms}ms")
end
defp path_with_params(request_path, ""), do: request_path
defp path_with_params(request_path, query_string), do: request_path <> "?" <> query_string
end

@ -69,7 +69,7 @@ defmodule PlausibleWeb.Endpoint do
plug(Plug.RequestId)
plug(PromEx.Plug, prom_ex_module: Plausible.PromEx)
plug(Plug.Telemetry, event_prefix: [:phoenix, :endpoint])
plug(Plug.Telemetry, event_prefix: [:phoenix, :endpoint], log: false)
plug(Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],

Loading…
Cancel
Save