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
-
.next_id ⇒ Object
Return a randomly generated integer, valid as a Span ID or Trace ID.
-
.serialize_attribute(key, value) ⇒ Object
Serialize values into Datadog span tags and metrics.
Methods included from Core::Utils::Forking
after_fork!, extended, fork_pid, forked?, included, update_fork_pid!
Class Method Details
.next_id ⇒ Object
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 |
.serialize_attribute(key, value) ⇒ Object
Serialize values into Datadog span tags and metrics. Notably, arrays are exploded into many keys, each with a numeric suffix representing the array index, for example: ‘’foo’ => [‘a’,‘b’]‘ becomes `’foo.0’ => ‘a’, ‘foo.1’ => ‘b’‘
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/datadog/tracing/utils.rb', line 52 def self.serialize_attribute(key, value) if value.is_a?(Array) value.flat_map.with_index do |v, idx| serialize_attribute("#{key}.#{idx}", v) end elsif value.is_a?(TrueClass) || value.is_a?(FalseClass) [[key, value.to_s]] else [[key, value]] end end |