View Source Sentry.LiveViewHook (Sentry v10.8.1)

A module that provides a Phoenix.LiveView hook to add Sentry context and breadcrumbs.

Available since v10.5.0.

This module sets context and breadcrumbs for the live view process through Sentry.Context. It sets things like:

  • The request URL
  • The user agent and user's IP address
  • Breadcrumbs for events that happen within LiveView

To make this module work best, you'll need to fetch information from the LiveView's WebSocket. You can do that when calling the socket/3 macro in your Phoenix endpoint. For example:

socket "/live", Phoenix.LiveView.Socket,
  websocket: [connect_info: [:peer_data, :uri, :user_agent]]

Examples

defmodule MyApp.UserLive do
  use Phoenix.LiveView

  on_mount Sentry.LiveViewHook

  # ...
end

You can do the same at the router level:

live_session :default, on_mount: Sentry.LiveViewHook do
  scope "..." do
    # ...
  end
end

You can also set this in your MyAppWeb module, so that all LiveViews that use MyAppWeb, :live_view will have this hook.