Class: LightStep::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/lightstep/reporter.rb

Overview

Reporter builds up reports of spans and flushes them to a transport

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_span_records:, transport:, guid:, component_name:) ⇒ Reporter

Returns a new instance of Reporter.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/lightstep/reporter.rb', line 8

def initialize(max_span_records:, transport:, guid:, component_name:)
  @max_span_records = max_span_records
  @span_records = Concurrent::Array.new
  @dropped_spans = Concurrent::AtomicFixnum.new
  @dropped_span_logs = Concurrent::AtomicFixnum.new
  @transport = transport

  start_time = LightStep.micros(Time.now)
  @guid = LightStep.guid
  @report_start_time = start_time

  @runtime = {
    guid: guid,
    start_micros: start_time,
    group_name: component_name,
    attrs: [
      {Key: "lightstep.tracer_platform",         Value: "ruby"},
      {Key: "lightstep.tracer_version",          Value: LightStep::VERSION},
      {Key: "lightstep.tracer_platform_version", Value: RUBY_VERSION}
    ]
  }.freeze

  reset_on_fork

  at_exit do
    @quit_signal << true
    @thread.join
  end
end

Instance Attribute Details

#max_span_recordsObject

Returns the value of attribute max_span_records.



6
7
8
# File 'lib/lightstep/reporter.rb', line 6

def max_span_records
  @max_span_records
end

Instance Method Details

#add_span(span) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lightstep/reporter.rb', line 38

def add_span(span)
  reset_on_fork

  @span_records.push(span.to_h)
  if @span_records.size > max_span_records
    dropped = @span_records.shift
    @dropped_spans.increment
    @dropped_span_logs.increment(dropped[:log_records].size + dropped[:dropped_logs])
  end

  @span_signal << true
end

#clearObject



51
52
53
54
55
56
57
58
59
# File 'lib/lightstep/reporter.rb', line 51

def clear
  span_records = @span_records.slice!(0, @span_records.length)
  @dropped_spans.increment(span_records.size)
  @dropped_span_logs.increment(
    span_records.reduce(0) {|memo, span|
      memo + span[:log_records].size + span[:dropped_logs]
    }
  )
end

#flushObject



61
62
63
64
# File 'lib/lightstep/reporter.rb', line 61

def flush
  @flush_signal << true
  ~@flush_response_signal
end