docbrown/lib/instrumentation.rb
rhymes 3b4bda89df Upgrade Honeycomb gem, fix and improve RssReader tests (#2319)
* Switch from deprecated honeycomb-rails to honeycomb-beeline

* Improve error handling, tests and add refactoring

* Fix multiple fetching test and add one more

The test wasn't actually testing the correct behavior, because the class
by default force fetches. It worked because it wasn't reloading the user
from the database.

* Test that Honeycomb's client is doing its thing

* Use some defensive programming to avoid any possible problem during shutdown

* Fix typo

* Use the new API to add fields to the current measured event

* Use default instrumentation and add user info to event

* Replace user.email with user.username, less personal data around

* Use mocking instead of calling Honeycomb.init

* Freeze time before traveling

* Remove a flaky test dependent on rand
2019-04-07 15:27:53 -04:00

26 lines
651 B
Ruby

require "rack/honeycomb/middleware"
module Instrumentation
def self.included(base)
base.before_action :add_user_info_to_honeycomb_event
end
def add_param_context(*keys)
keys.each do |key|
Rack::Honeycomb.add_field(request.env, key, params[key])
end
end
def add_context(metadata)
metadata.each do |key, value|
Rack::Honeycomb.add_field(request.env, key, value)
end
end
def add_user_info_to_honeycomb_event
return unless current_user
Rack::Honeycomb.add_field(request.env, "user.id", current_user.id)
Rack::Honeycomb.add_field(request.env, "user.username", current_user.username)
end
end