Opentelemetry Phoenix LiveView Process Propagator

View Source

Github CI hex.pm

Functions for cross-process opentelemetry context propagation in Phoenix LiveView.

Installation

Add opentelemetry_phoenix_live_view_process_propagator to your list of dependencies in mix.exs:

def deps do
  [
    {:opentelemetry_phoenix_live_view_process_propagator, "~> 0.1", only: [:dev, :test], runtime: false}
  ]
end

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 the references to assign_async and start_async to use this module:application

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