Integrating AppSignal into Phoenix
The AppSignal for Elixir package integrates with Phoenix. To set up the integration, please follow our installation guide.
This page will describe further ways of configuring AppSignal for the Phoenix framework. To add more custom instrumentation to your Phoenix application, read the Elixir instrumentation documentation.
More information can be found in the AppSignal Hex package documentation.
Installation
-
The AppSignal instrumentation for Phoenix is part of a separate package, which depends on the primary
appsignal
package. Add theappsignal_phoenix
package to yourmix.exs
file. -
Then run
mix deps.get
. -
Then run
mix appsignal.install YOUR_PUSH_API_KEY
.
After installing and configuring, the AppSignal for Phoenix package automatically starts instrumenting HTTP requests, meaning no further setup is necessary.
To gain deeper insights, AppSignal can be set up to instrument channels and live views.
Channels
Channel instrumentation with a channel's handle
Incoming channel requests can be instrumented by wrapping the code in your
handle_in/3
functions with Appsignal.Phoenix.Channel.instrument/5
:
Alternatively, you can use function decorators to instrument channels. While less flexible than the instrumentation function, decorators minimize the amount of code you have to add to your application's channels.
Channel events will be displayed under the "Background jobs" tab, showing the channel module and the action argument that you entered.
LiveView
There are two different ways to instrument live views. You can either use our automatic telemetry handlers, or you can manually instrument your live view handlers with our helper functions.
Automatic telemetry handlers
AppSignal's LiveView Telemetry integration automatically instruments live view events.
To set it up, call Appsignal.Phoenix.LiveView.attach/0
to attach the LiveView Telemetry handlers.
We recommend calling this function from your app's application.ex
:
AppSignal will now automatically instrument all mount
, handle_event
and handle_param
events under the live_view
namespace, meaning you'll receive both performance and error insights into your live views.
Manual helper functions
A LiveView action can also be manually instrumented by wrapping its contents in a
Appsignal.Phoenix.LiveView.instrument/4
block.
Given a live view that updates its own state every second, we can add
AppSignal instrumentation by wrapping both the mount/2 and handle_info/2
functions with a Appsignal.Phoenix.LiveView.instrument
/4 call:
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.
Instrumentation for included Plugs
Exceptions in included Plugs are automatically caught by AppSignal, but performance samples need to be set up manually using the custom instrumentation helpers or decorators. See the Plug documentation for more information.
Custom instrumentation
Add custom instrumentation to keep track of more complex code and get more complete breakdowns of slow requests.