exception_notification-td 0.0.1.pre → 0.0.1.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/exception_notification/td/version.rb +1 -1
- data/lib/exception_notifier/td_notifier.rb +41 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 592a064dbe40de85210df6e3c7c7312c73339be5
|
4
|
+
data.tar.gz: 2198d8c11f95c1d1585ac547ccfe97f0514d150f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3585e51101db121217774782867a7b9ad4709e3237a40a900effb0189843975c8e0ed66d49625f1ad5f96c337620783f18cc74990fa6cb415115aca421b1033c
|
7
|
+
data.tar.gz: 81934771ad7de9632f0da2e61c4c38039eed11f9f6f0982d78885ee86ad5577819f93abc60bc21463ba156f5f037bcdade8c328e7d61a2ee0b147c4db6eb27cf
|
@@ -4,28 +4,62 @@ require "td-logger"
|
|
4
4
|
|
5
5
|
module ExceptionNotifier
|
6
6
|
class TdNotifier
|
7
|
+
BACKTRACE_LIMIT_DEFAULT = 10
|
8
|
+
|
7
9
|
def initialize(options)
|
8
|
-
@database = options.delete(:database)
|
9
10
|
@table_name = options.delete(:table_name)
|
10
|
-
raise "Please set
|
11
|
+
raise "Please set table_name. options: #{options.inspect}" unless @table_name
|
12
|
+
|
13
|
+
@backtrace_limit = options.delete(:backtrace_limit) || BACKTRACE_LIMIT_DEFAULT
|
14
|
+
@custom_param_proc = options.delete(:custom_param_proc)
|
11
15
|
|
12
|
-
TreasureData::Logger
|
16
|
+
unless defined? TreasureData::Logger::Agent::Rails
|
17
|
+
@database = options.delete(:database)
|
18
|
+
raise "Please set database. options: #{options.inspect}" unless @database
|
19
|
+
TreasureData::Logger.open(@database, options)
|
20
|
+
end
|
13
21
|
end
|
14
|
-
attr_accessor :td
|
15
22
|
|
16
23
|
def call(exception, options = {})
|
17
24
|
TD.event.post(@table_name, exception_to_td_data(exception, options))
|
18
25
|
end
|
19
26
|
|
27
|
+
private
|
28
|
+
def request_klass
|
29
|
+
@request_klass ||= if defined?(ActionDispatch::Request)
|
30
|
+
ActionDispatch::Request
|
31
|
+
else
|
32
|
+
require 'rack/request'
|
33
|
+
Rack::Request
|
34
|
+
end
|
35
|
+
rescue LoadError, NameError
|
36
|
+
warn "ExceptionNotification::Td is designed to be used with Rack-based apps. Skip some of features."
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
20
40
|
def exception_to_td_data(exception, options)
|
41
|
+
backtrace = exception.backtrace ? exception.backtrace[0, @backtrace_limit] : []
|
21
42
|
params = {
|
22
|
-
class: exception.class,
|
43
|
+
class: exception.class.to_s,
|
23
44
|
message: exception.message,
|
24
|
-
backtrace:
|
45
|
+
backtrace: backtrace,
|
25
46
|
hostname: (Socket.gethostname rescue nil),
|
26
47
|
environment: Rails.env,
|
27
48
|
}
|
28
|
-
|
49
|
+
if request_klass && options[:env]
|
50
|
+
request = request_klass.new(options[:env])
|
51
|
+
params.merge!(
|
52
|
+
method: request.request_method,
|
53
|
+
request_url: request.url,
|
54
|
+
cookies: request.cookies,
|
55
|
+
referer: request.referer,
|
56
|
+
)
|
57
|
+
params[:post_body] = request.body unless request.get?
|
58
|
+
|
59
|
+
end
|
60
|
+
if @custom_param_proc
|
61
|
+
@custom_param_proc.call(params, exception, request)
|
62
|
+
end
|
29
63
|
params
|
30
64
|
end
|
31
65
|
end
|