diff --git a/lib/lightstep.rb b/lib/lightstep.rb index ccf7f4a..a6e9b36 100644 --- a/lib/lightstep.rb +++ b/lib/lightstep.rb @@ -22,6 +22,13 @@ module LightStep def self.micros(time) (time.to_f * 1E6).floor end + + # Returns a random guid. Note: this intentionally does not use SecureRandom, + # which is slower and cryptographically secure randomness is not required here. + def self.guid + @_rng ||= Random.new + @_rng.bytes(8).unpack('H*')[0] + end end require 'lightstep/tracer' diff --git a/lib/lightstep/span.rb b/lib/lightstep/span.rb index 751a86f..2c52616 100644 --- a/lib/lightstep/span.rb +++ b/lib/lightstep/span.rb @@ -43,7 +43,7 @@ module LightStep @baggage = Concurrent::Hash.new @tracer = tracer - @guid = tracer.generate_guid + @guid = LightStep.guid self.operation_name = operation_name self.start_micros = start_micros self.trace_guid = trace_guid diff --git a/lib/lightstep/tracer.rb b/lib/lightstep/tracer.rb index 0c1b6c3..3aa93bb 100644 --- a/lib/lightstep/tracer.rb +++ b/lib/lightstep/tracer.rb @@ -84,7 +84,7 @@ module LightStep child_of_guid = child_of.guid trace_guid = child_of.trace_guid else - trace_guid = generate_guid + trace_guid = LightStep.guid end Span.new( @@ -186,13 +186,6 @@ module LightStep @dropped_logs.increment if full end - # Returns a random guid. Note: this intentionally does not use SecureRandom, - # which is slower and cryptographically secure randomness is not required here. - def generate_guid - @_rng ||= Random.new - @_rng.bytes(8).unpack('H*')[0] - end - protected def access_token=(token) @@ -212,7 +205,7 @@ module LightStep @dropped_spans = Concurrent::AtomicFixnum.new start_time = LightStep.micros(Time.now) - @guid = generate_guid + @guid = LightStep.guid @report_start_time = start_time @last_flush_micros = start_time