Module: ElasticAPM::Util

Defined in:
lib/elastic_apm/util.rb,
lib/elastic_apm/util/inflector.rb,
lib/elastic_apm/util/lru_cache.rb

Overview

rubocop:disable all

Defined Under Namespace

Modules: Inflector Classes: LruCache

Class Method Summary collapse

Class Method Details

.git_shaObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
18
# File 'lib/elastic_apm/util.rb', line 15

def self.git_sha
  sha = `git rev-parse --verify HEAD 2>&1`.chomp
  $? && $?.success? ? sha : nil
end

.hex_to_bits(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/elastic_apm/util.rb', line 20

def self.hex_to_bits(str)
  str.hex.to_s(2).rjust(str.size * 4, '0')
end

.micros(target = Time.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
# File 'lib/elastic_apm/util.rb', line 10

def self.micros(target = Time.now)
  utc = target.utc
  utc.to_i * 1_000_000 + utc.usec
end

.nearest_minute(target = Time.now.utc) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'lib/elastic_apm/util.rb', line 6

def self.nearest_minute(target = Time.now.utc)
  target - target.to_i % 60
end

.reverse_merge!(first, second) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/elastic_apm/util.rb', line 24

def self.reverse_merge!(first, second)
  first.merge!(second) { |_, old, _| old }
end

.truncate(value, max_length: 1024) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
# File 'lib/elastic_apm/util.rb', line 28

def self.truncate(value, max_length: 1024)
  return unless value
  return value if value.length <= max_length

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