Module: Datadog::Tracing::Utils::TraceId

Defined in:
lib/datadog/tracing/utils.rb

Overview

The module handles bitwise operation for trace id

Constant Summary collapse

MAX =
(1 << 128) - 1

Class Method Summary collapse

Class Method Details

.concatenate(high_order, low_order) ⇒ Object



77
78
79
# File 'lib/datadog/tracing/utils.rb', line 77

def concatenate(high_order, low_order)
  high_order << 64 | low_order
end

.next_idObject

Format for generating 128 bits trace id =>

  • 32-bits : seconds since Epoch

  • 32-bits : set to zero,

  • 64 bits : random 64-bits



60
61
62
63
64
65
66
67
# File 'lib/datadog/tracing/utils.rb', line 60

def next_id
  return Utils.next_id unless Datadog.configuration.tracing.trace_id_128_bit_generation_enabled

  concatenate(
    Core::Utils::Time.now.to_i << 32,
    Utils.next_id
  )
end

.to_high_order(trace_id) ⇒ Object



69
70
71
# File 'lib/datadog/tracing/utils.rb', line 69

def to_high_order(trace_id)
  trace_id >> 64
end

.to_low_order(trace_id) ⇒ Object



73
74
75
# File 'lib/datadog/tracing/utils.rb', line 73

def to_low_order(trace_id)
  trace_id & 0xFFFFFFFFFFFFFFFF
end