Instrumenter to handle logging of various instrumentation events.
Phoenix uses the :telemetry
library for instrumentation. The following events are published by Phoenix with the following measurements and metadata:
[:phoenix, :endpoint, :start]
- dispatched by Plug.Telemetry
in your endpoint, usually after code reloading
%{system_time: system_time}
%{conn: Plug.Conn.t, options: Keyword.t}
%{log: Logger.level | false}
plug Plug.Telemetry, ..., log: Logger.level | false
[:phoenix, :endpoint, :stop]
- dispatched by Plug.Telemetry
in your endpoint whenever the response is sent
%{duration: native_time}
%{conn: Plug.Conn.t, options: Keyword.t}
%{log: Logger.level | false}
plug Plug.Telemetry, ..., log: Logger.level | false
[:phoenix, :router_dispatch, :start]
- dispatched by Phoenix.Router
before dispatching to a matched route
%{system_time: System.system_time}
%{conn: Plug.Conn.t, route: binary, plug: module, plug_opts: term, path_params: map, pipe_through: [atom], log: Logger.level | false}
log: false
to the router macro, for example: get("/page", PageController, :index, log: false)
[:phoenix, :router_dispatch, :exception]
- dispatched by Phoenix.Router
after exceptions on dispatching a route
%{duration: native_time}
%{conn: Plug.Conn.t, kind: :throw | :error | :exit, reason: term(), stacktrace: Exception.stacktrace()}
[:phoenix, :router_dispatch, :stop]
- dispatched by Phoenix.Router
after successfully dispatching a matched route
%{duration: native_time}
%{conn: Plug.Conn.t, route: binary, plug: module, plug_opts: term, path_params: map, pipe_through: [atom], log: Logger.level | false}
[:phoenix, :error_rendered]
- dispatched at the end of an error view being rendered
%{duration: native_time}
%{conn: Plug.Conn.t, status: Plug.Conn.status, kind: Exception.kind, reason: term, stacktrace: Exception.stacktrace}
render_errors: [log: false]
on your endpoint configuration[:phoenix, :socket_connected]
- dispatched by Phoenix.Socket
, at the end of a socket connection
%{duration: native_time}
%{endpoint: atom, transport: atom, params: term, connect_info: map, vsn: binary, user_socket: atom, result: :ok | :error, serializer: atom, log: Logger.level | false}
use Phoenix.Socket, log: false
or socket "/foo", MySocket, websocket: [log: false]
in your endpoint[:phoenix, :channel_joined]
- dispatched at the end of a channel join
%{duration: native_time}
%{result: :ok | :error, params: term, socket: Phoenix.Socket.t}
[:phoenix, :channel_handled_in]
- dispatched at the end of a channel handle in
%{duration: native_time}
%{event: binary, params: term, socket: Phoenix.Socket.t}
To see an example of how Phoenix LiveDashboard uses these events to create metrics, visit https://hexdocs.pm/phoenix_live_dashboard/metrics.html.
When logging parameters, Phoenix can filter out sensitive parameters such as passwords and tokens. Parameters to be filtered can be added via the :filter_parameters
option:
config :phoenix, :filter_parameters, ["password", "secret"]
With the configuration above, Phoenix will filter any parameter that contains the terms password
or secret
. The match is case sensitive.
Phoenix's default is ["password"]
.
Phoenix can filter all parameters by default and selectively keep parameters. This can be configured like so:
config :phoenix, :filter_parameters, {:keep, ["id", "order"]}
With the configuration above, Phoenix will filter all parameters, except those that match exactly id
or order
. If a kept parameter matches, all parameters nested under that one will also be kept.
When you are using custom logging system it is not always desirable to enable Phoenix.Logger
by default. You can always disable this in general by:
config :phoenix, :logger, false
© 2014 Chris McCord
Licensed under the MIT License.
https://hexdocs.pm/phoenix/Phoenix.Logger.html