[011.5] Monitoring with AppSignal

Add Performance Monitoring to a Phoenix app in five minutes or less.

Subscribe now

Monitoring with AppSignal [09.23.2017]

Firestorm's been deployed for a little, but right now we have essentially no insight into the performance of the app in production. We'll integrate AppSignal into our app. AppSignal offers what they call consolidated monitoring - errors, performance, server metrics and custom metrics all in one. With AppSignal, we can see how our app's performing, so we can fix problems when they crop up. Let's get started.


We're starting with the dailydrip/firestorm repo tagged before this episode.

First, we'll install the appsignal package:

vim mix.exs
defmodule FirestormWeb.Mixfile do
  # ...
  defp deps do
      # ...
      {:appsignal, "~> 1.0"},
      # ...
  # ...
mix deps.get

Then we'll install it using the provided mix task:

mix appsignal.install $YOURKEY

We'll be asked a few questions: our application's name, and whether we prefer to configure AppSignal with a config/appsignal.exs file or via environment variables. I prefer environment variables.

The necessary environment variables for a basic setup are APPSIGNAL_APP_NAME, APPSIGNAL_APP_ENV, and APPSIGNAL_PUSH_API_KEY. There are more detailed configuration settings available as well.

This is sufficient for a basic Elixir integration. We have a Phoenix app, so we need to follow the Phoenix integration guide.

We'll start by adding use Appsignal.Phoenix in our endpoint, directly before the Router plug:

vim lib/firestorm_web/web/endpoint.ex
defmodule FirestormWeb.Web.Endpoint do
  # ...
  use Appsignal.Phoenix
  plug FirestormWeb.Web.Router
  # ...

This will create a transaction for every HTTP request which is performed on the endpoint.

Phoenix also has instrumentation hooks built in, and we can configure it to use the Appsignal.Phoenix.Instrumenter:

vim config/prod.exs
# ...
config :firestorm_web, FirestormWeb.Web.Endpoint,
  # ...
  instrumenters: [Appsignal.Phoenix.Instrumenter]
# ...

We can also add instrumentation to measure the time it takes to render our templates. We just need to register the AppSignal template engine:

config :phoenix, :template_engines,
  eex: Appsignal.Phoenix.Template.EExEngine,
  exs: Appsignal.Phoenix.Template.ExsEngine

We would also like to add query logging, for insight into how our database queries are performing. We can do this by adding the Appsignal.Ecto logger to our list of loggers for the main Repo. We'll need to include Ecto.LogEntry as well, since we're overriding the default.

config :firestorm_web, FirestormWeb.Repo,
  # ...
  loggers: [Appsignal.Ecto, Ecto.LogEntry]

Finally, we'll instrument our channels. We'll do this using module attribute decorators, though you can also do this in a more explicit manner - it's just a bit more code.

vim lib/firestorm_web/web/channels/store_channel.ex
defmodule FirestormWeb.Web.StoreChannel do
  use FirestormWeb.Web, :channel
  use Appsignal.Instrumentation.Decorators
  # ...
  @decorate channel_action()
  def handle_in("fetch_home_data", _, socket) do
    # ...

  @decorate channel_action()
  def handle_in("fetch", replenish_request, socket) do
    # ...

With that, AppSignal should be integrated into our application.

We'll want to make sure AppSignal knows each time we deploy. Firestorm's currently deployed to Heroku, so we can use the deployhooks addon to notify AppSignal after each deploy:

heroku addons:create deployhooks:http \

Now we can deploy it and start monitoring Firestorm in AppSignal:

git checkout -b feature/add_appsignal
git add .
git commit -m"Add AppSignal"
git push heroku feature/add_appsignal:master

We'll visit the site and click around a bit. Then we can look at the AppSignal Dashboard to see the data that's been gathered:


We can click around a bit and see what kind of insights we can see. Let's look at a controller action.

Controller Action

We can also see a graph of performance over time.

Performance Graph

In addition to basic Application Performance Monitoring, AppSignal also provides:

Error Tracking

See when and where errors are happening, with stacktraces and integration with your Issue Tracker.

Error Tracking

Host Metrics

See your Load Average, CPU Usage, Memory, Disk IO, Network Traffic, and Disk Usage over time.

Host Metrics

Custom Metrics

AppSignal also supports custom metrics and dashboards. We'll go into these in more depth in the next AppSignal episode.

Team Features and Integrations

They also support team management, as well as a host of integrations, as seen here.

Team Features and Integrations

Try AppSignal in your app to get more insight into what's happening behind the scenes.


In less than five minutes, we've added Consolidated Monitoring to Firestorm with AppSignal. It seems to be pretty extensive, hooking into the most important bits of our app quickly. I hope you'll take the chance to add it to your app and start getting more detailed information about its production performance. See you soon!