Class: LightStep::Reporter

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

Overview

Monkey patch of the LightStep library to make it not swallow reporting errors

Instance Method Summary collapse

Instance Method Details

#flushObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/bigcommerce/lightstep.rb', line 54

def flush
  reset_on_fork

  return if @span_records.empty?

  now = ::LightStep.micros(Time.now)

  span_records = @span_records.slice!(0, @span_records.length)
  dropped_spans = 0
  @dropped_spans.update do |old|
    dropped_spans = old
    0
  end

  report_request = {
    runtime: @runtime,
    oldest_micros: @report_start_time,
    youngest_micros: now,
    span_records: span_records,
    internal_metrics: {
      counts: [
        { name: 'spans.dropped', int64_value: dropped_spans }
      ]
    }
  }

  @report_start_time = now

  begin
    @transport.report(report_request)
  rescue StandardError => e
    Bigcommerce::Lightstep.logger.error "Failed to send request to collector: #{e.message}"
    # an error occurs, add the previous dropped_spans and count of spans
    # that would have been recorded
    @dropped_spans.increment(dropped_spans + span_records.length)
  end
end