Module: Bugsnag::Helpers

Defined in:
lib/bugsnag/helpers.rb

Overview

rubocop:todo Metrics/ModuleLength

Constant Summary collapse

MAX_STRING_LENGTH =
3072
MAX_PAYLOAD_LENGTH =
512000
MAX_ARRAY_LENGTH =
80
MAX_TRIM_STACK_FRAMES =
30
RAW_DATA_TYPES =
[Numeric, TrueClass, FalseClass]

Class Method Summary collapse

Class Method Details

.deep_merge(l_hash, r_hash) ⇒ Object

Merges r_hash into l_hash recursively, favouring the values in r_hash.

Returns a new array consisting of the merged values



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bugsnag/helpers.rb', line 41

def self.deep_merge(l_hash, r_hash)
  l_hash.merge(r_hash) do |key, l_val, r_val|
    if l_val.is_a?(Hash) && r_val.is_a?(Hash)
      deep_merge(l_val, r_val)
    elsif l_val.is_a?(Array) && r_val.is_a?(Array)
      l_val.concat(r_val)
    else
      r_val
    end
  end
end

.deep_merge!(l_hash, r_hash) ⇒ Object

Merges r_hash into l_hash recursively, favouring the values in r_hash.

Overwrites the values in the existing l_hash



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bugsnag/helpers.rb', line 57

def self.deep_merge!(l_hash, r_hash)
  l_hash.merge!(r_hash) do |key, l_val, r_val|
    if l_val.is_a?(Hash) && r_val.is_a?(Hash)
      deep_merge(l_val, r_val)
    elsif l_val.is_a?(Array) && r_val.is_a?(Array)
      l_val.concat(r_val)
    else
      r_val
    end
  end
end

.trim_if_needed(value) ⇒ Object

Trim the size of value if the serialized JSON value is longer than is accepted by Bugsnag



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bugsnag/helpers.rb', line 12

def self.trim_if_needed(value)
  value = "" if value.nil?

  return value unless payload_too_long?(value)

  # Truncate exception messages
  reduced_value = truncate_exception_messages(value)
  return reduced_value unless payload_too_long?(reduced_value)

  # Trim metadata
  reduced_value = (reduced_value)
  return reduced_value unless payload_too_long?(reduced_value)

  # Trim code from stacktrace
  reduced_value = trim_stacktrace_code(reduced_value)
  return reduced_value unless payload_too_long?(reduced_value)

  # Remove metadata
  reduced_value = (reduced_value)
  return reduced_value unless payload_too_long?(reduced_value)

  # Remove oldest functions in stacktrace
  trim_stacktrace_functions(reduced_value)
end