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



93
94
95
# File 'lib/datadog/tracing/utils.rb', line 93

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



76
77
78
79
80
81
82
83
# File 'lib/datadog/tracing/utils.rb', line 76

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



85
86
87
# File 'lib/datadog/tracing/utils.rb', line 85

def to_high_order(trace_id)
  trace_id >> 64
end

.to_low_order(trace_id) ⇒ Object



89
90
91
# File 'lib/datadog/tracing/utils.rb', line 89

def to_low_order(trace_id)
  trace_id & 0xFFFFFFFFFFFFFFFF
end