raygun4ruby 0.0.6 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +47 -0
- data/lib/raygun/client.rb +27 -7
- data/lib/raygun/configuration.rb +11 -3
- data/lib/raygun/middleware/rack_exception_interceptor.rb +18 -0
- data/lib/raygun/middleware/rails_insert_affected_user.rb +32 -0
- data/lib/raygun/railtie.rb +7 -3
- data/lib/raygun/version.rb +1 -1
- data/lib/raygun.rb +2 -2
- metadata +21 -40
- data/lib/raygun/rack_exception_interceptor.rb +0 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 364f723004d0b0a022bb82d74551e274466cd296
|
4
|
+
data.tar.gz: 2a403d1dc79b9ea1c580e4f232284769894a3eaf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a7597177c7877ca08356ded80ba631e437b173b1e3fa9409458e564c4b5174a0aa5b35156d4e8dabe7d5aefc991e790b4c4da23553248f6c52dc3af6483a296b
|
7
|
+
data.tar.gz: 57f578a39ae59d7ef0dc1c275b945b86b4b23e26bf51f5cb41a60ba30eac727dac4956e38f68b3aa255669c578a1dba8be2864c5930fb6bb462311faa9ea68f8
|
data/README.md
CHANGED
@@ -62,6 +62,19 @@ end
|
|
62
62
|
|
63
63
|
(You can also pass a Hash as the second parameter to `track_exception`. It should look like a [Rack Env Hash](http://rack.rubyforge.org/doc/SPEC.html))
|
64
64
|
|
65
|
+
###Custom User Data
|
66
|
+
Custom data can be added to `track_exception` by passing a custom_data key in the second parameter hash.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
|
70
|
+
begin
|
71
|
+
# more lovely code
|
72
|
+
rescue Exception => e
|
73
|
+
Raygun.track_exception(e, custom_data: {my: 'custom data', goes: 'here'})
|
74
|
+
end
|
75
|
+
|
76
|
+
```
|
77
|
+
|
65
78
|
###Ignoring Some Errors
|
66
79
|
|
67
80
|
You can ignore certain types of Exception using the `ignore` option in the setup block, like so:
|
@@ -75,6 +88,40 @@ end
|
|
75
88
|
|
76
89
|
You can also check which [exceptions are ignored by default](https://github.com/MindscapeHQ/raygun4ruby/blob/master/lib/raygun/configuration.rb#L26)
|
77
90
|
|
91
|
+
###Affected User Tracking
|
92
|
+
|
93
|
+
Raygun can now track how many users have been affected by an error.
|
94
|
+
|
95
|
+
By default, Raygun looks for a method called `current_user` on your controller, and calls either `email`, `username` or `id` on the object returned by that method.
|
96
|
+
|
97
|
+
You can customize those method names in your configuration block:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
Raygun.setup do |config|
|
101
|
+
config.api_key = "MY_SWEET_API_KEY"
|
102
|
+
config.affected_user_method = :my_current_user # `current_user` by default
|
103
|
+
config.affected_user_identifier_methods << :login # `[ :email, :username, :id ]` by default - will use the first that works
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
If you're using Rails, most authentication systems will have this method set and you should be good to go.
|
108
|
+
|
109
|
+
The count of unique affected users will appear on the error group in the Raygun dashboard. If your user has an `email` method, and that email has a Gravatars associated, you will also see your user's avatar.
|
110
|
+
|
111
|
+
If you wish to keep it anonymous, you could set this identifier to something like `SecureRandom.uuid` and store that in a cookie, like so:
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
class ApplicationController < ActionController::Base
|
115
|
+
|
116
|
+
def raygun_user
|
117
|
+
cookies.permanent[:raygun_user_identifier] ||= SecureRandom.uuid
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
(Remember to set `affected_user_method` to `:raygun_user` in your config block...)
|
124
|
+
|
78
125
|
###Resque Error Tracking
|
79
126
|
|
80
127
|
Raygun4Ruby also includes a Resque failure backend. You should include it inside your Resque initializer (usually something like `config/initializers/load_resque.rb`)
|
data/lib/raygun/client.rb
CHANGED
@@ -58,6 +58,14 @@ module Raygun
|
|
58
58
|
Raygun.configuration.version
|
59
59
|
end
|
60
60
|
|
61
|
+
def user_information(env)
|
62
|
+
env["raygun.affected_user"]
|
63
|
+
end
|
64
|
+
|
65
|
+
def affected_user_present?(env)
|
66
|
+
!!env["raygun.affected_user"]
|
67
|
+
end
|
68
|
+
|
61
69
|
def request_information(env)
|
62
70
|
return {} if env.nil? || env.empty?
|
63
71
|
|
@@ -65,7 +73,7 @@ module Raygun
|
|
65
73
|
hostName: env["SERVER_NAME"],
|
66
74
|
url: env["PATH_INFO"],
|
67
75
|
httpMethod: env["REQUEST_METHOD"],
|
68
|
-
|
76
|
+
iPAddress: env["REMOTE_ADDR"],
|
69
77
|
queryString: Rack::Utils.parse_nested_query(env["QUERY_STRING"]),
|
70
78
|
form: form_data(env),
|
71
79
|
headers: headers(env),
|
@@ -74,11 +82,19 @@ module Raygun
|
|
74
82
|
end
|
75
83
|
|
76
84
|
def headers(rack_env)
|
77
|
-
rack_env.select do |k, v|
|
78
|
-
k
|
85
|
+
rack_env.select { |k, v| k.to_s.start_with?("HTTP_") }.inject({}) do |hsh, (k, v)|
|
86
|
+
hsh[normalize_raygun_header_key(k)] = v
|
87
|
+
hsh
|
79
88
|
end
|
80
89
|
end
|
81
90
|
|
91
|
+
def normalize_raygun_header_key(key)
|
92
|
+
key.sub(/^HTTP_/, '')
|
93
|
+
.sub(/_/, ' ')
|
94
|
+
.split.map(&:capitalize).join(' ')
|
95
|
+
.sub(/ /, '-')
|
96
|
+
end
|
97
|
+
|
82
98
|
def form_data(rack_env)
|
83
99
|
request = Rack::Request.new(rack_env)
|
84
100
|
|
@@ -91,16 +107,20 @@ module Raygun
|
|
91
107
|
def build_payload_hash(exception_instance, env = {})
|
92
108
|
custom_data = env.delete(:custom_data) || {}
|
93
109
|
|
94
|
-
{
|
95
|
-
occurredOn: Time.now.utc.iso8601,
|
96
|
-
details: {
|
110
|
+
error_details = {
|
97
111
|
machineName: hostname,
|
98
112
|
version: version,
|
99
113
|
client: client_details,
|
100
114
|
error: error_details(exception_instance),
|
101
115
|
userCustomData: Raygun.configuration.custom_data.merge(custom_data),
|
102
116
|
request: request_information(env)
|
103
|
-
|
117
|
+
}
|
118
|
+
|
119
|
+
error_details.merge!(user: user_information(env)) if affected_user_present?(env)
|
120
|
+
|
121
|
+
{
|
122
|
+
occurredOn: Time.now.utc.iso8601,
|
123
|
+
details: error_details
|
104
124
|
}
|
105
125
|
end
|
106
126
|
|
data/lib/raygun/configuration.rb
CHANGED
@@ -22,6 +22,12 @@ module Raygun
|
|
22
22
|
# Failsafe logger (for exceptions that happen when we're attempting to report exceptions)
|
23
23
|
attr_accessor :failsafe_logger
|
24
24
|
|
25
|
+
# Which controller method should we call to find out the affected user?
|
26
|
+
attr_accessor :affected_user_method
|
27
|
+
|
28
|
+
# Which methods should we try on the affected user object in order to get an identifier
|
29
|
+
attr_accessor :affected_user_identifier_methods
|
30
|
+
|
25
31
|
# Exception classes to ignore by default
|
26
32
|
IGNORE_DEFAULT = ['ActiveRecord::RecordNotFound',
|
27
33
|
'ActionController::RoutingError',
|
@@ -33,9 +39,11 @@ module Raygun
|
|
33
39
|
|
34
40
|
def initialize
|
35
41
|
# set default attribute values
|
36
|
-
@ignore
|
37
|
-
@custom_data
|
38
|
-
@silence_reporting
|
42
|
+
@ignore = IGNORE_DEFAULT
|
43
|
+
@custom_data = {}
|
44
|
+
@silence_reporting = nil
|
45
|
+
@affected_user_method = :current_user
|
46
|
+
@affected_user_identifier_methods = [ :email, :username, :id ]
|
39
47
|
end
|
40
48
|
|
41
49
|
def [](key)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Raygun
|
2
|
+
module Middleware
|
3
|
+
class RackExceptionInterceptor
|
4
|
+
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
response = @app.call(env)
|
11
|
+
rescue Exception => exception
|
12
|
+
Raygun.track_exception(exception, env)
|
13
|
+
raise exception
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Raygun
|
2
|
+
module Middleware
|
3
|
+
# Adapted from the Rollbar approach https://github.com/rollbar/rollbar-gem/blob/master/lib/rollbar/middleware/rails/rollbar_request_store.rb
|
4
|
+
class RailsInsertAffectedUser
|
5
|
+
|
6
|
+
def initialize(app)
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
response = @app.call(env)
|
12
|
+
rescue Exception => exception
|
13
|
+
if (controller = env["action_controller.instance"]) && controller.respond_to?(Raygun.configuration.affected_user_method)
|
14
|
+
user = controller.send(Raygun.configuration.affected_user_method)
|
15
|
+
|
16
|
+
if user
|
17
|
+
identifier = if (m = Raygun.configuration.affected_user_identifier_methods.detect { |m| user.respond_to?(m) })
|
18
|
+
user.send(m)
|
19
|
+
else
|
20
|
+
user
|
21
|
+
end
|
22
|
+
|
23
|
+
env["raygun.affected_user"] = { :identifier => identifier }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
raise exception
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/raygun/railtie.rb
CHANGED
@@ -11,12 +11,16 @@ class Raygun::Railtie < Rails::Railtie
|
|
11
11
|
"ActionDispatch::ShowExceptions"
|
12
12
|
end
|
13
13
|
|
14
|
-
app.config.middleware.insert_after middleware, "Raygun::RackExceptionInterceptor"
|
14
|
+
app.config.middleware.insert_after middleware, "Raygun::Middleware::RackExceptionInterceptor"
|
15
|
+
|
16
|
+
# Affected User tracking
|
17
|
+
require "raygun/middleware/rails_insert_affected_user"
|
18
|
+
app.config.middleware.insert_after Raygun::Middleware::RackExceptionInterceptor, "Raygun::Middleware::RailsInsertAffectedUser"
|
15
19
|
end
|
16
20
|
|
17
21
|
config.to_prepare do
|
18
|
-
Raygun.configuration.logger
|
19
|
-
Raygun.configuration.silence_reporting
|
22
|
+
Raygun.configuration.logger ||= Rails.logger
|
23
|
+
Raygun.configuration.silence_reporting = !Rails.env.production? if Raygun.configuration.silence_reporting.nil?
|
20
24
|
end
|
21
25
|
|
22
26
|
rake_tasks do
|
data/lib/raygun/version.rb
CHANGED
data/lib/raygun.rb
CHANGED
@@ -10,7 +10,7 @@ require "rack"
|
|
10
10
|
require "raygun/version"
|
11
11
|
require "raygun/configuration"
|
12
12
|
require "raygun/client"
|
13
|
-
require "raygun/rack_exception_interceptor"
|
13
|
+
require "raygun/middleware/rack_exception_interceptor"
|
14
14
|
require "raygun/testable"
|
15
15
|
require "raygun/railtie" if defined?(Rails)
|
16
16
|
|
@@ -69,7 +69,7 @@ module Raygun
|
|
69
69
|
|
70
70
|
def should_report?(exception)
|
71
71
|
return false if configuration.silence_reporting
|
72
|
-
return false if configuration.ignore.include?(exception.class.to_s)
|
72
|
+
return false if configuration.ignore.flatten.include?(exception.class.to_s)
|
73
73
|
true
|
74
74
|
end
|
75
75
|
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raygun4ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.9
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mindscape
|
@@ -10,12 +9,11 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: httparty
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
18
|
- - ~>
|
21
19
|
- !ruby/object:Gem::Version
|
@@ -23,7 +21,6 @@ dependencies:
|
|
23
21
|
type: :runtime
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
25
|
- - ~>
|
29
26
|
- !ruby/object:Gem::Version
|
@@ -31,71 +28,62 @@ dependencies:
|
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: json
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- -
|
32
|
+
- - '>='
|
37
33
|
- !ruby/object:Gem::Version
|
38
34
|
version: '0'
|
39
35
|
type: :runtime
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- -
|
39
|
+
- - '>='
|
45
40
|
- !ruby/object:Gem::Version
|
46
41
|
version: '0'
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: rack
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- -
|
46
|
+
- - '>='
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: '0'
|
55
49
|
type: :runtime
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- -
|
53
|
+
- - '>='
|
61
54
|
- !ruby/object:Gem::Version
|
62
55
|
version: '0'
|
63
56
|
- !ruby/object:Gem::Dependency
|
64
57
|
name: bundler
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
59
|
requirements:
|
68
|
-
- -
|
60
|
+
- - '>='
|
69
61
|
- !ruby/object:Gem::Version
|
70
62
|
version: '1.1'
|
71
63
|
type: :development
|
72
64
|
prerelease: false
|
73
65
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
66
|
requirements:
|
76
|
-
- -
|
67
|
+
- - '>='
|
77
68
|
- !ruby/object:Gem::Version
|
78
69
|
version: '1.1'
|
79
70
|
- !ruby/object:Gem::Dependency
|
80
71
|
name: rake
|
81
72
|
requirement: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
73
|
requirements:
|
84
|
-
- -
|
74
|
+
- - '>='
|
85
75
|
- !ruby/object:Gem::Version
|
86
76
|
version: '0'
|
87
77
|
type: :development
|
88
78
|
prerelease: false
|
89
79
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
80
|
requirements:
|
92
|
-
- -
|
81
|
+
- - '>='
|
93
82
|
- !ruby/object:Gem::Version
|
94
83
|
version: '0'
|
95
84
|
- !ruby/object:Gem::Dependency
|
96
85
|
name: fakeweb
|
97
86
|
requirement: !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
87
|
requirements:
|
100
88
|
- - ~>
|
101
89
|
- !ruby/object:Gem::Version
|
@@ -103,7 +91,6 @@ dependencies:
|
|
103
91
|
type: :development
|
104
92
|
prerelease: false
|
105
93
|
version_requirements: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
94
|
requirements:
|
108
95
|
- - ~>
|
109
96
|
- !ruby/object:Gem::Version
|
@@ -111,23 +98,20 @@ dependencies:
|
|
111
98
|
- !ruby/object:Gem::Dependency
|
112
99
|
name: timecop
|
113
100
|
requirement: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
101
|
requirements:
|
116
|
-
- -
|
102
|
+
- - '>='
|
117
103
|
- !ruby/object:Gem::Version
|
118
104
|
version: '0'
|
119
105
|
type: :development
|
120
106
|
prerelease: false
|
121
107
|
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
108
|
requirements:
|
124
|
-
- -
|
109
|
+
- - '>='
|
125
110
|
- !ruby/object:Gem::Version
|
126
111
|
version: '0'
|
127
112
|
- !ruby/object:Gem::Dependency
|
128
113
|
name: minitest
|
129
114
|
requirement: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
115
|
requirements:
|
132
116
|
- - ~>
|
133
117
|
- !ruby/object:Gem::Version
|
@@ -135,7 +119,6 @@ dependencies:
|
|
135
119
|
type: :development
|
136
120
|
prerelease: false
|
137
121
|
version_requirements: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
122
|
requirements:
|
140
123
|
- - ~>
|
141
124
|
- !ruby/object:Gem::Version
|
@@ -143,17 +126,15 @@ dependencies:
|
|
143
126
|
- !ruby/object:Gem::Dependency
|
144
127
|
name: resque
|
145
128
|
requirement: !ruby/object:Gem::Requirement
|
146
|
-
none: false
|
147
129
|
requirements:
|
148
|
-
- -
|
130
|
+
- - '>='
|
149
131
|
- !ruby/object:Gem::Version
|
150
132
|
version: '0'
|
151
133
|
type: :development
|
152
134
|
prerelease: false
|
153
135
|
version_requirements: !ruby/object:Gem::Requirement
|
154
|
-
none: false
|
155
136
|
requirements:
|
156
|
-
- -
|
137
|
+
- - '>='
|
157
138
|
- !ruby/object:Gem::Version
|
158
139
|
version: '0'
|
159
140
|
description: Ruby Adapter for Raygun.io
|
@@ -166,7 +147,8 @@ files:
|
|
166
147
|
- lib/raygun.rb
|
167
148
|
- lib/raygun/client.rb
|
168
149
|
- lib/raygun/configuration.rb
|
169
|
-
- lib/raygun/rack_exception_interceptor.rb
|
150
|
+
- lib/raygun/middleware/rack_exception_interceptor.rb
|
151
|
+
- lib/raygun/middleware/rails_insert_affected_user.rb
|
170
152
|
- lib/raygun/railtie.rb
|
171
153
|
- lib/raygun/version.rb
|
172
154
|
- lib/raygun4ruby.rb
|
@@ -178,27 +160,26 @@ files:
|
|
178
160
|
homepage: http://raygun.io
|
179
161
|
licenses:
|
180
162
|
- MIT
|
163
|
+
metadata: {}
|
181
164
|
post_install_message:
|
182
165
|
rdoc_options: []
|
183
166
|
require_paths:
|
184
167
|
- lib
|
185
168
|
required_ruby_version: !ruby/object:Gem::Requirement
|
186
|
-
none: false
|
187
169
|
requirements:
|
188
|
-
- -
|
170
|
+
- - '>='
|
189
171
|
- !ruby/object:Gem::Version
|
190
172
|
version: '0'
|
191
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
|
-
none: false
|
193
174
|
requirements:
|
194
|
-
- -
|
175
|
+
- - '>='
|
195
176
|
- !ruby/object:Gem::Version
|
196
177
|
version: '0'
|
197
178
|
requirements: []
|
198
179
|
rubyforge_project:
|
199
|
-
rubygems_version:
|
180
|
+
rubygems_version: 2.0.3
|
200
181
|
signing_key:
|
201
|
-
specification_version:
|
182
|
+
specification_version: 4
|
202
183
|
summary: This gem provides support for Ruby and Ruby on Rails for the Raygun.io error
|
203
184
|
reporter
|
204
185
|
test_files: []
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Raygun
|
2
|
-
class RackExceptionInterceptor
|
3
|
-
|
4
|
-
def initialize(app)
|
5
|
-
@app = app
|
6
|
-
end
|
7
|
-
|
8
|
-
def call(env)
|
9
|
-
response = @app.call(env)
|
10
|
-
rescue Exception => exception
|
11
|
-
Raygun.track_exception(exception, env)
|
12
|
-
raise exception
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|