Module: Datadog::Core::Utils

Extended by:
Forking
Defined in:
lib/datadog/core/utils.rb,
lib/datadog/core/utils/url.rb,
lib/datadog/core/utils/hash.rb,
lib/datadog/core/utils/time.rb,
lib/datadog/core/utils/base64.rb,
lib/datadog/core/utils/forking.rb,
lib/datadog/core/utils/network.rb,
lib/datadog/core/utils/duration.rb,
lib/datadog/core/utils/safe_dup.rb,
lib/datadog/core/utils/sequence.rb,
lib/datadog/core/utils/only_once.rb,
lib/datadog/core/utils/truncation.rb,
lib/datadog/core/utils/at_fork_monkey_patch.rb,
lib/datadog/core/utils/only_once_successful.rb

Overview

Utils contains low-level utilities, typically to provide pseudo-random trace IDs.

Defined Under Namespace

Modules: AtForkMonkeyPatch, Base64, Duration, Forking, Hash, Network, SafeDup, Time, Truncation, Url Classes: OnlyOnce, OnlyOnceSuccessful, Sequence

Constant Summary collapse

EMPTY_STRING =
''.encode(::Encoding::UTF_8).freeze

Class Method Summary collapse

Methods included from Forking

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

Class Method Details

.encode_tags(hash) ⇒ Object



69
70
71
72
73
74
# File 'lib/datadog/core/utils.rb', line 69

def self.encode_tags(hash)
  # Make sure everything is an utf-8 string, to avoid encoding issues in downstream
  hash.each_with_object({}) do |(key, value), h|
    h[utf8_encode(key)] = utf8_encode(value)
  end
end

.extract_host_port(host_port) ⇒ String, ...

Extracts hostname and port from a string that contains both, separated by ‘:’.

Returns:

  • (String, Integer)

    hostname and port

  • (nil)

    if format did not match



93
94
95
96
97
98
# File 'lib/datadog/core/utils.rb', line 93

def self.extract_host_port(host_port)
  match = /^([^:]+):(\d+)$/.match(host_port)
  return unless match

  [match[1], match[2].to_i]
end