Common initializers for logging and monitoring across Airhelp Rails projects:
- lograge - for readable rails http logs
- sidekiq statsd middleware - for sidekiq stats
Add this line to your application's Gemfile:
gem 'ah-lograge', git: 'https://github.com/AirHelp/ah-lograge'And then execute:
$ bundleJust install it. You can pass env variable DISABLE_LOGRAGE to disable it.
add config/initializers/lograge.rb to your app with following:
Ah::Lograge.filter_params do |params| params.delete("unwanted") endin config/initializers/lograge.rb add something like:
Ah::Lograge.additional_custom_entries do |event| { something: event.payload[:something] } endThe middleware requires sidekiq and statsd-ruby to operate (it needs to be provided in application gemfile). It will report various sidekiq metrics via statsd. There is a penalty: job execution duration will be 0.08s longer (we can live with that). If statsd host fails it will not interrupt normal sidekiq operation.
require 'ah/lograge/sidekiq_statsd_server_middleware' Sidekiq.configure_server do |config| config.server_middleware do |chain| chain.add Ah::Lograge::SidekiqStatsdServerMiddleware, statsd: Statsd.new(Settings.statsd_host) end endby default all calls will be gathered and reported by hostname like:
Completed 200 OK in 3222ms (Views: 81.2ms | ActiveRecord: 204.4ms | Http(airspace.ahinternal.net): 1944.4ms | Http(herman-staging.ahinternal.net): 313.2ms) if there is defined global variable $statsd with Statsd client instance it will be used to trace execution times and invocation counts
gem 'ah-lograge', require: ['ah/lograge/httparty'] class Gateway include HTTParty include Ah::Lograge::HTTParty::Instrumentation endJust create a PR & ping #dev-room or our developers email.
The gem is available as open source under the terms of the MIT License.