class ZipkinTracer::TraceGenerator
This class generates trace ids.
Constants
- DEFAULT_SAMPLE_RATE
- TRACE_ID_HIGH_32BIT_UPPER_BOUND
- TRACE_ID_UPPER_BOUND
Public Instance Methods
current()
click to toggle source
# File lib/zipkin-tracer/trace_generator.rb, line 13 def current if TraceContainer.tracing_information_set? TraceContainer.current else generate_trace_id end end
generate_id()
click to toggle source
# File lib/zipkin-tracer/trace_generator.rb, line 34 def generate_id rand(TRACE_ID_UPPER_BOUND) end
generate_id_from_span_id(span_id)
click to toggle source
# File lib/zipkin-tracer/trace_generator.rb, line 30 def generate_id_from_span_id(span_id) Trace.trace_id_128bit ? generate_id_128bit(span_id) : span_id end
generate_trace_id()
click to toggle source
# File lib/zipkin-tracer/trace_generator.rb, line 21 def generate_trace_id span_id = generate_id Trace::TraceId.new(generate_id_from_span_id(span_id), nil, span_id, should_sample?.to_s, Trace::Flags::EMPTY) end
next_trace_id()
click to toggle source
Next id, based on the current information in the container
# File lib/zipkin-tracer/trace_generator.rb, line 5 def next_trace_id if TraceContainer.tracing_information_set? TraceContainer.current.next_id else generate_trace_id end end
should_sample?()
click to toggle source
# File lib/zipkin-tracer/trace_generator.rb, line 26 def should_sample? rand < (Trace.sample_rate || DEFAULT_SAMPLE_RATE) end
Private Instance Methods
generate_id_128bit(span_id)
click to toggle source
# File lib/zipkin-tracer/trace_generator.rb, line 40 def generate_id_128bit(span_id) trace_id_low_64bit = '%016x' % span_id "#{trace_id_epoch_seconds}#{trace_id_high_32bit}#{trace_id_low_64bit}".hex end
trace_id_epoch_seconds()
click to toggle source
# File lib/zipkin-tracer/trace_generator.rb, line 45 def trace_id_epoch_seconds '%08x' % Time.now.to_i end
trace_id_high_32bit()
click to toggle source
# File lib/zipkin-tracer/trace_generator.rb, line 49 def trace_id_high_32bit '%08x' % rand(TRACE_ID_HIGH_32BIT_UPPER_BOUND) end