Integrating AppSignal with Phoenix Liveview tutorial
I write open source software, check my Github!
Ping me for collabs
Search for a command to run...
I write open source software, check my Github!
Ping me for collabs
Hi S, thanks for a nice writeup! Feel free to reach out on Twitter if you'd like to get some more stroopwafels 😁
AppSignal deploy markers are a way to keep track of what git commit the bug happened, or when the slowdown started appearing in your app. https://docs.appsignal.com/application/markers/deploy-markers.html As long as you have an APP_REVISION environm...
Hey there, we're going to walk through deploying a Phoenix app to a DigitalOcean droplet, manually - no tools no nothing. Just straight up BASH! But don't worry, I've done the hard work so you don't have to. It occurred to me this week after seeing s...
It's generally a good idea to use binary ids / UUIds for the primary keys in your database. Here's how to easily do it in Rails 7, using Postgres! Configure your generators to use UUID for keys. Create a file in config/initializers/generators.rb Rail...
It's been really hard to figure this out and I had to cobble together many sources to get it working. Enjoy! We're going to build a direct image upload to Cloudflare B2 from the browser. That way the file doesn't travel to your servers and slow them...

Uploads files from your browser directly to your bucket.

Right, you want to use Appsignal to monitor your Phoenix Liveview application? Here's how you do it.
Note: This guide assumes you're on Liveview 0.17.5 or newer because we depend on the new liveview event hooks.
First install the appsignal_phoenix package. Because this package already depends on the appsignal package, there's no need for you to manually add it.
defp deps do
[
{:appsignal_phoenix, "~> 2.0"},
Then we're going to hook into the lifecycle in two spots. One for the mount event, and one for the handle_event.
In your myproject_web.ex add two on_mount handlers.
def live_view do
quote do
use Phoenix.LiveView,
layout: {GamingWeb.LayoutView, "live.html"}
on_mount(GamingWeb.InitAssigns)
on_mount(GamingWeb.Appsignal)
unquote(view_helpers())
end
end
Let's start by creating the InitAssigns module.
defmodule GamingWeb.InitAssigns do
@moduledoc false
import Phoenix.LiveView
import Appsignal.Phoenix.LiveView, only: [live_view_action: 5]
def on_mount(:default, params, session, socket) do
# here's where we're calling appsignal instrumentation
live_view_action(socket.view, "mount", params, socket, fn ->
socket =
socket
|> assign_new(:current_user, fn ->
get_user(session["user_token"])
end)
{:cont, socket}
end)
end
end
We're done, every mount will be tracked properly on Appsignal.

We're going to track the handle_event lifecycle event. If you want you can track others like:
defmodule GamingWeb.Appsignal do
@moduledoc false
import Phoenix.LiveView
import Appsignal.Phoenix.LiveView, only: [live_view_action: 5]
def on_mount(:default, _params, _session, socket) do
socket =
attach_hook(socket, :mount_hook, :handle_event, fn
event, params, socket ->
live_view_action(socket.view, event, params, socket, fn ->
{:cont, socket}
end)
end)
{:cont, socket}
end
end
And we're done. Here I'm tracking a simple form event named submit.
def handle_event("submit", %{"waitlist" => params}, socket) do
{:noreply, socket}
end
