Class: Bugsnag::Report
- Inherits:
-
Object
- Object
- Bugsnag::Report
- Includes:
- Utility::FeatureDataStore
- Defined in:
- lib/bugsnag/report.rb
Overview
rubocop:todo Metrics/ClassLength
Constant Summary collapse
- NOTIFIER_NAME =
"Ruby Bugsnag Notifier"
- NOTIFIER_VERSION =
Bugsnag::VERSION
- NOTIFIER_URL =
"https://www.bugsnag.com"
- UNHANDLED_EXCEPTION =
"unhandledException"
- UNHANDLED_EXCEPTION_MIDDLEWARE =
"unhandledExceptionMiddleware"
- ERROR_CLASS =
"errorClass"
- HANDLED_EXCEPTION =
"handledException"
- USER_SPECIFIED_SEVERITY =
"userSpecifiedSeverity"
- USER_CALLBACK_SET_SEVERITY =
"userCallbackSetSeverity"
- MAX_EXCEPTIONS_TO_UNWRAP =
5
- CURRENT_PAYLOAD_VERSION =
"4.0"
Instance Attribute Summary collapse
-
#api_key ⇒ String?
Your Integration API Key.
-
#app_type ⇒ String?
The type of application executing the current code.
-
#app_version ⇒ String?
The current version of your application.
-
#breadcrumbs ⇒ Array<Breadcrumb>
The list of breadcrumbs attached to this report.
-
#context ⇒ String?
Additional context for this report.
-
#delivery_method ⇒ Symbol
The delivery method that will be used for this report.
-
#errors ⇒ Array<Error>
readonly
A list of errors in this report.
-
#exceptions ⇒ Array<Hash>
deprecated
Deprecated.
Use #errors instead
-
#grouping_hash ⇒ String
All errors with the same grouping hash will be grouped in the Bugsnag app.
- #hostname ⇒ String
-
#meta_data ⇒ Hash
deprecated
Deprecated.
Use #metadata instead
-
#metadata ⇒ Hash
A Hash containing arbitrary metadata.
-
#original_error ⇒ Exception
readonly
The Exception instance this report was created for.
-
#raw_exceptions ⇒ Array<Exception>
deprecated
Deprecated.
Use #original_error instead
-
#release_stage ⇒ String?
The current stage of the release process, e.g.
-
#session ⇒ Hash
The session that active when this report was generated.
-
#severity ⇒ String
The severity of this report, e.g.
-
#unhandled ⇒ Boolean
Whether this report is for a handled or unhandled error.
-
#user ⇒ Hash
The current user when this report was generated.
Instance Method Summary collapse
-
#add_feature_flag(name, variant = nil) ⇒ void
included
from Utility::FeatureDataStore
Add a feature flag with the given name & variant.
-
#add_feature_flags(feature_flags) ⇒ void
included
from Utility::FeatureDataStore
Merge the given array of FeatureFlag instances into the stored feature flags.
-
#add_metadata(section, key_or_data, *args) ⇒ void
Add values to metadata.
-
#add_tab(name, value) ⇒ void
deprecated
Deprecated.
Use #add_metadata instead
-
#as_json ⇒ Hash
Builds and returns the exception payload for this notification.
-
#clear_feature_flag(name) ⇒ void
included
from Utility::FeatureDataStore
Remove the stored flag with the given name.
-
#clear_feature_flags ⇒ void
included
from Utility::FeatureDataStore
Remove all the stored flags.
-
#clear_metadata(section, *args) ⇒ void
Clear values from metadata.
-
#feature_flags ⇒ Array<Bugsnag::FeatureFlag>
Get the array of stored feature flags.
-
#headers ⇒ Hash{String => String}
Returns the headers required for the notification.
-
#ignore! ⇒ void
Tells the client this report should not be sent.
-
#ignore? ⇒ Boolean
Whether this report should be ignored and not sent.
-
#initialize(exception, passed_configuration, auto_notify = false) ⇒ Report
constructor
Initializes a new report from an exception.
-
#remove_tab(name) ⇒ void
deprecated
Deprecated.
Use #clear_metadata instead
-
#request ⇒ Hash?
Data from the current HTTP request.
-
#request_data ⇒ Hash
Data set on the configuration to be attached to every error notification.
-
#set_user(id = nil, email = nil, name = nil) ⇒ void
Set information about the current user.
-
#summary ⇒ Hash
Generates a summary to be attached as a breadcrumb.
Constructor Details
#initialize(exception, passed_configuration, auto_notify = false) ⇒ Report
Initializes a new report from an exception.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/bugsnag/report.rb', line 117 def initialize(exception, passed_configuration, auto_notify=false) # store the creation time for use as device.time @created_at = Time.now.utc.iso8601(3) @should_ignore = false @unhandled = auto_notify @initial_unhandled = @unhandled self.configuration = passed_configuration @original_error = exception self.raw_exceptions = generate_raw_exceptions(exception) self.exceptions = generate_exception_list @errors = generate_error_list self.api_key = configuration.api_key self.app_type = configuration.app_type self.app_version = configuration.app_version self. = [] self.context = configuration.context if configuration.context_set? self.delivery_method = configuration.delivery_method self.hostname = configuration.hostname self.runtime_versions = configuration.runtime_versions.dup self. = Utility::Duplicator.duplicate(configuration.) self.release_stage = configuration.release_stage self.severity = auto_notify ? "error" : "warning" self.severity_reason = auto_notify ? {:type => UNHANDLED_EXCEPTION} : {:type => HANDLED_EXCEPTION} self.user = {} @metadata_delegate = Utility::MetadataDelegate.new @feature_flag_delegate = Bugsnag.feature_flag_delegate.dup end |
Instance Attribute Details
#api_key ⇒ String?
Your Integration API Key
32 33 34 |
# File 'lib/bugsnag/report.rb', line 32 def api_key @api_key end |
#app_type ⇒ String?
The type of application executing the current code
37 38 39 |
# File 'lib/bugsnag/report.rb', line 37 def app_type @app_type end |
#app_version ⇒ String?
The current version of your application
41 42 43 |
# File 'lib/bugsnag/report.rb', line 41 def app_version @app_version end |
#breadcrumbs ⇒ Array<Breadcrumb>
The list of breadcrumbs attached to this report
45 46 47 |
# File 'lib/bugsnag/report.rb', line 45 def @breadcrumbs end |
#context ⇒ String?
Additional context for this report
154 155 156 157 158 |
# File 'lib/bugsnag/report.rb', line 154 def context return @context if defined?(@context) @automatic_context end |
#delivery_method ⇒ Symbol
The delivery method that will be used for this report
54 55 56 |
# File 'lib/bugsnag/report.rb', line 54 def delivery_method @delivery_method end |
#errors ⇒ Array<Error> (readonly)
A list of errors in this report
109 110 111 |
# File 'lib/bugsnag/report.rb', line 109 def errors @errors end |
#exceptions ⇒ Array<Hash>
Use #errors instead
The list of exceptions in this report
59 60 61 |
# File 'lib/bugsnag/report.rb', line 59 def exceptions @exceptions end |
#grouping_hash ⇒ String
All errors with the same grouping hash will be grouped in the Bugsnag app
72 73 74 |
# File 'lib/bugsnag/report.rb', line 72 def grouping_hash @grouping_hash end |
#hostname ⇒ String
63 64 65 |
# File 'lib/bugsnag/report.rb', line 63 def hostname @hostname end |
#meta_data ⇒ Hash
Use #metadata instead
Arbitrary metadata attached to this report
77 78 79 |
# File 'lib/bugsnag/report.rb', line 77 def @meta_data end |
#metadata ⇒ Hash
A Hash containing arbitrary metadata
309 310 311 |
# File 'lib/bugsnag/report.rb', line 309 def @meta_data end |
#original_error ⇒ Exception (readonly)
The Exception instance this report was created for
113 114 115 |
# File 'lib/bugsnag/report.rb', line 113 def original_error @original_error end |
#raw_exceptions ⇒ Array<Exception>
Use #original_error instead
The raw Exception instances for this report
83 84 85 |
# File 'lib/bugsnag/report.rb', line 83 def raw_exceptions @raw_exceptions end |
#release_stage ⇒ String?
The current stage of the release process, e.g. ‘development’, production’
88 89 90 |
# File 'lib/bugsnag/report.rb', line 88 def release_stage @release_stage end |
#session ⇒ Hash
The session that active when this report was generated
93 94 95 |
# File 'lib/bugsnag/report.rb', line 93 def session @session end |
#severity ⇒ String
The severity of this report, e.g. ‘error’, ‘warning’
97 98 99 |
# File 'lib/bugsnag/report.rb', line 97 def severity @severity end |
#unhandled ⇒ Boolean
Whether this report is for a handled or unhandled error
27 28 29 |
# File 'lib/bugsnag/report.rb', line 27 def unhandled @unhandled end |
#user ⇒ Hash
The current user when this report was generated
105 106 107 |
# File 'lib/bugsnag/report.rb', line 105 def user @user end |
Instance Method Details
#add_feature_flag(name, variant = nil) ⇒ void Originally defined in module Utility::FeatureDataStore
This method returns an undefined value.
Add a feature flag with the given name & variant
#add_feature_flags(feature_flags) ⇒ void Originally defined in module Utility::FeatureDataStore
This method returns an undefined value.
Merge the given array of FeatureFlag instances into the stored feature flags
New flags will be appended to the array. Flags with the same name will be overwritten, but their position in the array will not change
#add_metadata(section, data) ⇒ void #add_metadata(section, key, value) ⇒ void
This method returns an undefined value.
Add values to metadata
343 344 345 |
# File 'lib/bugsnag/report.rb', line 343 def (section, key_or_data, *args) @metadata_delegate.(@meta_data, section, key_or_data, *args) end |
#add_tab(name, value) ⇒ void
Use #add_metadata instead
This method returns an undefined value.
Add a new metadata tab to this notification.
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/bugsnag/report.rb', line 179 def add_tab(name, value) return if name.nil? if value.is_a? Hash [name] ||= {} [name].merge! value else ["custom"] = {} unless ["custom"] ["custom"][name.to_s] = value end end |
#as_json ⇒ Hash
Builds and returns the exception payload for this notification.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/bugsnag/report.rb', line 209 def as_json # Build the payload's exception event payload_event = { app: { version: app_version, releaseStage: release_stage, type: app_type }, breadcrumbs: .map(&:to_h), context: context, device: { hostname: hostname, runtimeVersions: runtime_versions, time: @created_at }, exceptions: exceptions, featureFlags: @feature_flag_delegate.as_json, groupingHash: grouping_hash, metaData: , session: session, severity: severity, severityReason: severity_reason, unhandled: @unhandled, user: user } payload_event.reject! {|k, v| v.nil? } # return the payload hash { :apiKey => api_key, :notifier => { :name => NOTIFIER_NAME, :version => NOTIFIER_VERSION, :url => NOTIFIER_URL }, :payloadVersion => CURRENT_PAYLOAD_VERSION, :events => [payload_event] } end |
#clear_feature_flag(name) ⇒ void Originally defined in module Utility::FeatureDataStore
This method returns an undefined value.
Remove the stored flag with the given name
#clear_feature_flags ⇒ void Originally defined in module Utility::FeatureDataStore
This method returns an undefined value.
Remove all the stored flags
#clear_metadata(section) ⇒ void #clear_metadata(section, key) ⇒ void
This method returns an undefined value.
Clear values from metadata
360 361 362 |
# File 'lib/bugsnag/report.rb', line 360 def (section, *args) @metadata_delegate.(@meta_data, section, *args) end |
#feature_flags ⇒ Array<Bugsnag::FeatureFlag>
Get the array of stored feature flags
367 368 369 |
# File 'lib/bugsnag/report.rb', line 367 def feature_flags @feature_flag_delegate.to_a end |
#headers ⇒ Hash{String => String}
Returns the headers required for the notification.
254 255 256 257 258 259 260 |
# File 'lib/bugsnag/report.rb', line 254 def headers { "Bugsnag-Api-Key" => api_key, "Bugsnag-Payload-Version" => CURRENT_PAYLOAD_VERSION, "Bugsnag-Sent-At" => Time.now.utc.iso8601(3) } end |
#ignore! ⇒ void
This method returns an undefined value.
Tells the client this report should not be sent.
282 283 284 |
# File 'lib/bugsnag/report.rb', line 282 def ignore! @should_ignore = true end |
#ignore? ⇒ Boolean
Whether this report should be ignored and not sent.
266 267 268 |
# File 'lib/bugsnag/report.rb', line 266 def ignore? @should_ignore end |
#remove_tab(name) ⇒ void
Use #clear_metadata instead
This method returns an undefined value.
Removes a metadata tab from this notification.
199 200 201 202 203 |
# File 'lib/bugsnag/report.rb', line 199 def remove_tab(name) return if name.nil? .delete(name) end |
#request ⇒ Hash?
Data from the current HTTP request. May be nil if no data has been recorded
323 324 325 |
# File 'lib/bugsnag/report.rb', line 323 def request @meta_data[:request] end |
#request_data ⇒ Hash
Data set on the configuration to be attached to every error notification.
274 275 276 |
# File 'lib/bugsnag/report.rb', line 274 def request_data configuration.request_data end |
#set_user(id = nil, email = nil, name = nil) ⇒ void
This method returns an undefined value.
Set information about the current user
Additional user fields can be added as metadata in a “user” section
Setting a field to ‘nil’ will remove it from the user data
382 383 384 385 386 387 |
# File 'lib/bugsnag/report.rb', line 382 def set_user(id = nil, email = nil, name = nil) new_user = { id: id, email: email, name: name } new_user.reject! { |key, value| value.nil? } @user = new_user end |
#summary ⇒ Hash
Generates a summary to be attached as a breadcrumb
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/bugsnag/report.rb', line 290 def summary # Guard against the exceptions array being removed/changed or emptied here if exceptions.respond_to?(:first) && exceptions.first { :error_class => exceptions.first[:errorClass], :message => exceptions.first[:message], :severity => severity } else { :error_class => "Unknown", :severity => severity } end end |