Module: NewRelic::TelemetrySdk::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/newrelic/telemetry_sdk/util.rb

Constant Summary collapse

HEX_DIGITS =
(0..15).map{|i| i.to_s(16)}

Class Method Summary collapse

Class Method Details

.current_timeObject



28
29
30
# File 'lib/newrelic/telemetry_sdk/util.rb', line 28

def current_time
  Time.now
end

.generate_guid(length = 16) ⇒ Object

This method intentionally does not use SecureRandom, because it relies on urandom, which raises an exception in MRI when the interpreter runs out of allocated file descriptors. The guids generated by this method may not be secure, but they are random enough for our purposes.



20
21
22
23
24
25
26
# File 'lib/newrelic/telemetry_sdk/util.rb', line 20

def generate_guid length = 16
  guid = String.new
  length.times do |a|
    guid << HEX_DIGITS[rand(16)]
  end
  guid
end

.time_to_ms(time = current_time) ⇒ Object



32
33
34
# File 'lib/newrelic/telemetry_sdk/util.rb', line 32

def time_to_ms time = current_time
  (time.to_f * 1000).round
end