Module: Skylight::Core::Fanout

Defined in:
lib/skylight/core/fanout.rb

Class Method Summary collapse

Class Method Details

.broken!Object


42
43
44
# File 'lib/skylight/core/fanout.rb', line 42

def self.broken!
  registered.each(&:broken!)
end

.done(spans, meta = nil) ⇒ Object


36
37
38
39
40
# File 'lib/skylight/core/fanout.rb', line 36

def self.done(spans, meta = nil)
  spans.reverse_each do |(target, span)|
    target.done(span, meta)
  end
end

.each_traceObject


50
51
52
53
54
55
56
# File 'lib/skylight/core/fanout.rb', line 50

def self.each_trace
  return to_enum(__method__) unless block_given?
  registered.each do |r|
    next unless r.instrumenter && (trace = r.instrumenter.current_trace)
    yield trace
  end
end

.endpoint=(endpoint) ⇒ Object


46
47
48
# File 'lib/skylight/core/fanout.rb', line 46

def self.endpoint=(endpoint)
  each_trace { |t| t.endpoint = endpoint }
end

.instrument(*args) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/skylight/core/fanout.rb', line 20

def self.instrument(*args)
  if block_given?
    spans = instrument(*args)
    meta = {}
    begin
      yield spans
    ensure
      done(spans, meta)
    end
  else
    registered.map do |r|
      [r, r.instrument(*args)]
    end
  end
end

.register(obj) ⇒ Object


8
9
10
# File 'lib/skylight/core/fanout.rb', line 8

def self.register(obj)
  registered.push(obj)
end

.registeredObject


4
5
6
# File 'lib/skylight/core/fanout.rb', line 4

def self.registered
  @registered ||= []
end

.trace(*args) ⇒ Object


16
17
18
# File 'lib/skylight/core/fanout.rb', line 16

def self.trace(*args)
  registered.map { |r| r.trace(*args) }
end

.unregister(obj) ⇒ Object


12
13
14
# File 'lib/skylight/core/fanout.rb', line 12

def self.unregister(obj)
  registered.delete(obj)
end