Better Appsignal logs for Her
Her is a Ruby gem which maps REST resources to Ruby objects. We use it to conveniently consume APIs. Appsignal on the other hand is a software monitoring service. We use the Ruby integration to log slow requests in our Rails app. So each time Her makes a request to our APIs, Appsignal tracks that. On the dashboard this looks like this:
It would be nice to have a bit more information here. While we could use Appsignal.instrument
in our Her base model to manually inject some more context, there’s a nice out-of-the box solution for that. There are three things we need to have in mind for that:
- Her uses Faraday as HTTP backend
- Faraday can use ActiveSupport::Notifications to notify listeners about events (see Faraday source)
- Appsignal listens to events from Faraday per default (see Appsignal source)
The only thing we need to do, is to activate Faraday::Request::Instrumentation for Her in its setup code:
Her::API.setup url: 'https://api.example.com' do |c|
…
c.use Faraday::Request::Instrumentation
…
end
After this, your Appsignal request logs will include an new tree node request.faraday
. It includes now method, protocol, host and path — how nice!
This is only the map to the rabbit hole. You can get wild with your own Rack middleware for Her or Faraday, with ActiveSupport::Notifications or directly with Appsignal’s powerful helpers like method instrumentation.