appsignal

Elixir Package 1.13: Phoenix LiveView Helpers and Updated Typespecs

Jeff Kreeftmeijer

Jeff Kreeftmeijer on

Elixir Package 1.13: Phoenix LiveView Helpers and Updated Typespecs

With a special thanks to Aleksandar and Unai, we're happy to announce AppSignal for Elixir 1.13.0, which includes our all-new LiveView instrumentation helpers and updated typespecs.

If you're not an AppSignal user yet, make sure to check out the product tour and see how errors, performance, host metrics and triggers all come together in one tool.

Using the LiveView Helpers

Phoenix LiveView renders HTML on the server and uses web sockets to push changes to the client in real-time. To gain insights into their performance, AppSignal for Elixir 1.13.0 ships with a LiveView helper to instrument those server sight actions.

A LiveView action is instrumented by wrapping its contents in a Appsignal.Phoenix.LiveView.live_view_action/4 block.

Elixir
defmodule AppsignalPhoenixExampleWeb.ClockLive do use Phoenix.LiveView def render(assigns) do AppsignalPhoenixExampleWeb.ClockView.render("index.html", assigns) end def mount(_session, socket) do :timer.send_interval(1000, self(), :tick) {:ok, assign(socket, state: Time.utc_now())} end def handle_info(:tick, socket) do {:ok, assign(socket, state: Time.utc_now())} end end

Given a live view that updates its state every second, we can add AppSignal instrumentation by wrapping both the mount/2 and handle_info/2 functions with a Appsignal.Phoenix.LiveView.live_view_action/4 call:

Elixir
defmodule AppsignalPhoenixExampleWeb.ClockLive do use Phoenix.LiveView import Appsignal.Phoenix.LiveView, only: [live_view_action: 4] def render(assigns) do AppsignalPhoenixExampleWeb.ClockView.render("index.html", assigns) end def mount(_session, socket) do live_view_action(__MODULE__, "mount", socket, fn -> :timer.send_interval(1000, self(), :tick) {:ok, assign(socket, state: Time.utc_now())} end) end def handle_info(:tick, socket) do live_view_action(__MODULE__, "mount", socket, fn -> {:ok, assign(socket, state: Time.utc_now())} end) end end

Calling one of these functions in your app will now automatically create a sample that's sent to AppSignal. These are displayed under the :live_view namespace.

AppSignal LiveView Preview

Typespecs and Behaviours

The Appsignal.Phoenix.Channel.channel_action/4 function has an updated typespec in 1.13.0, which prevents Dialyzer errors when using the @channel_action decorator in your apps.

Also, Unai added the missing record_event callback, in our TransactionBehaviour, which fixes issues when using the behaviour when mocking with Mox.

You can keep an eye on our changelog for incoming or past changes to our Elixir integration. And as always: get in touch if you have any questions, compliments, or encounter problems after upgrading. We're happy to help!

Become our next author!

Find out more

AppSignal monitors your apps

AppSignal provides insights for Ruby, Rails, Elixir, Phoenix, Node.js, Express and many other frameworks and libraries. We are located in beautiful Amsterdam. We love stroopwafels. If you do too, let us know. We might send you some!

Discover AppSignal
AppSignal monitors your apps