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.
1 defmodule AppsignalPhoenixExampleWeb.ClockLive do
2 use Phoenix.LiveView
3
4 def render(assigns) do
5 AppsignalPhoenixExampleWeb.ClockView.render("index.html", assigns)
6 end
7
8 def mount(_session, socket) do
9 :timer.send_interval(1000, self(), :tick)
10 {:ok, assign(socket, state: Time.utc_now())}
11 end
12
13
14 def handle_info(:tick, socket) do
15 {:ok, assign(socket, state: Time.utc_now())}
16 end
17 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:
1 defmodule AppsignalPhoenixExampleWeb.ClockLive do
2 use Phoenix.LiveView
3 import Appsignal.Phoenix.LiveView, only: [live_view_action: 4]
4
5 def render(assigns) do
6 AppsignalPhoenixExampleWeb.ClockView.render("index.html", assigns)
7 end
8
9 def mount(_session, socket) do
10 live_view_action(__MODULE__, "mount", socket, fn ->
11 :timer.send_interval(1000, self(), :tick)
12 {:ok, assign(socket, state: Time.utc_now())}
13 end)
14 end
15
16 def handle_info(:tick, socket) do
17 live_view_action(__MODULE__, "mount", socket, fn ->
18 {:ok, assign(socket, state: Time.utc_now())}
19 end)
20 end
21 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.
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!