Class: Dontbugme::Subscribers::Cache
- Inherits:
-
Object
- Object
- Dontbugme::Subscribers::Cache
- Defined in:
- lib/dontbugme/subscribers/cache.rb
Constant Summary collapse
- EVENTS =
%w[ cache_read.active_support cache_write.active_support cache_delete.active_support cache_exist?.active_support ].freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.subscribe ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/dontbugme/subscribers/cache.rb', line 13 def self.subscribe return unless defined?(ActiveSupport::Cache::Store) EVENTS.each do |event| ::ActiveSupport::Notifications.subscribe(event) do |*args| new.call(*args) end end end |
Instance Method Details
#call(name, start, finish, _id, payload) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dontbugme/subscribers/cache.rb', line 23 def call(name, start, finish, _id, payload) return unless Context.active? return unless Dontbugme.config.recording? duration_ms = ((finish - start) * 1000).round(2) operation = payload[:operation] || payload['operation'] || extract_operation(name) key = payload[:key] || payload['key'] hit = payload[:hit] if payload.key?(:hit) || payload.key?('hit') detail = "cache #{operation} #{key}" payload_data = { key: key } payload_data[:hit] = hit unless hit.nil? payload_data[:super_operation] = payload[:super_operation] if payload[:super_operation] Recorder.add_span( category: :cache, operation: operation.to_s.upcase, detail: detail, payload: payload_data, duration_ms: duration_ms, started_at: start ) end |