Class: RSpec::Buildkite::Analytics::Tracer

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/buildkite/analytics/tracer.rb

Defined Under Namespace

Classes: Span

Instance Method Summary collapse

Constructor Details

#initializeTracer

Returns a new instance of Tracer.



30
31
32
33
# File 'lib/rspec/buildkite/analytics/tracer.rb', line 30

def initialize
  @top = Span.new(:top, Concurrent.monotonic_time, nil, {})
  @stack = [@top]
end

Instance Method Details

#backfill(section, duration, **detail) ⇒ Object



46
47
48
49
# File 'lib/rspec/buildkite/analytics/tracer.rb', line 46

def backfill(section, duration, **detail)
  new_entry = Span.new(section, Concurrent.monotonic_time - duration, Concurrent.monotonic_time, detail)
  current_span.children << new_entry
end

#current_spanObject



51
52
53
# File 'lib/rspec/buildkite/analytics/tracer.rb', line 51

def current_span
  @stack.last
end

#enter(section, **detail) ⇒ Object



35
36
37
38
39
# File 'lib/rspec/buildkite/analytics/tracer.rb', line 35

def enter(section, **detail)
  new_entry = Span.new(section, Concurrent.monotonic_time, nil, detail)
  current_span.children << new_entry
  @stack << new_entry
end

#finalizeObject



55
56
57
58
59
# File 'lib/rspec/buildkite/analytics/tracer.rb', line 55

def finalize
  raise "Stack not empty" unless @stack.size == 1
  @top.end_at = Concurrent.monotonic_time
  self
end

#historyObject



61
62
63
# File 'lib/rspec/buildkite/analytics/tracer.rb', line 61

def history
  @top.as_hash
end

#leaveObject



41
42
43
44
# File 'lib/rspec/buildkite/analytics/tracer.rb', line 41

def leave
  current_span.end_at = Concurrent.monotonic_time
  @stack.pop
end