redmine_airbrake_backend 0.2.4 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8491f61028050f6bddc8ab2a4f1b058ac0345a6
4
- data.tar.gz: 3be0314d2231897aeb5822f2ce244852ae19d98e
3
+ metadata.gz: fede908ea4433fdce923fbdd62b4bd27cd17e3bb
4
+ data.tar.gz: 2e86039dabbd831acd7e98ef00c1fe4a2257c784
5
5
  SHA512:
6
- metadata.gz: 6b69fa46ffcc8ed4eb860d4cff31542d707797c0dbd253709799ab5ea15dcfa2784656099feb17997058e4459bbcc549ca67ea4999f560c7e514cd70e52187b9
7
- data.tar.gz: e2f410b9e81b87c6f8885684439e863647952dfa0ee158513c412c61d7bbb57ef3e9ee99b69699a4961bedf374648e09a2222917aa0e037c48544c1ad16035e7
6
+ metadata.gz: 0bf50e59f151679b90705f180d054b3ae9eb1d889f4126c42ee1363422da36f6359e5485a4c06a610c1d805bb3bac9c3f57968245fa4072229da7dec6a837760
7
+ data.tar.gz: afbdb05de2139170591a40c8a9b4cfa461be1f80c8482456768ba6cbf99d61988d07c61cffea130a2701fd50a3d2dcbb8f4484ab851484fc5c3c845d3b2cb997
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redmine_airbrake_backend (0.2.4)
4
+ redmine_airbrake_backend (0.3.1)
5
5
  hpricot
6
6
  htmlentities
7
7
  rails
@@ -99,18 +99,20 @@ class AirbrakeController < ::ApplicationController
99
99
  end
100
100
 
101
101
  def subject
102
- if @notice.error[:message].starts_with?("#{@notice.error[:class]}:")
103
- "[#{notice_hash[0..7]}] #{@notice.error[:message]}"[0..254]
102
+ s = ''
103
+ if @notice.error[:class].blank? || @notice.error[:message].starts_with?("#{@notice.error[:class]}:")
104
+ s = "[#{notice_hash[0..7]}] #{@notice.error[:message]}"
104
105
  else
105
- "[#{notice_hash[0..7]}] #{@notice.error[:class]} #{@notice.error[:message]}"[0..254]
106
+ s = "[#{notice_hash[0..7]}] #{@notice.error[:class]} #{@notice.error[:message]}"
106
107
  end
108
+ s[0..254].strip
107
109
  end
108
110
 
109
111
  def notice_hash
110
112
  h = []
111
113
  h << @notice.error[:class]
112
114
  h << @notice.error[:message]
113
- h += normalized_backtrace if @notice.error[:backtrace].present?
115
+ h += normalized_backtrace
114
116
 
115
117
  Digest::MD5.hexdigest(h.compact.join("\n"))
116
118
  end
@@ -1,10 +1,10 @@
1
1
  class AirbrakeProjectSettingsController < ::ApplicationController
2
2
  before_filter :find_project
3
+ before_filter :find_airbrake_setting
3
4
 
4
5
  menu_item :settings
5
6
 
6
7
  def update
7
- @airbrake_project_setting = @project.airbrake_settings || AirbrakeProjectSetting.new(project: @project)
8
8
  @airbrake_project_setting.safe_attributes = params[:airbrake_project_setting]
9
9
 
10
10
  @airbrake_project_setting.save
@@ -19,4 +19,8 @@ class AirbrakeProjectSettingsController < ::ApplicationController
19
19
  @project = Project.find(params[:id])
20
20
  end
21
21
 
22
+ def find_airbrake_setting
23
+ @airbrake_project_setting = @project.airbrake_settings || AirbrakeProjectSetting.new(project: @project)
24
+ end
25
+
22
26
  end
@@ -3,13 +3,23 @@ module AirbrakeHelper
3
3
  def format_table(data)
4
4
  lines = []
5
5
  data.each do |key, value|
6
+ next unless value.is_a?(String)
6
7
  lines << "|@#{key}@|#{value.strip.blank? ? value : "@#{value}@"}|"
7
8
  end
8
9
  lines.join("\n")
9
10
  end
10
11
 
12
+ def format_log(data)
13
+ lines = []
14
+ data.each do |log|
15
+ next unless log.is_a?(Hash)
16
+ lines << "[#{log[:time].strftime('%F %T')}] #{log[:line]}"
17
+ end
18
+ lines.join("\n")
19
+ end
20
+
11
21
  def format_list_item(name, value)
12
- return '' if value.to_s.strip.blank?
22
+ return '' if value.blank?
13
23
  "* *#{name}:* #{value}"
14
24
  end
15
25
 
@@ -14,27 +14,37 @@ h2. Request:
14
14
  <%=format_list_item('Action', @notice.request[:action]) %>
15
15
 
16
16
  <% if @notice.request[:params].present? %>
17
- h2. Parameters:
17
+ h2. Parameters:
18
18
 
19
19
  <%=format_table(@notice.request[:params]) %>
20
20
  <% end %>
21
21
 
22
22
  <% if @notice.request[:cgi_data].present? %>
23
- h2. Headers:
23
+ h2. Headers:
24
24
 
25
25
  <%=format_table(@notice.request[:cgi_data]) %>
26
26
  <% end %>
27
27
 
28
+ <% log = @notice.request[:session].delete(:log) if @notice.request[:session].present? %>
28
29
  <% if @notice.request[:session].present? %>
29
- h2. Session:
30
+ h2. Session:
30
31
 
31
32
  <%=format_table(@notice.request[:session]) %>
32
33
  <% end %>
34
+
35
+ <% if log.present? %>
36
+ h2. Log:
37
+
38
+ <pre>
39
+ <%=format_log(log) %>
40
+ </pre>
41
+ <% end %>
33
42
  <% end %>
34
43
 
35
44
  <% if @notice.env.present? %>
36
45
  h2. Environment
37
46
 
47
+ <%=format_list_item('Name', @notice.env[:environment_name]) %>
38
48
  <%=format_list_item('Directory', @notice.env[:project_root]) %>
39
49
  <%=format_list_item('Hostname', @notice.env[:hostname]) %>
40
50
  <% end %>
@@ -34,10 +34,13 @@ module RedmineAirbrakeBackend
34
34
  raise NoticeInvalid if (notifier = convert_element(notice.at('notifier'))).blank?
35
35
 
36
36
  raise NoticeInvalid if (error = convert_element(notice.at('error'))).blank?
37
- raise NoticeInvalid if error[:class].blank? || error[:message].blank?
38
- error[:backtrace] = error[:backtrace][:line].is_a?(Array) ? error[:backtrace][:line] : [error[:backtrace][:line]] unless error[:backtrace].nil?
37
+ raise NoticeInvalid if error[:message].blank?
38
+
39
+ error[:backtrace] = format_backtrace(error[:backtrace])
39
40
 
40
41
  request = convert_element(notice.at('request'))
42
+ request[:session][:log] = format_session_log(request[:session][:log]) if request[:session].present?
43
+
41
44
  env = convert_element(notice.at('server-environment'))
42
45
 
43
46
  new(version, params, notifier, error: error, request: request, env: env)
@@ -81,5 +84,25 @@ module RedmineAirbrakeBackend
81
84
  key.to_s.gsub(/-/, '_')
82
85
  end
83
86
 
87
+ def self.ensure_hash_array(data)
88
+ d = (data.is_a?(Array) ? data : [data]).compact
89
+ d.reject!{|e| !e.is_a?(Hash)}
90
+ d.blank? ? nil : d
91
+ end
92
+
93
+ def self.format_backtrace(backtrace)
94
+ ensure_hash_array(backtrace)
95
+ end
96
+
97
+ def self.format_session_log(log)
98
+ log = JSON.parse(log) rescue nil
99
+ return nil unless log = ensure_hash_array(log)
100
+
101
+ log.map!{|l| l.symbolize_keys!; l[:time] = (Time.parse(l[:time]) rescue nil); l}
102
+ log.reject!{|l| l[:time].blank?}
103
+
104
+ log.blank? ? nil : log
105
+ end
106
+
84
107
  end
85
108
  end
@@ -1,3 +1,3 @@
1
1
  module RedmineAirbrakeBackend
2
- VERSION = '0.2.4'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_airbrake_backend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Schwab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-05 00:00:00.000000000 Z
11
+ date: 2013-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails