Class: Flipper::Adapters::Instrumented

Inherits:
Decorator show all
Defined in:
lib/flipper/adapters/instrumented.rb

Overview

Internal: Adapter that wraps another adapter and instruments all adapter operations. Used by flipper dsl to provide instrumentatin for flipper.

Constant Summary collapse

InstrumentationName =

Private: The name of instrumentation events.

"adapter_operation.#{InstrumentationNamespace}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter, options = {}) ⇒ Instrumented

Internal: Initializes a new adapter instance.

adapter - Vanilla adapter instance to wrap.

options - The Hash of options.

:instrumenter - What to use to instrument all the things.


22
23
24
25
26
# File 'lib/flipper/adapters/instrumented.rb', line 22

def initialize(adapter, options = {})
  super(adapter)
  @name = :instrumented
  @instrumenter = options.fetch(:instrumenter, Instrumenters::Noop)
end

Instance Attribute Details

#instrumenterObject (readonly)

Private: What is used to instrument all the things.



13
14
15
# File 'lib/flipper/adapters/instrumented.rb', line 13

def instrumenter
  @instrumenter
end

Instance Method Details

#add(feature) ⇒ Object

Public



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/flipper/adapters/instrumented.rb', line 41

def add(feature)
  payload = {
    :operation => :add,
    :adapter_name => name,
    :feature_name => feature.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) { |payload|
    payload[:result] = super
  }
end

#clear(feature) ⇒ Object

Public



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/flipper/adapters/instrumented.rb', line 67

def clear(feature)
  payload = {
    :operation => :clear,
    :adapter_name => name,
    :feature_name => feature.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) { |payload|
    payload[:result] = super
  }
end

#disable(feature, gate, thing) ⇒ Object

Public



107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/flipper/adapters/instrumented.rb', line 107

def disable(feature, gate, thing)
  payload = {
    :operation => :disable,
    :adapter_name => name,
    :feature_name => feature.name,
    :gate_name => gate.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) { |payload|
    payload[:result] = super
  }
end

#enable(feature, gate, thing) ⇒ Object

Public



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/flipper/adapters/instrumented.rb', line 93

def enable(feature, gate, thing)
  payload = {
    :operation => :enable,
    :adapter_name => name,
    :feature_name => feature.name,
    :gate_name => gate.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) { |payload|
    payload[:result] = super
  }
end

#featuresObject

Public



29
30
31
32
33
34
35
36
37
38
# File 'lib/flipper/adapters/instrumented.rb', line 29

def features
  payload = {
    :operation => :features,
    :adapter_name => name,
  }

  @instrumenter.instrument(InstrumentationName, payload) { |payload|
    payload[:result] = super
  }
end

#get(feature) ⇒ Object

Public



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/flipper/adapters/instrumented.rb', line 80

def get(feature)
  payload = {
    :operation => :get,
    :adapter_name => name,
    :feature_name => feature.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) { |payload|
    payload[:result] = super
  }
end

#remove(feature) ⇒ Object

Public



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/flipper/adapters/instrumented.rb', line 54

def remove(feature)
  payload = {
    :operation => :remove,
    :adapter_name => name,
    :feature_name => feature.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) { |payload|
    payload[:result] = super
  }
end