Class: Rollbar::Item
- Inherits:
-
Object
- Object
- Rollbar::Item
- Extended by:
- Forwardable
- Defined in:
- lib/rollbar/item.rb,
lib/rollbar/item/frame.rb,
lib/rollbar/item/backtrace.rb
Overview
This class represents the payload to be sent to the API. It contains the logic to build the payload, trucante it and dump the JSON.
Defined Under Namespace
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#extra ⇒ Object
readonly
Returns the value of attribute extra.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#notifier ⇒ Object
readonly
Returns the value of attribute notifier.
- #payload ⇒ Object
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #build_data ⇒ Object
- #dump ⇒ Object
- #handle_too_large_payload(stringified_payload, final_payload) ⇒ Object
- #ignored? ⇒ Boolean
-
#initialize(options) ⇒ Item
constructor
A new instance of Item.
Constructor Details
#initialize(options) ⇒ Item
Returns a new instance of Item.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rollbar/item.rb', line 47 def initialize() @level = [:level] @message = [:message] @exception = [:exception] @extra = [:extra] @configuration = [:configuration] @logger = [:logger] @scope = [:scope] @payload = nil @notifier = [:notifier] @context = [:context] end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
30 31 32 |
# File 'lib/rollbar/item.rb', line 30 def configuration @configuration end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
35 36 37 |
# File 'lib/rollbar/item.rb', line 35 def context @context end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
27 28 29 |
# File 'lib/rollbar/item.rb', line 27 def exception @exception end |
#extra ⇒ Object (readonly)
Returns the value of attribute extra.
28 29 30 |
# File 'lib/rollbar/item.rb', line 28 def extra @extra end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
25 26 27 |
# File 'lib/rollbar/item.rb', line 25 def level @level end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
32 33 34 |
# File 'lib/rollbar/item.rb', line 32 def logger @logger end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
26 27 28 |
# File 'lib/rollbar/item.rb', line 26 def @message end |
#notifier ⇒ Object (readonly)
Returns the value of attribute notifier.
33 34 35 |
# File 'lib/rollbar/item.rb', line 33 def notifier @notifier end |
#payload ⇒ Object
60 61 62 |
# File 'lib/rollbar/item.rb', line 60 def payload @payload ||= build end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
31 32 33 |
# File 'lib/rollbar/item.rb', line 31 def scope @scope end |
Class Method Details
.build_with(payload, options = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/rollbar/item.rb', line 40 def build_with(payload, = {}) new().tap do |item| item.payload = payload end end |
Instance Method Details
#build ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rollbar/item.rb', line 64 def build data = build_data self.payload = { 'access_token' => configuration.access_token, 'data' => data } enforce_valid_utf8 transform payload end |
#build_data ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rollbar/item.rb', line 76 def build_data data = { :timestamp => Time.now.to_i, :environment => build_environment, :level => level, :language => 'ruby', :framework => configuration.framework, :server => server_data, :notifier => { :name => 'rollbar-gem', :version => VERSION }, :body => build_body } data[:project_package_paths] = configuration.project_gem_paths if configuration.project_gem_paths.any? data[:code_version] = configuration.code_version if configuration.code_version data[:uuid] = SecureRandom.uuid if defined?(SecureRandom) && SecureRandom.respond_to?(:uuid) Util.deep_merge(data, configuration.) Util.deep_merge(data, scope) # Our API doesn't allow null context values, so just delete # the key if value is nil. data.delete(:context) unless data[:context] data end |
#dump ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rollbar/item.rb', line 104 def dump # Ensure all keys are strings since we can receive the payload inline or # from an async handler job, which can be serialized. stringified_payload = Util::Hash.deep_stringify_keys(payload) result = Truncation.truncate(stringified_payload) return result unless Truncation.truncate?(result) handle_too_large_payload(stringified_payload, result) nil end |
#handle_too_large_payload(stringified_payload, final_payload) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/rollbar/item.rb', line 117 def handle_too_large_payload(stringified_payload, final_payload) original_size = Rollbar::JSON.dump(stringified_payload).bytesize final_size = final_payload.bytesize uuid = stringified_payload['data']['uuid'] host = stringified_payload['data'].fetch('server', {})['host'] notifier.send_failsafe("Could not send payload due to it being too large after truncating attempts. Original size: #{original_size} Final size: #{final_size}", nil, uuid, host) logger.error("[Rollbar] Payload too large to be sent for UUID #{uuid}: #{Rollbar::JSON.dump(payload)}") end |
#ignored? ⇒ Boolean
127 128 129 130 131 132 133 134 |
# File 'lib/rollbar/item.rb', line 127 def ignored? data = payload['data'] return unless data[:person] person_id = data[:person][configuration.person_id_method.to_sym] configuration.ignored_person_ids.include?(person_id) end |