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


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bugsnag/helpers.rb', line 46

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


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/bugsnag/helpers.rb', line 62

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


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bugsnag/helpers.rb', line 17

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