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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c29372e0364d9254aedfe11dd57cf4ea5b2539a2
4
- data.tar.gz: 403dab98cd39902459865cd1e084cdce6fb71f27
3
+ metadata.gz: 592a064dbe40de85210df6e3c7c7312c73339be5
4
+ data.tar.gz: 2198d8c11f95c1d1585ac547ccfe97f0514d150f
5
5
  SHA512:
6
- metadata.gz: 169a4a6927ddce4363086c09618345c441ef3870b14cc5b2a702bfc3e7c952c51abb8a328e925658201bc008e691698fa2df728af92f65f2d560ddbbe81d4f52
7
- data.tar.gz: 46a6ca7e67186e9ee2afc61a0e9dec018ea0064569fdbe2d78d39d3dc5ca93d76ccb6e03a9523ca495d701cd1eaea360a44dc512210df7536be0b7c6c8784025
6
+ metadata.gz: 3585e51101db121217774782867a7b9ad4709e3237a40a900effb0189843975c8e0ed66d49625f1ad5f96c337620783f18cc74990fa6cb415115aca421b1033c
7
+ data.tar.gz: 81934771ad7de9632f0da2e61c4c38039eed11f9f6f0982d78885ee86ad5577819f93abc60bc21463ba156f5f037bcdade8c328e7d61a2ee0b147c4db6eb27cf
@@ -1,5 +1,5 @@
1
1
  module ExceptionNotification
2
2
  module Td
3
- VERSION = "0.0.1.pre"
3
+ VERSION = "0.0.1.pre2"
4
4
  end
5
5
  end
@@ -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 database and table_name. options: #{options.inspect}" if !@database or !@table_name
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.open(@database, options)
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: exception.backtrace,
45
+ backtrace: backtrace,
25
46
  hostname: (Socket.gethostname rescue nil),
26
47
  environment: Rails.env,
27
48
  }
28
- params.merge!(request_env: options[:env]) if options[:env]
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_notification-td
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 0.0.1.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio KONDO