Sha256: ce69224ea86efedb992eddc81c3473c4099074c44f8fb70ac76ffb77d3dc5dca
Contents?: true
Size: 1.31 KB
Versions: 4
Compression:
Stored size: 1.31 KB
Contents
require 'thread' module Datadog # Trace buffer that stores application traces. The buffer has a maximum size and when # the buffer is full, a random trace is discarded. This class is thread-safe and is used # automatically by the ``Tracer`` instance when a ``Span`` is finished. class TraceBuffer def initialize(max_size) @max_size = max_size @mutex = Mutex.new() @traces = [] end # Add a new ``trace`` in the local queue. This method doesn't block the execution # even if the buffer is full. In that case, a random trace is discarded. def push(trace) @mutex.synchronize do len = @traces.length if len < @max_size || @max_size <= 0 @traces << trace else # we should replace a random trace with the new one @traces[rand(len)] = trace end end end # Return the current number of stored traces. def length @mutex.synchronize do return @traces.length end end # Return if the buffer is empty. def empty? @mutex.synchronize do return @traces.empty? end end # Stored traces are returned and the local buffer is reset. def pop @mutex.synchronize do traces = @traces @traces = [] return traces end end end end
Version data entries
4 entries across 4 versions & 2 rubygems
Version | Path |
---|---|
fair-ddtrace-0.8.2.a | lib/ddtrace/buffer.rb |
ddtrace-0.8.2 | lib/ddtrace/buffer.rb |
ddtrace-0.8.1 | lib/ddtrace/buffer.rb |
ddtrace-0.8.0 | lib/ddtrace/buffer.rb |