PhoenixReplay.Capture.LiveComponents (PhoenixReplay v0.6.2)

Copy Markdown View Source

Records LiveComponent state from LiveView's telemetry events.

LiveComponents have no on_mount hook, but LiveView emits [:phoenix, :live_component, :update | :handle_event, :stop] and [:phoenix, :live_component, :destroyed] from the LiveView process with the component's socket. The handlers attached here run in that process, find its session in PhoenixReplay.Session.Buffer, and record:

  • :event — %{name: String.t(), params: map, target: {module, id}}, an event handled by a component, which the view's own hooks never see
  • :component — %{module: module, id: term, assigns: map}, the component assigns changed by an update or event
  • :component_destroyed — %{module: module, id: term}

LiveView does not yet emit telemetry for async results applied to a component; PhoenixReplay.Capture.AsyncResults covers them until it does.

Components of LiveViews that are not recorded cost one ETS lookup per event. Assigns go through the session's PhoenixReplay.Sanitizer.

:telemetry detaches a handler that raises, which would stop component recording for the whole application, so the handlers match metadata loosely and ignore shapes they do not expect, and a failure is reported with [:phoenix_replay, :collector, :exception], as collectors' are.

Summary

Functions

Attaches the telemetry handlers. Called by PhoenixReplay.Capture.Handlers.

Detaches the telemetry handlers, if attached.

Handles a LiveComponent telemetry event in the LiveView process. A failure, such as a custom sanitizer raising, is reported with PhoenixReplay.Telemetry.collector_failed/5 instead of raised: :telemetry would detach the handler for the whole application.

Functions

attach()

@spec attach() :: :ok | {:error, :already_exists}

Attaches the telemetry handlers. Called by PhoenixReplay.Capture.Handlers.

detach()

@spec detach() :: :ok

Detaches the telemetry handlers, if attached.

handle_event(event, measures, metadata, handler_config)

@spec handle_event([atom()], map(), map(), term()) :: :ok

Handles a LiveComponent telemetry event in the LiveView process. A failure, such as a custom sanitizer raising, is reported with PhoenixReplay.Telemetry.collector_failed/5 instead of raised: :telemetry would detach the handler for the whole application.