Class: Flipper::Adapters::Instrumented

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

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.


20
21
22
23
24
# File 'lib/flipper/adapters/instrumented.rb', line 20

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

Instance Attribute Details

#instrumenterObject (readonly)

Private: What is used to instrument all the things.



11
12
13
# File 'lib/flipper/adapters/instrumented.rb', line 11

def instrumenter
  @instrumenter
end

Instance Method Details

#add(feature) ⇒ Object

Public



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

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



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

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



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

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



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

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



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

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

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

#get(feature) ⇒ Object

Public



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

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



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

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

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