Module: Datadog::Tracing::Utils

Extended by:
Core::Utils::Forking
Defined in:
lib/datadog/tracing/utils.rb

Overview

Utils contains low-level tracing utility functions.

Defined Under Namespace

Modules: TraceId

Constant Summary collapse

RUBY_MAX_ID =

The max value for a Span identifier. Span and trace identifiers should be strictly positive and strictly inferior to this limit.

Limited to 2<<62-1 positive integers, as Ruby is able to represent such numbers “inline”, inside a VALUE scalar, thus not requiring memory allocation.

The range of IDs also has to consider portability across different languages and platforms.

(1 << 62) - 1
RUBY_ID_RANGE =

Excludes zero from possible values

(1..RUBY_MAX_ID).freeze
EXTERNAL_MAX_ID =

While we only generate 63-bit integers due to limitations in other languages, we support parsing 64-bit integers for distributed tracing since an upstream system may generate one

1 << 64

Class Method Summary collapse

Methods included from Core::Utils::Forking

after_fork!, extended, fork_pid, forked?, included, update_fork_pid!

Class Method Details

.next_idObject

Return a randomly generated integer, valid as a Span ID or Trace ID. This method is thread-safe and fork-safe.



35
36
37
38
# File 'lib/datadog/tracing/utils.rb', line 35

def self.next_id
  after_fork! { reset! }
  id_rng.rand(RUBY_ID_RANGE)
end