Class: Flipper::Instrumentation::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/flipper/instrumentation/log_subscriber.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attachObject



75
76
77
# File 'lib/flipper/instrumentation/log_subscriber.rb', line 75

def self.attach
  attach_to InstrumentationNamespace
end

.detachObject



79
80
81
82
# File 'lib/flipper/instrumentation/log_subscriber.rb', line 79

def self.detach
  # Rails 5.2 doesn't support this, that's fine
  detach_from InstrumentationNamespace if respond_to?(:detach_from)
end

Instance Method Details

#adapter_operation(event) ⇒ Object

Logs an adapter operation. If operation is for a feature, then that feature is included in log output.

Example Output

# log output for adapter operation with feature
# Flipper feature(search) adapter(memory) enable  (0.0ms)  [ result=...]

# log output for adapter operation with no feature
# Flipper adapter(memory) features (0.0ms)  [ result=... ]

Returns nothing.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/flipper/instrumentation/log_subscriber.rb', line 51

def adapter_operation(event)
  return unless logger.debug?

  feature_name = event.payload[:feature_name]
  adapter_name = event.payload[:adapter_name]
  gate_name = event.payload[:gate_name]
  operation = event.payload[:operation]
  result = event.payload[:result]

  description = 'Flipper '
  description << "feature(#{feature_name}) " unless feature_name.nil?
  description << "adapter(#{adapter_name}) "
  description << "#{operation} "

  details = "result=#{result.inspect}"

  name = '%s (%.1fms)' % [description, event.duration]
  debug "  #{color_name(name)}  [ #{details} ]"
end

#feature_operation(event) ⇒ Object

Logs a feature operation.

Example Output

flipper[:search].enabled?(user)
# Flipper feature(search) enabled? false (1.2ms)  [ actors=... ]

Returns nothing.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/flipper/instrumentation/log_subscriber.rb', line 17

def feature_operation(event)
  return unless logger.debug?

  feature_name = event.payload[:feature_name]
  gate_name = event.payload[:gate_name]
  operation = event.payload[:operation]
  result = event.payload[:result]

  description = "Flipper feature(#{feature_name}) #{operation} #{result.inspect}"

  details = if event.payload.key?(:actors)
    "actors=#{event.payload[:actors].inspect}"
  else
    "thing=#{event.payload[:thing].inspect}"
  end

  details += " gate_name=#{gate_name}" unless gate_name.nil?

  name = '%s (%.1fms)' % [description, event.duration]
  debug "  #{color_name(name)}  [ #{details} ]"
end

#loggerObject



71
72
73
# File 'lib/flipper/instrumentation/log_subscriber.rb', line 71

def logger
  self.class.logger
end