module ElasticAPM::Util

@api private

rubocop:disable all

Public Class Methods

git_sha() click to toggle source
# File lib/elastic_apm/util.rb, line 14
def self.git_sha
  sha = `git rev-parse --verify HEAD 2>&1`.chomp
  $? && $?.success? ? sha : nil
end
hex_to_bits(str) click to toggle source
# File lib/elastic_apm/util.rb, line 19
def self.hex_to_bits(str)
  str.hex.to_s(2).rjust(str.size * 4, '0')
end
micros(target = Time.now) click to toggle source
# File lib/elastic_apm/util.rb, line 9
def self.micros(target = Time.now)
  utc = target.utc
  utc.to_i * 1_000_000 + utc.usec
end
nearest_minute(target = Time.now.utc) click to toggle source
# File lib/elastic_apm/util.rb, line 5
def self.nearest_minute(target = Time.now.utc)
  target - target.to_i % 60
end
reverse_merge!(first, *others) click to toggle source
# File lib/elastic_apm/util.rb, line 23
def self.reverse_merge!(first, *others)
  others.reduce(first) do |curr, other|
    curr.merge!(other) { |_, _, new| new }
  end
end
truncate(value, max_length: 1024) click to toggle source
# File lib/elastic_apm/util.rb, line 29
def self.truncate(value, max_length: 1024)
  return unless value
  return value if value.length <= max_length

  value[0...(max_length - 1)] + '…'
end