Commit cb1212fa8c9bcf1e0c98e21d29fdfa225d2b3a41

Authored by Nathan Broadbent
1 parent 8f0aefe2
Exists in master and in 1 other branch production

Added user_info data to notices, to retrieve and display info about the currently logged in user.

This allows us to know who took the action that caused
the error, so we can follow up via email or phone
if we need further information about the context.
app/models/error_report.rb
@@ -2,7 +2,7 @@ require 'digest/md5' @@ -2,7 +2,7 @@ require 'digest/md5'
2 require 'hoptoad_notifier' 2 require 'hoptoad_notifier'
3 3
4 class ErrorReport 4 class ErrorReport
5 - attr_reader :klass, :message, :backtrace, :request, :server_environment, :api_key, :notifier 5 + attr_reader :klass, :message, :backtrace, :request, :server_environment, :api_key, :notifier, :user_info
6 6
7 def initialize(xml_or_attributes) 7 def initialize(xml_or_attributes)
8 @attributes = (xml_or_attributes.is_a?(String) ? Hoptoad.parse_xml!(xml_or_attributes) : xml_or_attributes).with_indifferent_access 8 @attributes = (xml_or_attributes.is_a?(String) ? Hoptoad.parse_xml!(xml_or_attributes) : xml_or_attributes).with_indifferent_access
@@ -35,7 +35,8 @@ class ErrorReport @@ -35,7 +35,8 @@ class ErrorReport
35 :backtrace => backtrace, 35 :backtrace => backtrace,
36 :request => request, 36 :request => request,
37 :server_environment => server_environment, 37 :server_environment => server_environment,
38 - :notifier => notifier) 38 + :notifier => notifier,
  39 + :user_info => user_info)
39 40
40 err = app.find_or_create_err!( 41 err = app.find_or_create_err!(
41 :klass => klass, 42 :klass => klass,
app/models/notice.rb
@@ -10,6 +10,7 @@ class Notice @@ -10,6 +10,7 @@ class Notice
10 field :server_environment, :type => Hash 10 field :server_environment, :type => Hash
11 field :request, :type => Hash 11 field :request, :type => Hash
12 field :notifier, :type => Hash 12 field :notifier, :type => Hash
  13 + field :user_info, :type => Hash
13 field :klass 14 field :klass
14 15
15 belongs_to :err 16 belongs_to :err
app/views/errs/show.html.haml
@@ -50,6 +50,7 @@ @@ -50,6 +50,7 @@
50 %ul 50 %ul
51 %li= link_to 'Summary', '#summary', :rel => 'summary', :class => 'button' 51 %li= link_to 'Summary', '#summary', :rel => 'summary', :class => 'button'
52 %li= link_to 'Backtrace', '#backtrace', :rel => 'backtrace', :class => 'button' 52 %li= link_to 'Backtrace', '#backtrace', :rel => 'backtrace', :class => 'button'
  53 + %li= link_to 'Application User', '#user_info', :rel => 'user_info', :class => 'button'
53 %li= link_to 'Environment', '#environment', :rel => 'environment', :class => 'button' 54 %li= link_to 'Environment', '#environment', :rel => 'environment', :class => 'button'
54 %li= link_to 'Parameters', '#params', :rel => 'params', :class => 'button' 55 %li= link_to 'Parameters', '#params', :rel => 'params', :class => 'button'
55 %li= link_to 'Session', '#session', :rel => 'session', :class => 'button' 56 %li= link_to 'Session', '#session', :rel => 'session', :class => 'button'
@@ -63,6 +64,11 @@ @@ -63,6 +64,11 @@
63 %h3 Backtrace 64 %h3 Backtrace
64 = render 'notices/backtrace', :lines => @notice.backtrace 65 = render 'notices/backtrace', :lines => @notice.backtrace
65 66
  67 + - if @notice.user_info.present?
  68 + #user_info
  69 + %h3 User
  70 + = render 'notices/user_info', :user => @notice.user_info
  71 +
66 #environment 72 #environment
67 %h3 Environment 73 %h3 Environment
68 = render 'notices/environment', :notice => @notice 74 = render 'notices/environment', :notice => @notice
@@ -74,4 +80,3 @@ @@ -74,4 +80,3 @@
74 #session 80 #session
75 %h3 Session 81 %h3 Session
76 = render 'notices/session', :notice => @notice 82 = render 'notices/session', :notice => @notice
77 -  
app/views/notices/_user_info.html.haml 0 → 100644
@@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
  1 +.window
  2 + %table.user_info
  3 + - user.each do |user_key, user_value|
  4 + %tr
  5 + %th= user_key
  6 + %td= auto_link(user_value).html_safe
lib/hoptoad/v2.rb
@@ -58,7 +58,8 @@ module Hoptoad @@ -58,7 +58,8 @@ module Hoptoad
58 :server_environment => notice['server-environment'], 58 :server_environment => notice['server-environment'],
59 59
60 :api_key => notice['api-key'], 60 :api_key => notice['api-key'],
61 - :notifier => notice['notifier'] 61 + :notifier => notice['notifier'],
  62 + :user_info => notice['user-info'] || {}
62 } 63 }
63 end 64 end
64 end 65 end
lib/tasks/errbit/demo.rake
@@ -52,7 +52,13 @@ namespace :errbit do @@ -52,7 +52,13 @@ namespace :errbit do
52 'action' => 'error' 52 'action' => 'error'
53 }, 53 },
54 :server_environment => {'environment-name' => Rails.env.to_s}, 54 :server_environment => {'environment-name' => Rails.env.to_s},
55 - :notifier => {:name => "seeds.rb"} 55 + :notifier => {:name => "seeds.rb"},
  56 + :app_user => {
  57 + :id => "1234",
  58 + :username => "jsmith",
  59 + :name => "John Smith",
  60 + :url => "http://www.example.com/users/jsmith"
  61 + }
56 }) 62 })
57 63
58 app.report_error!(error_report) 64 app.report_error!(error_report)