Class: Racecar::Instrumenter

Inherits:
Object
  • Object
show all
Defined in:
lib/racecar/instrumenter.rb

Overview

Common API for instrumentation to standardize namespace and default payload

Constant Summary collapse

NAMESPACE =
"racecar"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_payload = {}) ⇒ Instrumenter

Returns a new instance of Instrumenter.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/racecar/instrumenter.rb', line 12

def initialize(default_payload = {})
  @default_payload = default_payload

  @backend = if defined?(ActiveSupport::Notifications)
    # ActiveSupport needs `concurrent-ruby` but doesn't `require` it.
    require 'concurrent/utility/monotonic_time'
    ActiveSupport::Notifications
  else
    NullInstrumenter
  end
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



10
11
12
# File 'lib/racecar/instrumenter.rb', line 10

def backend
  @backend
end

Instance Method Details

#instrument(event_name, payload = {}, &block) ⇒ Object



24
25
26
# File 'lib/racecar/instrumenter.rb', line 24

def instrument(event_name, payload = {}, &block)
  @backend.instrument("#{event_name}.#{NAMESPACE}", @default_payload.merge(payload), &block)
end