diff --git a/Gemfile b/Gemfile index 8bb7383..71f470a 100644 --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,11 @@ gem 'capistrano-rbenv' gem 'capistrano3-puma' gem "loofah", ">= 2.2.3" +# Honeycomb +gem 'sequel' +gem 'honeycomb-beeline' +gem 'rack-honeycomb', '~> 0.5.0' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4ac8823..d0c3d4c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,9 @@ class ApplicationController < ActionController::API + + if %w[production staging development].include? Rails.env + def append_info_to_payload(payload) + super(payload) + Rack::Honeycomb.add_field(request.env, 'classname', self.class.name) + end + end end diff --git a/config.ru b/config.ru index f7ba0b5..9172847 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,9 @@ # This file is used by Rack-based servers to start the application. +# + +# Initialize Honeycomb before everything else +require 'honeycomb-beeline' +Honeycomb.init require_relative 'config/environment' diff --git a/config/initializers/hacks/libhoney.rb b/config/initializers/hacks/libhoney.rb new file mode 100644 index 0000000..194d887 --- /dev/null +++ b/config/initializers/hacks/libhoney.rb @@ -0,0 +1,12 @@ +# frozen_string_literal:true + +Libhoney::LogTransmissionClient.class_eval do + def add(event) + if @verbose + data = "Honeycomb dataset '#{event.dataset}' | #{event.timestamp.iso8601}" + data << " (sample rate: #{event.sample_rate})" if event.sample_rate != 1 + @output.print("#{data} | ") + end + @output.puts(event.data.to_s.to_json) + end +end