Class: Airbrake::Notice

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake_overrides/notice.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#user_attributesObject

User information

  • Provides information about the currently logged in user



7
8
9
# File 'lib/airbrake_overrides/notice.rb', line 7

def user_attributes
  @user_attributes
end

Instance Method Details

#initialize_with_user_attributes(args) ⇒ Object



9
10
11
12
# File 'lib/airbrake_overrides/notice.rb', line 9

def initialize_with_user_attributes(args)
  self.user_attributes = args[:user_attributes] || {}
  initialize_without_user_attributes(args)
end

#to_xmlObject

Converts the given notice to XML Need to override whole builder to add user-attributes at end.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/airbrake_overrides/notice.rb', line 17

def to_xml
  builder = Builder::XmlMarkup.new
  builder.instruct!
  xml = builder.notice(:version => Airbrake::API_VERSION) do |notice|
    notice.tag!("api-key", api_key)
    notice.notifier do |notifier|
      notifier.name(notifier_name)
      notifier.version(notifier_version)
      notifier.url(notifier_url)
    end
    notice.error do |error|
      error.tag!('class', error_class)
      error.message(error_message)
      error.backtrace do |backtrace|
        self.backtrace.lines.each do |line|
          backtrace.line(:number => line.number,
                         :file   => line.file,
                         :method => line.method)
        end
      end
    end
    if url ||
        controller ||
        action ||
        !parameters.blank? ||
        !cgi_data.blank? ||
        !session_data.blank?
      notice.request do |request|
        request.url(url)
        request.component(controller)
        request.action(action)
        unless parameters.nil? || parameters.empty?
          request.params do |params|
            xml_vars_for(params, parameters)
          end
        end
        unless session_data.nil? || session_data.empty?
          request.session do |session|
            xml_vars_for(session, session_data)
          end
        end
        unless cgi_data.nil? || cgi_data.empty?
          request.tag!("cgi-data") do |cgi_datum|
            xml_vars_for(cgi_datum, cgi_data)
          end
        end
      end
    end
    notice.tag!("server-environment") do |env|
      env.tag!("project-root", project_root)
      env.tag!("environment-name", environment_name)
      env.tag!("hostname", hostname)
    end

    if user_attributes.present?
      notice.tag!("user-attributes") do |user|
        xml_vars_for(user, user_attributes)
      end
    end
  end

  xml.to_s
end