ratchetio 0.4.0 → 0.4.8
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.
- data/.gitignore +2 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.md +29 -4
- data/Gemfile +5 -1
- data/README.md +45 -8
- data/Rakefile +13 -1
- data/THANKS +5 -0
- data/lib/generators/ratchetio/ratchetio_generator.rb +1 -1
- data/lib/generators/ratchetio/templates/initializer.rb +10 -0
- data/lib/ratchetio/configuration.rb +24 -10
- data/lib/ratchetio/goalie.rb +23 -0
- data/lib/ratchetio/rails/controller_methods.rb +8 -3
- data/lib/ratchetio/rails/middleware/exception_catcher.rb +2 -4
- data/lib/ratchetio/railtie.rb +1 -0
- data/lib/ratchetio/version.rb +1 -1
- data/lib/ratchetio.rb +186 -59
- data/ratchetio.gemspec +6 -3
- data/spec/controllers/home_controller_spec.rb +186 -0
- data/spec/dummyapp/.gitignore +73 -0
- data/spec/dummyapp/Rakefile +7 -0
- data/spec/dummyapp/app/assets/javascripts/application.js +3 -0
- data/spec/dummyapp/app/assets/stylesheets/application.css.scss +37 -0
- data/spec/dummyapp/app/controllers/application_controller.rb +3 -0
- data/spec/dummyapp/app/controllers/home_controller.rb +21 -0
- data/spec/dummyapp/app/controllers/users_controller.rb +12 -0
- data/spec/dummyapp/app/helpers/.gitkeep +0 -0
- data/spec/dummyapp/app/mailers/.gitkeep +0 -0
- data/spec/dummyapp/app/models/.gitkeep +0 -0
- data/spec/dummyapp/app/models/user.rb +11 -0
- data/spec/dummyapp/app/views/devise/registrations/edit.html.erb +27 -0
- data/spec/dummyapp/app/views/devise/registrations/new.html.erb +20 -0
- data/spec/dummyapp/app/views/devise/shared/_links.html.erb +25 -0
- data/spec/dummyapp/app/views/home/cause_exception.html.erb +1 -0
- data/spec/dummyapp/app/views/home/index.html.erb +4 -0
- data/spec/dummyapp/app/views/home/report_exception.html.erb +1 -0
- data/spec/dummyapp/app/views/layouts/_messages.html.erb +5 -0
- data/spec/dummyapp/app/views/layouts/_navigation.html.erb +21 -0
- data/spec/dummyapp/app/views/layouts/application.html.erb +25 -0
- data/spec/dummyapp/app/views/users/index.html.erb +8 -0
- data/spec/dummyapp/app/views/users/show.html.erb +3 -0
- data/spec/dummyapp/config/application.rb +60 -0
- data/spec/dummyapp/config/boot.rb +10 -0
- data/spec/dummyapp/config/database.yml +25 -0
- data/spec/dummyapp/config/environment.rb +5 -0
- data/spec/dummyapp/config/environments/development.rb +37 -0
- data/spec/dummyapp/config/environments/production.rb +67 -0
- data/spec/dummyapp/config/environments/test.rb +37 -0
- data/spec/dummyapp/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummyapp/config/initializers/devise.rb +233 -0
- data/spec/dummyapp/config/initializers/inflections.rb +15 -0
- data/spec/dummyapp/config/initializers/mime_types.rb +5 -0
- data/spec/dummyapp/config/initializers/ratchetio.rb +20 -0
- data/spec/dummyapp/config/initializers/secret_token.rb +7 -0
- data/spec/dummyapp/config/initializers/session_store.rb +8 -0
- data/spec/dummyapp/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummyapp/config/locales/devise.en.yml +58 -0
- data/spec/dummyapp/config/locales/en.yml +5 -0
- data/spec/dummyapp/config/routes.rb +11 -0
- data/spec/dummyapp/config.ru +4 -0
- data/spec/dummyapp/db/migrate/20121121184652_devise_create_users.rb +46 -0
- data/spec/dummyapp/db/migrate/20121121184654_add_name_to_users.rb +5 -0
- data/spec/dummyapp/db/schema.rb +35 -0
- data/spec/dummyapp/db/seeds.rb +12 -0
- data/spec/dummyapp/lib/assets/.gitkeep +0 -0
- data/spec/dummyapp/public/404.html +26 -0
- data/spec/dummyapp/public/422.html +26 -0
- data/spec/dummyapp/public/500.html +25 -0
- data/spec/dummyapp/public/favicon.ico +0 -0
- data/spec/dummyapp/script/rails +6 -0
- data/spec/ratchetio_spec.rb +387 -1
- data/spec/spec_helper.rb +35 -0
- data/spec/support/devise.rb +3 -0
- metadata +195 -3
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
**0.4.8**
|
|
4
|
+
- Add ability to send reports asynchronously, using girl_friday or Threading by default.
|
|
5
|
+
- Add ability to save reports to a file (for use with ratchet-agent) instead of sending across to Ratchet servers.
|
|
6
|
+
|
|
7
|
+
**0.4.7**
|
|
8
|
+
- Sensitive params now scrubbed out of requests. Param name list is customizable via the `scrub_fields` config option.
|
|
9
|
+
|
|
10
|
+
**0.4.6**
|
|
11
|
+
- Add support to play nicely with Goalie.
|
|
12
|
+
|
|
13
|
+
**0.4.5**
|
|
14
|
+
- Add `default_logger` config option. It should be a lambda that will return the logger to use if no other logger is configured (i.e. no logger is set by the Railtie hook). Default: `lambda { Logger.new(STDERR) }`
|
|
15
|
+
|
|
16
|
+
**0.4.4**
|
|
17
|
+
- Add `enabled` runtime config flag. When `false`, no data (messages or exceptions) will be reported.
|
|
18
|
+
|
|
19
|
+
**0.4.3**
|
|
20
|
+
- Add RSpec test suite. A few minor code changes.
|
|
21
|
+
|
|
22
|
+
**0.4.2**
|
|
23
|
+
- Add "ignore" filter level to completely ignore exceptions by class.
|
|
24
|
+
|
|
25
|
+
**0.4.1**
|
|
26
|
+
- Recursively filter files out of the params hash. Thanks to [trisweb](https://github.com/trisweb) for the pull request.
|
|
27
|
+
|
|
3
28
|
**0.4.0**
|
|
4
29
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
30
|
+
- Breaking change to make the "person" more configurable. If you were previously relying on your `current_member` method being called to return the person object, you will need to add the following line to `config/initializers/ratchetio.rb`:
|
|
31
|
+
|
|
32
|
+
config.person_method = "current_member"
|
|
8
33
|
|
|
9
|
-
|
|
34
|
+
- Person id, username, and email method names are now configurable -- see README for details.
|
data/Gemfile
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
|
-
# Specify your gem's dependencies in ratchetio.gemspec
|
|
4
3
|
gemspec
|
|
4
|
+
|
|
5
|
+
gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
|
|
6
|
+
gem 'jruby-openssl', :platform => :jruby
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
|
|
8
|
+
gem 'girl_friday'
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Ratchetio
|
|
1
|
+
# Ratchetio [](https://travis-ci.org/ratchetio/ratchetio-gem)
|
|
2
2
|
|
|
3
3
|
Ruby gem for Ratchet.io, for reporting exceptions in Rails 3 to Ratchet.io. Requires a Ratchet.io account (you can sign up for free).
|
|
4
4
|
|
|
@@ -59,22 +59,22 @@ Ratchetio.report_message("Unexpected input", "warning")
|
|
|
59
59
|
# default level is "info"
|
|
60
60
|
Ratchetio.report_message("Login successful")
|
|
61
61
|
|
|
62
|
-
# can also include additional data as a hash in the final param
|
|
62
|
+
# can also include additional data as a hash in the final param. :body is reserved.
|
|
63
63
|
Ratchetio.report_message("Login successful", "info", :user => @user)
|
|
64
64
|
```
|
|
65
65
|
|
|
66
66
|
|
|
67
67
|
## Person tracking
|
|
68
68
|
|
|
69
|
-
Ratchet will send information about the current user (called a "person" in Ratchet parlance) along with each error report, when available. This works by calling the `
|
|
69
|
+
Ratchet will send information about the current user (called a "person" in Ratchet parlance) along with each error report, when available. This works by calling the `current_user` controller method. The return value should be an object with an `id` method and, optionally, `username` and `email` methods.
|
|
70
70
|
|
|
71
|
-
If the gem should call a controller method besides `
|
|
71
|
+
If the gem should call a controller method besides `current_user`, add the following in `config/initializers/ratchetio.rb`:
|
|
72
72
|
|
|
73
73
|
```ruby
|
|
74
74
|
config.person_method = "my_current_user"
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
If the methods to extract the `id`, `username`, and `email` from the object returned by the `
|
|
77
|
+
If the methods to extract the `id`, `username`, and `email` from the object returned by the `person_method` have other names, configure like so in `config/initializers/ratchetio.rb`:
|
|
78
78
|
|
|
79
79
|
```ruby
|
|
80
80
|
config.person_id_method = "user_id" # default is "id"
|
|
@@ -85,18 +85,53 @@ If the methods to extract the `id`, `username`, and `email` from the object retu
|
|
|
85
85
|
|
|
86
86
|
## Exception level filters
|
|
87
87
|
|
|
88
|
-
By default, all exceptions reported through `Ratchetio.
|
|
88
|
+
By default, all exceptions reported through `Ratchetio.report_exception()` are reported at the "error" level, except for the following, which are reported at "warning" level:
|
|
89
89
|
|
|
90
90
|
- ActiveRecord::RecordNotFound
|
|
91
91
|
- AbstractController::ActionNotFound
|
|
92
92
|
- ActionController::RoutingError
|
|
93
93
|
|
|
94
|
-
If you'd like to customize this list, see the example code in `config/initializers/ratchetio.rb`. Supported levels: "critical", "error", "warning", "info", "debug".
|
|
94
|
+
If you'd like to customize this list, see the example code in `config/initializers/ratchetio.rb`. Supported levels: "critical", "error", "warning", "info", "debug", "ignore". Set to "ignore" to cause the exception not to be reported at all.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## Asynchronous reporting
|
|
99
|
+
|
|
100
|
+
By default, all messages are reported synchronously. You can enable asynchronous reporting by adding the following in `config/initializers/ratchetio.rb`:
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
config.use_async = true
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Ratchet uses [girl_friday](https://github.com/mperham/girl_friday) to handle asynchronous reporting when installed, and falls back to Threading if girl_friday is not installed.
|
|
107
|
+
|
|
108
|
+
You can supply your own handler using `config.async_handler`. The handler should schedule the payload for later processing (i.e. with a delayed_job, in a resque queue, etc.) and should itself return immediately. For example:
|
|
109
|
+
|
|
110
|
+
```ruby
|
|
111
|
+
config.async_handler = Proc.new { |payload|
|
|
112
|
+
Thread.new { Ratchetio.process_payload(payload) }
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Make sure you pass `payload` to `Ratchetio.process_payload` in your own implementation.
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
## Using with ratchet-agent
|
|
120
|
+
|
|
121
|
+
For even more asynchrony, you can configure the gem to write to a file instead of sending the payload to Ratchet servers directly. [ratchet-agent](https://github.com/ratchetio/ratchet-agent) can then be hooked up to this file to actually send the payload across. To enable, add the following in `config/initializers/ratchetio.rb`:
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
config.write_to_file = true
|
|
125
|
+
# optional, defaults to "#{AppName}.ratchet"
|
|
126
|
+
config.filepath = '/path/to/file.ratchet' #should end in '.ratchet' for use with ratchet-agent
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
For this to work, you'll also need to set up ratchet-agent--see its docs for details.
|
|
95
130
|
|
|
96
131
|
|
|
97
132
|
## Help / Support
|
|
98
133
|
|
|
99
|
-
If you run into any issues, please email
|
|
134
|
+
If you run into any issues, please email us at `support@ratchet.io`
|
|
100
135
|
|
|
101
136
|
## Contributing
|
|
102
137
|
|
|
@@ -105,3 +140,5 @@ If you run into any issues, please email me at support@ratchet.io
|
|
|
105
140
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
106
141
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
107
142
|
5. Create new Pull Request
|
|
143
|
+
|
|
144
|
+
We're using RSpec for testing. Run the test suite with `rake spec`. Tests for pull requests are appreciated but not required. (If you don't include a test, we'll write one before merging.)
|
data/Rakefile
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env rake
|
|
2
|
-
require
|
|
2
|
+
require 'bundler/gem_tasks'
|
|
3
|
+
require 'rspec/core/rake_task'
|
|
4
|
+
|
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
6
|
+
|
|
7
|
+
namespace :dummy do
|
|
8
|
+
load 'spec/dummyapp/Rakefile'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
desc 'Run specs'
|
|
12
|
+
task :default => ['dummy:db:setup'] do
|
|
13
|
+
Rake::Task[:spec].invoke
|
|
14
|
+
end
|
data/THANKS
ADDED
|
@@ -4,7 +4,7 @@ require 'rails/generators/named_base'
|
|
|
4
4
|
module Ratchetio
|
|
5
5
|
module Generators
|
|
6
6
|
class RatchetioGenerator < ::Rails::Generators::Base
|
|
7
|
-
argument :access_token, :type => :string, :banner =>
|
|
7
|
+
argument :access_token, :type => :string, :banner => 'access_token'
|
|
8
8
|
|
|
9
9
|
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
|
10
10
|
|
|
@@ -14,5 +14,15 @@ Ratchetio.configure do |config|
|
|
|
14
14
|
# change the level that exception is reported at. Note that if an exception
|
|
15
15
|
# has already been reported and logged the level will need to be changed
|
|
16
16
|
# via the ratchet.io interface.
|
|
17
|
+
# Valid levels: 'critical', 'error', 'warning', 'info', 'debug', 'ignore'
|
|
18
|
+
# 'ignore' will cause the exception to not be reported at all.
|
|
17
19
|
# config.exception_level_filters.merge!('MyCriticalException' => 'critical')
|
|
20
|
+
|
|
21
|
+
# Enable asynchronous reporting (uses girl_friday or Threading if girl_friday
|
|
22
|
+
# is not installed)
|
|
23
|
+
# config.use_async = true
|
|
24
|
+
# Supply your own async handler:
|
|
25
|
+
# config.async_handler = Proc.new { |payload|
|
|
26
|
+
# Thread.new { Ratchetio.process_payload(payload) }
|
|
27
|
+
# }
|
|
18
28
|
end
|
|
@@ -1,34 +1,48 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
|
|
1
3
|
module Ratchetio
|
|
2
4
|
class Configuration
|
|
3
5
|
|
|
4
6
|
attr_accessor :access_token
|
|
5
|
-
attr_accessor :environment
|
|
6
|
-
attr_accessor :root
|
|
7
7
|
attr_accessor :branch
|
|
8
|
-
attr_accessor :
|
|
8
|
+
attr_accessor :default_logger
|
|
9
|
+
attr_accessor :enabled
|
|
9
10
|
attr_accessor :endpoint
|
|
11
|
+
attr_accessor :write_to_file
|
|
12
|
+
attr_accessor :filepath
|
|
13
|
+
attr_accessor :environment
|
|
10
14
|
attr_accessor :exception_level_filters
|
|
15
|
+
attr_accessor :framework
|
|
16
|
+
attr_accessor :logger
|
|
11
17
|
attr_accessor :person_method
|
|
12
18
|
attr_accessor :person_id_method
|
|
13
19
|
attr_accessor :person_username_method
|
|
14
20
|
attr_accessor :person_email_method
|
|
21
|
+
attr_accessor :root
|
|
22
|
+
attr_accessor :scrub_fields
|
|
23
|
+
attr_accessor :use_async
|
|
24
|
+
attr_accessor :async_handler
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
DEFAULT_ENDPOINT = "https://submit.ratchet.io/api/1/item/"
|
|
26
|
+
DEFAULT_ENDPOINT = 'https://submit.ratchet.io/api/1/item/'
|
|
19
27
|
|
|
20
28
|
def initialize
|
|
29
|
+
@default_logger = lambda { Logger.new(STDERR) }
|
|
30
|
+
@enabled = true
|
|
21
31
|
@endpoint = DEFAULT_ENDPOINT
|
|
32
|
+
@write_to_file = false
|
|
22
33
|
@framework = 'Plain'
|
|
23
34
|
@exception_level_filters = {
|
|
24
35
|
'ActiveRecord::RecordNotFound' => 'warning',
|
|
25
36
|
'AbstractController::ActionNotFound' => 'warning',
|
|
26
37
|
'ActionController::RoutingError' => 'warning'
|
|
27
38
|
}
|
|
28
|
-
@person_method =
|
|
29
|
-
@person_id_method =
|
|
30
|
-
@person_username_method =
|
|
31
|
-
@person_email_method =
|
|
39
|
+
@person_method = 'current_user'
|
|
40
|
+
@person_id_method = 'id'
|
|
41
|
+
@person_username_method = 'username'
|
|
42
|
+
@person_email_method = 'email'
|
|
43
|
+
@scrub_fields = [:passwd, :password, :secret]
|
|
44
|
+
@use_async = false
|
|
45
|
+
@async_handler = nil
|
|
32
46
|
end
|
|
33
47
|
|
|
34
48
|
# allow params to be read like a hash
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Goalie
|
|
2
|
+
class CustomErrorPages
|
|
3
|
+
alias_method :orig_render_exception, :render_exception
|
|
4
|
+
|
|
5
|
+
private
|
|
6
|
+
|
|
7
|
+
def render_exception(env, exception)
|
|
8
|
+
begin
|
|
9
|
+
controller = env['action_controller.instance']
|
|
10
|
+
request_data = controller.try(:ratchetio_request_data)
|
|
11
|
+
person_data = controller.try(:ratchetio_person_data)
|
|
12
|
+
Ratchetio.report_exception(exception, request_data, person_data)
|
|
13
|
+
rescue => e
|
|
14
|
+
# TODO use logger here?
|
|
15
|
+
puts "[Ratchet.io] Exception while reporting exception to Ratchet.io: #{e}"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# now continue as normal
|
|
19
|
+
orig_render_exception(env, exception)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
@@ -35,6 +35,7 @@ module Ratchetio
|
|
|
35
35
|
|
|
36
36
|
def ratchetio_filter_params(params)
|
|
37
37
|
filtered = {}
|
|
38
|
+
|
|
38
39
|
params.to_hash.each_pair do |k,v|
|
|
39
40
|
if v.is_a? ActionDispatch::Http::UploadedFile
|
|
40
41
|
# only save content_type, original_filename, and length
|
|
@@ -45,8 +46,12 @@ module Ratchetio
|
|
|
45
46
|
:size => v.tempfile.size
|
|
46
47
|
}
|
|
47
48
|
rescue
|
|
48
|
-
filtered[k] =
|
|
49
|
+
filtered[k] = 'Uploaded file'
|
|
49
50
|
end
|
|
51
|
+
elsif v.is_a? Hash
|
|
52
|
+
filtered[k] = ratchetio_filter_params v
|
|
53
|
+
elsif Ratchetio.configuration.scrub_fields.include? k
|
|
54
|
+
filtered[k] = "*" * v.length
|
|
50
55
|
else
|
|
51
56
|
filtered[k] = v
|
|
52
57
|
end
|
|
@@ -65,11 +70,11 @@ module Ratchetio
|
|
|
65
70
|
|
|
66
71
|
def ratchetio_user_ip
|
|
67
72
|
# priority: X-Real-Ip, then X-Forwarded-For, then request.remote_ip
|
|
68
|
-
real_ip = request.env[
|
|
73
|
+
real_ip = request.env['HTTP_X_REAL_IP']
|
|
69
74
|
if real_ip
|
|
70
75
|
return real_ip
|
|
71
76
|
end
|
|
72
|
-
forwarded_for = request.env[
|
|
77
|
+
forwarded_for = request.env['HTTP_X_FORWARDED_FOR']
|
|
73
78
|
if forwarded_for
|
|
74
79
|
return forwarded_for
|
|
75
80
|
end
|
|
@@ -7,16 +7,14 @@ module Ratchetio
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def render_exception_with_ratchetio(env, exception)
|
|
10
|
-
# wrap everything in a begin-rescue block
|
|
11
10
|
begin
|
|
12
11
|
controller = env['action_controller.instance']
|
|
13
12
|
request_data = controller.try(:ratchetio_request_data)
|
|
14
13
|
person_data = controller.try(:ratchetio_person_data)
|
|
15
14
|
Ratchetio.report_exception(exception, request_data, person_data)
|
|
16
|
-
rescue
|
|
15
|
+
rescue => e
|
|
17
16
|
# TODO use logger here?
|
|
18
|
-
puts "[Ratchet.io] Exception while reporting exception to Ratchet.io: "
|
|
19
|
-
puts exc
|
|
17
|
+
puts "[Ratchet.io] Exception while reporting exception to Ratchet.io: #{e}"
|
|
20
18
|
end
|
|
21
19
|
|
|
22
20
|
# now continue as normal
|
data/lib/ratchetio/railtie.rb
CHANGED
|
@@ -13,6 +13,7 @@ module Ratchetio
|
|
|
13
13
|
config.environment ||= ::Rails.env
|
|
14
14
|
config.root ||= ::Rails.root
|
|
15
15
|
config.framework = "Rails: #{::Rails::VERSION::STRING}"
|
|
16
|
+
config.filepath ||= ::Rails.application.class.parent_name + '.ratchet'
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
ActiveSupport.on_load(:action_controller) do
|
data/lib/ratchetio/version.rb
CHANGED