Module: Datadog::Tracing::MeasuredBuffer
- Included in:
- CRubyTraceBuffer, ThreadSafeTraceBuffer
- Defined in:
- lib/datadog/tracing/buffer.rb
Overview
Health metrics for trace buffers.
Instance Method Summary collapse
- #add!(trace) ⇒ Object
- #add_all!(traces) ⇒ Object
-
#drain! ⇒ Object
Stored traces are returned and the local buffer is reset.
- #initialize(*_) ⇒ Object
- #measure_accept(trace) ⇒ Object
- #measure_drop(trace) ⇒ Object
- #measure_pop(traces) ⇒ Object
- #replace!(trace) ⇒ Object
Instance Method Details
#add!(trace) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/datadog/tracing/buffer.rb', line 21 def add!(trace) super # Emit health metrics measure_accept(trace) end |
#add_all!(traces) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/datadog/tracing/buffer.rb', line 28 def add_all!(traces) super # Emit health metrics traces.each { |trace| measure_accept(trace) } end |
#drain! ⇒ Object
Stored traces are returned and the local buffer is reset.
46 47 48 49 50 |
# File 'lib/datadog/tracing/buffer.rb', line 46 def drain! traces = super measure_pop(traces) traces end |
#initialize(*_) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/datadog/tracing/buffer.rb', line 12 def initialize(*_) super @buffer_accepted = 0 @buffer_accepted_lengths = 0 @buffer_dropped = 0 @buffer_spans = 0 end |
#measure_accept(trace) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/datadog/tracing/buffer.rb', line 52 def measure_accept(trace) @buffer_accepted += 1 @buffer_accepted_lengths += trace.length @buffer_spans += trace.length rescue StandardError => e Datadog.logger.debug( "Failed to measure queue accept. Cause: #{e.class.name} #{e.} Source: #{Array(e.backtrace).first}" ) end |
#measure_drop(trace) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/datadog/tracing/buffer.rb', line 63 def measure_drop(trace) @buffer_dropped += 1 @buffer_spans -= trace.length rescue StandardError => e Datadog.logger.debug( "Failed to measure queue drop. Cause: #{e.class.name} #{e.} Source: #{Array(e.backtrace).first}" ) end |
#measure_pop(traces) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/datadog/tracing/buffer.rb', line 73 def measure_pop(traces) # Accepted, cumulative totals Datadog.health_metrics.queue_accepted(@buffer_accepted) Datadog.health_metrics.queue_accepted_lengths(@buffer_accepted_lengths) # Dropped, cumulative totals Datadog.health_metrics.queue_dropped(@buffer_dropped) # TODO: are we missing a +queue_dropped_lengths+ metric? # Queue gauges, current values Datadog.health_metrics.queue_max_length(@max_size) Datadog.health_metrics.queue_spans(@buffer_spans) Datadog.health_metrics.queue_length(traces.length) # Reset aggregated metrics @buffer_accepted = 0 @buffer_accepted_lengths = 0 @buffer_dropped = 0 @buffer_spans = 0 rescue StandardError => e Datadog.logger.debug( "Failed to measure queue. Cause: #{e.class.name} #{e.} Source: #{Array(e.backtrace).first}" ) end |
#replace!(trace) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/datadog/tracing/buffer.rb', line 35 def replace!(trace) discarded_trace = super # Emit health metrics measure_accept(trace) measure_drop(discarded_trace) if discarded_trace discarded_trace end |