OpentelemetryPhoenixLiveViewProcessPropagator.LiveView (OpentelemetryPhoenixLiveViewProcessPropagator v0.1.0)

View Source

OpentelemetryPhoenixLiveViewProcessPropagator.LiveView provides an extensions to the async functions in the Phoenix.LiveView to reduce boilerplate in propagating OpenTelemetry contexts across process boundaries.

Module Redefinement

This module does not redefine the Phoenix.Liveview module, instead it provides wrappers for async functions, so this functionality will not globally modify the default behavior of the Phoenix.Liveview module.

Usage

Require OpentelemetryPhoenixLiveViewProcessPropagator.LiveView in your live_view and live_component macros:

defmodule MyAppWeb do
  # ...
  def live_view do
    quote do
      use Phoenix.LiveView,
        layout: {MyAppWeb.Layouts, :app}

      require OpentelemetryPhoenixLiveViewProcessPropagator.LiveView

      unquote(html_helpers())
    end
  end

  def live_component do
    quote do
      use Phoenix.LiveComponent

      require OpentelemetryPhoenixLiveViewProcessPropagator.LiveView

      unquote(html_helpers())
    end
  end
end

Update all references to assign_async and start_async to use this module:

def mount(%{"slug" => slug}, _, socket) do
  {:ok,
  socket
  |> assign(:foo, "bar")
  |> OpentelemetryPhoenixLiveViewProcessPropagator.LiveView.assign_async(:org, fn -> {:ok, %{org: fetch_org!(slug)}} end)
  |> OpentelemetryPhoenixLiveViewProcessPropagator.LiveView.assign_async([:profile, :rank], fn -> {:ok, %{profile: ..., rank: ...}} end)}
end

Summary

Functions

assign_async(socket, key_or_keys, func, opts \\ [])

(macro)

start_async(socket, name, func, opts \\ [])

(macro)