exception_notification-squash_notifier 0.1.1 → 0.1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/exception-notification-squash-notifier.gemspec +1 -1
- data/lib/exception_notifier/squash_notifier/rails.rb +99 -0
- data/lib/exception_notifier/squash_notifier/version.rb +1 -1
- data/lib/exception_notifier/squash_notifier.rb +12 -24
- data/lib/exception_notifier/squash_ruby/rails.rb +26 -0
- data/lib/exception_notifier/squash_ruby.rb +7 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7ec2b5af8dd752ed7db38ab8986d6ff23840285
|
4
|
+
data.tar.gz: 22931676072bd8c10d45b1c334c597920ace15dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7235e19a31f9f636d671cf02a184b82e2092d1076619fd0dcbacfe8729860933dc2329b984db4e7b70cf635600d8f6bcf7659a35d0073dc908ebdf47ee971e5f
|
7
|
+
data.tar.gz: def3e87c18f5eab7ae12fb6d60a9f5753b6e221f6b2e4da6afa3fd8c31ae82e91ee47781a811746988d185bdeb14d1f3e7e7d8e6da954ec849a4ed2254a9657c
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ for cpaturing and forwarding exceptions to SquareSquash/web server
|
|
8
8
|
Add this line to your application's Gemfile:
|
9
9
|
|
10
10
|
```ruby
|
11
|
-
gem 'exception-notifier-squash-notifier'
|
11
|
+
gem 'exception-notifier-squash-notifier', require: 'exception_notifier/squash_notifier'
|
12
12
|
```
|
13
13
|
|
14
14
|
And then execute:
|
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "simplecov", "~> 0.9"
|
26
26
|
spec.add_development_dependency "exception_notification", "~> 4.0"
|
27
27
|
|
28
|
-
spec.add_dependency "activesupport", "
|
28
|
+
spec.add_dependency "activesupport", "~> 3.0"
|
29
29
|
spec.add_dependency "squash_ruby", "~> 2.0"
|
30
30
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Extend SquashNotifier with Rails support
|
2
|
+
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
class ExceptionNotifier::SquashNotifier
|
6
|
+
self.whitelisted_env_vars += [
|
7
|
+
'action_dispatch.request.parameters',
|
8
|
+
'action_dispatch.request.path_parameters',
|
9
|
+
'action_dispatch.request.query_parameters',
|
10
|
+
'action_dispatch.request.request_parameters',
|
11
|
+
/HTTP_/,
|
12
|
+
'PASSENGER_APP_TYPE',
|
13
|
+
'PASSENGER_ENV',
|
14
|
+
'PASSENGER_RUBY',
|
15
|
+
'PASSENGER_SPAWN_METHOD',
|
16
|
+
'PASSENGER_USER',
|
17
|
+
'RAILS_ENV',
|
18
|
+
'REMOTE_ADDR',
|
19
|
+
'REMOTE_PORT',
|
20
|
+
'REQUEST_METHOD',
|
21
|
+
'REQUEST_URI',
|
22
|
+
'SERVER_ADDR',
|
23
|
+
'SERVER_NAME',
|
24
|
+
'SERVER_PORT',
|
25
|
+
'SERVER_PROTOCOL',
|
26
|
+
'SERVER_SOFTWARE',
|
27
|
+
]
|
28
|
+
|
29
|
+
def munge_env(data)
|
30
|
+
return data unless data.has_key?(:env)
|
31
|
+
|
32
|
+
env = data.delete(:env)
|
33
|
+
|
34
|
+
request = ActionDispatch::Request.new(env)
|
35
|
+
|
36
|
+
whitelist_env = Squash::Ruby.configuration(:filter_env_vars)
|
37
|
+
parameter_filter = ActionDispatch::Http::ParameterFilter.new(env["action_dispatch.parameter_filter"])
|
38
|
+
filtered_env = whitelist_env.call(request.try(:filtered_env) || parameter_filter.filter(env))
|
39
|
+
|
40
|
+
data.merge(occurence_data(
|
41
|
+
request: request,
|
42
|
+
session: parameter_filter.filter(request.session.to_hash),
|
43
|
+
cookies: env['rack.request.cookie_hash'],
|
44
|
+
rack_env: filtered_env
|
45
|
+
))
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def occurence_data(request: nil, session: nil, cookies: {}, rack_env: {})
|
51
|
+
flash_key = defined?(ActionDispatch) ? ActionDispatch::Flash::KEY : 'flash'
|
52
|
+
|
53
|
+
# raw_session_id = request.session['session_id'] || (request.env["rack.session.options"] and request.env["rack.session.options"][:id])
|
54
|
+
# session_id = request.ssl? ? "[FILTERED]" : raw_session_id.inspect
|
55
|
+
|
56
|
+
#NB: If you update this hash, make sure to update TOP_LEVEL_USER_DATA in
|
57
|
+
# squash_ruby/rails.rb
|
58
|
+
{
|
59
|
+
:environment => environment_name,
|
60
|
+
:root => root_path,
|
61
|
+
|
62
|
+
# Squash Server recreates the URL from these:
|
63
|
+
:request_method => request.request_method.to_s,
|
64
|
+
:schema => request.protocol.sub('://', ''),
|
65
|
+
:host => request.host,
|
66
|
+
:port => request.port,
|
67
|
+
:path => request.path,
|
68
|
+
:query => request.query_string,
|
69
|
+
:headers => request_headers(rack_env),
|
70
|
+
|
71
|
+
# :controller ## Rails Controller
|
72
|
+
# :action ## Rails Action
|
73
|
+
:params => request.filtered_parameters,
|
74
|
+
# :session_id => session_id,
|
75
|
+
:session => session,
|
76
|
+
:flash => session[flash_key],
|
77
|
+
:cookies => cookies,
|
78
|
+
|
79
|
+
# User Data:
|
80
|
+
:host_ip => request.remote_ip,
|
81
|
+
:host_name => Socket.gethostname,
|
82
|
+
:"rack.env" => rack_env.to_hash
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def environment_name
|
87
|
+
return ::Rails.env.to_s if defined?(::Rails)
|
88
|
+
ENV['RAILS_ENV'] || ENV['RACK_ENV']
|
89
|
+
end
|
90
|
+
|
91
|
+
# Extract any rack key/value pairs where the key begins with HTTP_*
|
92
|
+
def request_headers(env)
|
93
|
+
env.select { |key, _| key[0, 5] == 'HTTP_' }
|
94
|
+
end
|
95
|
+
|
96
|
+
def root_path
|
97
|
+
defined?(::Rails) ? ::Rails.root.to_s : ENV['RAILS_ROOT']
|
98
|
+
end
|
99
|
+
end
|
@@ -7,11 +7,9 @@ require "exception_notifier/squash_ruby"
|
|
7
7
|
|
8
8
|
module ExceptionNotifier
|
9
9
|
class SquashNotifier
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
'action_dispatch.request.query_parameters',
|
14
|
-
'action_dispatch.request.request_parameters',
|
10
|
+
cattr_accessor :whitelisted_env_vars
|
11
|
+
# This accepts RegEx, so to not-whitelist, add an entry of /.*/
|
12
|
+
self.whitelisted_env_vars = [
|
15
13
|
'BUNDLE_BIN_PATH',
|
16
14
|
'BUNDLE_GEMFILE',
|
17
15
|
'CONTENT_LENGTH',
|
@@ -19,31 +17,14 @@ module ExceptionNotifier
|
|
19
17
|
'DOCUMENT_ROOT',
|
20
18
|
'GEM_HOME',
|
21
19
|
'HOME',
|
22
|
-
/HTTP_/,
|
23
20
|
'ORIGINAL_FULLPATH',
|
24
|
-
'PASSENGER_APP_TYPE',
|
25
|
-
'PASSENGER_ENV',
|
26
|
-
'PASSENGER_RUBY',
|
27
|
-
'PASSENGER_SPAWN_METHOD',
|
28
|
-
'PASSENGER_USER',
|
29
21
|
'PATH',
|
30
22
|
'PATH_INFO',
|
31
23
|
'PWD',
|
32
|
-
'RAILS_ENV',
|
33
|
-
'REMOTE_ADDR',
|
34
|
-
'REMOTE_PORT',
|
35
|
-
'REQUEST_METHOD',
|
36
|
-
'REQUEST_URI',
|
37
24
|
'RUBYOPT',
|
38
|
-
'SERVER_ADDR',
|
39
|
-
'SERVER_NAME',
|
40
|
-
'SERVER_PORT',
|
41
|
-
'SERVER_PROTOCOL',
|
42
|
-
'SERVER_SOFTWARE',
|
43
25
|
'TMPDIR',
|
44
26
|
'USER',
|
45
27
|
]
|
46
|
-
cattr_accessor :whitelisted_env_vars
|
47
28
|
|
48
29
|
def self.default_options
|
49
30
|
{
|
@@ -76,9 +57,16 @@ module ExceptionNotifier
|
|
76
57
|
Squash::Ruby.configure disabled: !Squash::Ruby.configuration(:api_key)
|
77
58
|
end
|
78
59
|
|
79
|
-
def call(exception,
|
60
|
+
def call(exception, data={})
|
80
61
|
#NB: You can pass a `user_data` hash to #notify, and most attr's will be placed into a `user_data` field
|
81
|
-
Squash::Ruby.notify(exception,
|
62
|
+
Squash::Ruby.notify(exception, munge_env(data))
|
63
|
+
end
|
64
|
+
|
65
|
+
def munge_env(data)
|
66
|
+
data
|
82
67
|
end
|
83
68
|
end
|
84
69
|
end
|
70
|
+
|
71
|
+
# Extend class if you find Rails is being used:
|
72
|
+
require 'exception_notifier/squash_notifier/rails' if defined? Rails
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Extend SquashNotifier with Rails support
|
2
|
+
|
3
|
+
module Squash::Ruby
|
4
|
+
TOP_LEVEL_USER_DATA.concat(
|
5
|
+
%w[environment root xhr
|
6
|
+
headers
|
7
|
+
request_method schema host port path query
|
8
|
+
params session flash cookies]
|
9
|
+
)
|
10
|
+
|
11
|
+
def self.client_name
|
12
|
+
'squash-rails'
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.failsafe_log(tag, message)
|
16
|
+
logger = Rails.respond_to?(:logger) ? Rails.logger : RAILS_DEFAULT_LOGGER
|
17
|
+
if (logger.respond_to?(:tagged))
|
18
|
+
logger.tagged(tag) { logger.error message }
|
19
|
+
else
|
20
|
+
logger.error "[#{tag}]\t#{message}"
|
21
|
+
end
|
22
|
+
rescue Object => err
|
23
|
+
$stderr.puts "Couldn't write to failsafe log (#{err.to_s}); writing to stderr instead."
|
24
|
+
$stderr.puts "#{Time.now.to_s}\t[#{tag}]\t#{message}"
|
25
|
+
end
|
26
|
+
end
|
@@ -8,6 +8,10 @@ module Squash::Ruby
|
|
8
8
|
class << self
|
9
9
|
private
|
10
10
|
|
11
|
+
def client_name
|
12
|
+
'squash'
|
13
|
+
end
|
14
|
+
|
11
15
|
alias :environment_data__original :environment_data
|
12
16
|
|
13
17
|
def environment_data
|
@@ -23,3 +27,6 @@ module Squash::Ruby
|
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
30
|
+
|
31
|
+
# Extend class if you find Rails is being used:
|
32
|
+
require 'exception_notifier/squash_ruby/rails' if defined? Rails
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exception_notification-squash_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.1
|
4
|
+
version: 0.1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Robertson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,16 +98,16 @@ dependencies:
|
|
98
98
|
name: activesupport
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 3.0
|
103
|
+
version: '3.0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 3.0
|
110
|
+
version: '3.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: squash_ruby
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,8 +140,10 @@ files:
|
|
140
140
|
- bin/exception-notifier-squash-notifier
|
141
141
|
- exception-notification-squash-notifier.gemspec
|
142
142
|
- lib/exception_notifier/squash_notifier.rb
|
143
|
+
- lib/exception_notifier/squash_notifier/rails.rb
|
143
144
|
- lib/exception_notifier/squash_notifier/version.rb
|
144
145
|
- lib/exception_notifier/squash_ruby.rb
|
146
|
+
- lib/exception_notifier/squash_ruby/rails.rb
|
145
147
|
- spec/exception_notifier/squash_notifier_spec.rb
|
146
148
|
- spec/exception_notifier/squash_ruby_spec.rb
|
147
149
|
- spec/spec_helper.rb
|