Custom Phoenix Telemetry handlers

Phoenix.Logger defines an install/0 function to attach telemetry handlers:

  @doc false
  def install do
    handlers = %{
      [:phoenix, :endpoint, :start] => &phoenix_endpoint_start/4,
      [:phoenix, :endpoint, :stop] => &phoenix_endpoint_stop/4,
      [:phoenix, :router_dispatch, :start] => &phoenix_router_dispatch_start/4,
      # [:phoenix, :router_dispatch, :stop] => &phoenix_router_dispatch_stop/4,
      [:phoenix, :error_rendered] => &phoenix_error_rendered/4,
      [:phoenix, :socket_connected] => &phoenix_socket_connected/4,
      [:phoenix, :channel_joined] => &phoenix_channel_joined/4,
      [:phoenix, :channel_handled_in] => &phoenix_channel_handled_in/4

    for {key, fun} <- handlers do
      :telemetry.attach({__MODULE__, key}, key, fun, :ok)

Is it somehow possible to replace these with custom handlers?

You can always add more handlers as single event can have more than one handler. But in next(?) Phoenix release there will be configuration option to disable Phoenix.Logger if you do not want additional messages in logs.


Tnx @hauleth that would be perfect.