Class: Bugsnag::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/bugsnag/report.rb

Constant Summary collapse

NOTIFIER_NAME =
"Ruby Bugsnag Notifier"
NOTIFIER_VERSION =
Bugsnag::VERSION
NOTIFIER_URL =
"http://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 =
"2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, passed_configuration, auto_notify = false) ⇒ Report

Returns a new instance of Report.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bugsnag/report.rb', line 38

def initialize(exception, passed_configuration, auto_notify=false)
  @should_ignore = false
  @unhandled = auto_notify

  self.configuration = passed_configuration

  self.raw_exceptions = generate_raw_exceptions(exception)
  self.exceptions = generate_exception_list

  self.api_key = configuration.api_key
  self.app_type = configuration.app_type
  self.app_version = configuration.app_version
  self.delivery_method = configuration.delivery_method
  self.hostname = configuration.hostname
  self. = {}
  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 = {}
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



22
23
24
# File 'lib/bugsnag/report.rb', line 22

def api_key
  @api_key
end

#app_typeObject

Returns the value of attribute app_type.



23
24
25
# File 'lib/bugsnag/report.rb', line 23

def app_type
  @app_type
end

#app_versionObject

Returns the value of attribute app_version.



24
25
26
# File 'lib/bugsnag/report.rb', line 24

def app_version
  @app_version
end

#configurationObject

Returns the value of attribute configuration.



25
26
27
# File 'lib/bugsnag/report.rb', line 25

def configuration
  @configuration
end

#contextObject

Returns the value of attribute context.



26
27
28
# File 'lib/bugsnag/report.rb', line 26

def context
  @context
end

#delivery_methodObject

Returns the value of attribute delivery_method.



27
28
29
# File 'lib/bugsnag/report.rb', line 27

def delivery_method
  @delivery_method
end

#exceptionsObject

Returns the value of attribute exceptions.



28
29
30
# File 'lib/bugsnag/report.rb', line 28

def exceptions
  @exceptions
end

#grouping_hashObject

Returns the value of attribute grouping_hash.



30
31
32
# File 'lib/bugsnag/report.rb', line 30

def grouping_hash
  @grouping_hash
end

#hostnameObject

Returns the value of attribute hostname.



29
30
31
# File 'lib/bugsnag/report.rb', line 29

def hostname
  @hostname
end

#meta_dataObject

Returns the value of attribute meta_data.



31
32
33
# File 'lib/bugsnag/report.rb', line 31

def 
  @meta_data
end

#raw_exceptionsObject

Returns the value of attribute raw_exceptions.



32
33
34
# File 'lib/bugsnag/report.rb', line 32

def raw_exceptions
  @raw_exceptions
end

#release_stageObject

Returns the value of attribute release_stage.



33
34
35
# File 'lib/bugsnag/report.rb', line 33

def release_stage
  @release_stage
end

#severityObject

Returns the value of attribute severity.



34
35
36
# File 'lib/bugsnag/report.rb', line 34

def severity
  @severity
end

#severity_reasonObject

Returns the value of attribute severity_reason.



35
36
37
# File 'lib/bugsnag/report.rb', line 35

def severity_reason
  @severity_reason
end

#userObject

Returns the value of attribute user.



36
37
38
# File 'lib/bugsnag/report.rb', line 36

def user
  @user
end

Instance Method Details

#add_tab(name, value) ⇒ Object

Add a new tab to this notification



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

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_jsonObject

Build an exception payload



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/bugsnag/report.rb', line 81

def as_json
  # Build the payload's exception event
  payload_event = {
    app: {
      version: app_version,
      releaseStage: release_stage,
      type: app_type
    },
    context: context,
    device: {
      hostname: hostname
    },
    exceptions: exceptions,
    groupingHash: grouping_hash,
    payloadVersion: CURRENT_PAYLOAD_VERSION,
    severity: severity,
    severityReason: severity_reason,
    unhandled: @unhandled,
    user: user
  }

  # cleanup character encodings
  payload_event = Bugsnag::Cleaner.clean_object_encoding(payload_event)

  # filter out sensitive values in (and cleanup encodings) metaData
  payload_event[:metaData] = Bugsnag::Cleaner.new(configuration.).clean_object()
  payload_event.reject! {|k,v| v.nil? }

  # return the payload hash
  {
    :apiKey => api_key,
    :notifier => {
      :name => NOTIFIER_NAME,
      :version => NOTIFIER_VERSION,
      :url => NOTIFIER_URL
    },
    :events => [payload_event]
  }
end

#ignore!Object



129
130
131
# File 'lib/bugsnag/report.rb', line 129

def ignore!
  @should_ignore = true
end

#ignore?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/bugsnag/report.rb', line 121

def ignore?
  @should_ignore
end

#remove_tab(name) ⇒ Object

Remove a tab from this notification



74
75
76
77
78
# File 'lib/bugsnag/report.rb', line 74

def remove_tab(name)
  return if name.nil?

  .delete(name)
end

#request_dataObject



125
126
127
# File 'lib/bugsnag/report.rb', line 125

def request_data
  configuration.request_data
end