Installation
The AppSignal instrumentation for Plug is part of a separate package, which depends on the primaryappsignal package. Add the appsignal_plug package to your mix.exs file.
appsignal_phoenix package, it’s not necessary to add the appsignal_plug package as it’s already a dependency of the appsignal_phoenix package. See also our Phoenix integration guide.
Incoming HTTP requests
We’ll start out with a small Plug app that acceptsGET requests to / and
returns a welcome message. To start logging HTTP requests in this app, we’ll
use the Appsignal.Plug module.
Custom instrumentation
AlthoughAppsignal.Plug will start transactions for you, it won’t instrument
events in your app just yet. To do that, we need to add some custom
instrumentation.
This example app looks like the one we used before, but it has a slow function
(aptly named slow/0) we’d like to add instrumentation for. To do that, we need
to use the Appsignal.instrument/2-3 helper in our called function:
slow/0 function to the current transaction
whenever it’s called. For more information about custom instrumentation, read
the Elixir instrumentation documentation.
Instrumentation for included Plugs
Exceptions in included Plugs are automatically caught by AppSignal, but performance traces need to be set up manually using the custom instrumentation helpers or decorators.Plug instrumentation with decorators
To add instrumentation to Plugs, use theAppsignal.instrument/2 function: