sentry-raven 0.11.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sentry-raven might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 183f7bb0f9258b5240479894362ea94c69874fd9
4
- data.tar.gz: 146ab626134eccee42463bde492a45a47ade0e17
3
+ metadata.gz: 5fbeb1ae8141697af3bf06f4c2167f97af8a7e58
4
+ data.tar.gz: 3431f08512c915bce224d07fb8ad77d5f04fe62a
5
5
  SHA512:
6
- metadata.gz: 712128a1d219122988b9f1a6891fdb3de5d7d3a43885020c0f4f0bd2105b677200015dc222909e078d99168968f8cbca96a4138ef286f6614d249b6471ab3888
7
- data.tar.gz: d34a51caadd2fdec5126a71ff987a8a07c7d501410b5cea1b957dc409b0b056d4013d43c1bbf135c1346fa3ababaae88fc1a6278ae2de9c3bbcf9c788078b57b
6
+ metadata.gz: 869b6bb29a4a351c8694de220ea6513bafea70554488fd1086b3fcced14510cae903621e37c9f86dedab1e12d40da51fb73c138a12a9b460afddba1485f7fd71
7
+ data.tar.gz: ef80ba9d906d81621e4add41b76368ee2549c7bbef3053bf9c280f10b8c3808a1cff39019bc20b01d70201f37bdf28585f65f977dcd76d1f9fc0863d005d26cb
data/README.md CHANGED
@@ -10,60 +10,32 @@ A client and integration layer for the [Sentry](https://github.com/getsentry/sen
10
10
 
11
11
  We test on Ruby MRI 1.8.7/REE, 1.9.3, 2.0 and 2.1. JRuby support is experimental - check TravisCI to see if the build is passing or failing.
12
12
 
13
- ## Installation
14
-
13
+ ## Getting Started
14
+ ### Install
15
15
  ```ruby
16
16
  gem "sentry-raven", :require => 'raven' #, :github => "getsentry/raven-ruby"
17
17
  ```
18
-
19
- ## Usage
20
-
21
- Set the ``SENTRY_DSN`` environment variable with the value found on your Sentry project settings page. It should resemble something like ```https://public:secret@app.getsentry.com/9999```.
22
-
23
- Many implementations will automatically capture uncaught exceptions (such as Rails, Sidekiq or by using
24
- the Rack middleware). If you catch those exceptions yourself, but still want to report on them, see section [Capturing Events](#capturing-events).
25
-
26
- ### Rails
27
-
28
- In Rails, all uncaught exceptions will be automatically reported.
29
-
30
- You'll still want to ensure you've disabled anything that would prevent errors from being propagated to the ```Raven::Rack``` middleware, like ```ActionDispatch::ShowExceptions```:
31
-
18
+ ### Set SENTRY_DSN
19
+ ```bash
20
+ # Set your SENTRY_DSN environment variable.
21
+ export SENTRY_DSN=http://public:secret@example.com/project-id
22
+ ```
32
23
  ```ruby
33
- config.action_dispatch.show_exceptions = false # this is the default setting in production
24
+ # Or you can configure the client in the code (not recommended - keep your DSN secret!)
25
+ Raven.configure do |config|
26
+ config.dsn = 'http://public:secret@example.com/project-id'
27
+ end
34
28
  ```
29
+ ### Call
30
+ If you use Rails, you're already done - no more configuration required! Check [Integrations](https://github.com/getsentry/raven-ruby/wiki/Integrations) for more details on other gems Sentry integrates with automatically.
35
31
 
36
- ### Rack
37
-
38
- Add ```use Raven::Rack``` to your ```config.ru``` or other rackup file (this is automatically inserted in Rails).
39
-
40
- ### Sinatra
41
-
42
- Like any other Rack middleware, add ```use Raven::Rack``` to your Sinatra app.
43
-
44
- ### Sidekiq, Delayed::Job and Rake
45
-
46
- Raven works out-of-the-box with all these tools!
47
-
48
- ## Capturing Events
49
-
50
- Many implementations will automatically capture uncaught exceptions (such as Rails, Sidekiq or by using
51
- the Rack middleware). Sometimes you may want to catch those exceptions, but still report on them.
52
-
53
- Several helpers are available to assist with this.
54
-
55
- ### Capture Exceptions in a Block
56
-
32
+ Otherwise, Raven supports two methods of capturing exceptions:
57
33
  ```ruby
58
34
  Raven.capture do
59
35
  # capture any exceptions which happen during execution of this block
60
36
  1 / 0
61
37
  end
62
- ```
63
-
64
- ### Capture an Exception by Value
65
38
 
66
- ```ruby
67
39
  begin
68
40
  1 / 0
69
41
  rescue ZeroDivisionError => exception
@@ -71,285 +43,11 @@ rescue ZeroDivisionError => exception
71
43
  end
72
44
  ```
73
45
 
74
- ### Additional Context
75
-
76
- Additional context can be passed to the capture methods.
77
-
78
- ```ruby
79
- Raven.capture_message "My event",
80
- logger: 'logger',
81
- extra: {
82
- my_custom_variable: 'value'
83
- },
84
- tags: {
85
- environment: 'production'
86
- }
87
- ```
88
-
89
- The following attributes are available:
90
-
91
- * `logger`: the logger name to record this event under
92
- * `level`: a string representing the level of this event (fatal, error, warning, info, debug)
93
- * `server_name`: the hostname of the server
94
- * `tags`: a mapping of [tags](https://www.getsentry.com/docs/tags/) describing this event
95
- * `extra`: a mapping of arbitrary context
96
-
97
- ## Providing Request Context
98
-
99
- Most of the time you're not actually calling out to Raven directly, but you still want to provide some additional context. This lifecycle generally constists of something like the following:
100
-
101
- - Set some context via a middleware (e.g. the logged in user)
102
- - Send all given context with any events during the request lifecycle
103
- - Cleanup context
104
-
105
- There are three primary methods for providing request context:
106
-
107
- ```ruby
108
- # bind the logged in user
109
- Raven.user_context email: 'foo@example.com'
110
-
111
- # tag the request with something interesting
112
- Raven.tags_context interesting: 'yes'
113
-
114
- # provide a bit of additional context
115
- Raven.extra_context happiness: 'very'
116
- ```
117
-
118
- Additionally, if you're using Rack (without the middleware), you can easily provide context with the ``rack_context`` helper:
119
-
120
- ```ruby
121
- Raven.rack_context(env)
122
- ```
123
-
124
- If you're using the Rack middleware, we've already taken care of cleanup for you, otherwise you'll need to ensure you perform it manually:
125
-
126
- ```ruby
127
- Raven::Context.clear!
128
- ```
129
-
130
- Note: the rack and user context will perform a set operation, whereas tags and extra context will merge with any existing request context.
131
-
132
- ### Authlogic
133
-
134
- When using Authlogic for authentication, you can provide user context by binding to session ```after_persisting``` and ```after_destroy``` events in ```user_session.rb```:
135
-
136
- ```ruby
137
- class UserSession < Authlogic::Session::Base
138
- # events binding
139
- after_persisting :raven_set_user_context
140
- after_destroy :raven_clear_user_context
141
-
142
- def raven_set_user_context
143
- Raven.user_context( { 'id' => self.user.id, 'email' => self.user.email, 'username' => self.user.username } )
144
- end
145
-
146
- def raven_clear_user_context
147
- Raven.user_context({})
148
- end
149
- end
150
- ```
151
-
152
- ## Configuration
153
-
154
- ### SENTRY_DSN
155
-
156
- After you complete setting up a project, you'll be given a value which we call a DSN, or Data Source Name. It looks a lot like a standard URL, but it's actually just a representation of the configuration required by Raven (the Sentry client). It consists of a few pieces, including the protocol, public and secret keys, the server address, and the project identifier.
157
-
158
- With Raven, you may either set the ```SENTRY_DSN``` environment variable (recommended), or set your DSN manually in a config block:
159
-
160
- ```ruby
161
- # in Rails, this might be in config/initializers/sentry.rb
162
- Raven.configure do |config|
163
- config.dsn = 'http://public:secret@example.com/project-id'
164
- end
165
- ```
166
-
167
- ### Environments
168
-
169
- As of [v0.10.0](https://github.com/getsentry/raven-ruby/blob/21cb3164e0d0ab91394ba98b78195c4f6342b4bb/changelog.md#0100), events will be sent to Sentry in all environments. If you do not wish
170
- to send events in an environment, we suggest you unset the ```SENTRY_DSN```
171
- variable in that environment.
172
-
173
- Alternately, you can configure Raven to run only in certain environments by configuring the `environments` whitelist. For example, to only run Sentry in production:
174
-
175
- ```ruby
176
- Raven.configure do |config|
177
- config.environments = %w[ production ]
178
- end
179
- ```
180
-
181
- Sentry automatically sets the current environment to ```RAILS_ENV```, or if it is not present, ```RACK_ENV```. If you are using Sentry outside of Rack or Rails, you'll need to set the current environment yourself:
182
-
183
- ```ruby
184
- Raven.configure do |config|
185
- config.current_environment = 'my_cool_environment'
186
- end
187
- ```
188
-
189
- ### Excluding Exceptions
190
-
191
- If you never wish to be notified of certain exceptions, specify 'excluded_exceptions' in your config file.
192
-
193
- In the example below, the exceptions Rails uses to generate 404 responses will be suppressed.
194
-
195
- ```ruby
196
- Raven.configure do |config|
197
- config.excluded_exceptions = ['ActionController::RoutingError', 'ActiveRecord::RecordNotFound']
198
- end
199
- ```
200
-
201
- You can find the list of exceptions that are excluded by default in [Raven::Configuration::IGNORE_DEFAULT](https://github.com/getsentry/raven-ruby/blob/master/lib/raven/configuration.rb). Remember you'll be overriding those defaults by setting this configuration.
202
-
203
- You can also use a configuration option to determine if an individual event should
204
- be sent to Sentry. Events are passed to the Proc or lambda you provide - returning
205
- `false` will stop the event from sending to Sentry:
206
-
207
- ```ruby
208
- Raven.configure do |config|
209
- config.should_send = Proc.new { |e| true unless e.contains_sensitive_info? }
210
- end
211
- ```
212
-
213
- ### Tags
214
-
215
- You can configure default tags to be sent with every event. These can be
216
- overridden in the context or event.
217
-
218
- ```ruby
219
- Raven.configure do |config|
220
- config.tags = { environment: Rails.env }
221
- end
222
- ```
223
-
224
- ### SSL Verification
225
-
226
- By default SSL certificate verification is **disabled** in the client. This choice
227
- was made due to root CAs not being commonly available on systems. If you'd like
228
- to change this, you can enable verification by passing the ``ssl_verification``
229
- flag:
230
-
231
- ```ruby
232
- Raven.configure do |config|
233
- config.ssl_verification = true
234
- end
235
- ```
236
-
237
- ### Asynchronous Delivery
238
-
239
- When an error occurs, the notification is immediately sent to Sentry. Raven can be configured
240
- to send notifications asynchronously:
241
-
242
- ```ruby
243
- Raven.configure do |config|
244
- config.async = lambda { |event|
245
- Thread.new { Raven.send(event) }
246
- }
247
- end
248
- ```
249
-
250
- This example uses a thread, but other tools can be used (GirlFriday, Resque, Sidekiq, etc...) as
251
- long as the `event` argument is eventually passed to `Raven.send`.
252
-
253
- ### Logging
254
-
255
- You can use any logger with Raven - just set config.logger. Raven respects logger
256
- levels.
257
-
258
- ```ruby
259
- logger = ::Logger.new(STDOUT)
260
- logger.level = ::Logger::WARN
261
-
262
- Raven.configure do |config|
263
- config.logger = logger
264
- end
265
- ```
266
-
267
- If you are using Rails, Raven will default to using Rails.logger as the logger.
268
-
269
- ### Encoding
270
-
271
- While unlikely that you'll need to change it, by default Raven compresses outgoing messages with gzip. This has a slight impact on performance, but due to the size of many Ruby stacktrace it's required for the serve to accept the content.
272
-
273
- To disable gzip, set the encoding to 'json':
274
-
275
- ```ruby
276
- Raven.configure do |config|
277
- config.encoding = 'json'
278
- end
279
- ```
280
-
281
- ### Silencing the ready message
282
-
283
- Upon start, Raven will write the following message to the log at the INFO level:
284
-
285
- ** [out :: hostname.example.com] I, [2014-07-22T15:32:57.498368 #30897] INFO -- : ** [Raven] Raven 0.9.4 ready to catch errors"
286
-
287
- You can turn off this message by passing `true` to `Raven.configure`
288
-
289
- ```ruby
290
- Raven.configure(true) do |config|
291
- ...
292
- end
293
- ```
294
-
295
-
296
- ## Sanitizing Data (Processors)
297
-
298
- If you need to sanitize or pre-process (before its sent to the server) data, you can do so using the Processors
299
- implementation. By default, a single processor is installed (Raven::Processor::SanitizeData), which will attempt to
300
- sanitize keys that match various patterns (e.g. password) and values that resemble credit card numbers.
301
-
302
- To specify your own (or to remove the defaults), simply pass them with your configuration:
303
-
304
- ```ruby
305
- Raven.configure do |config|
306
- config.processors = [Raven::Processor::SanitizeData]
307
- end
308
- ```
309
-
310
- ## Testing Your Configuration
311
-
312
- To ensure you've setup your configuration correctly we recommend running the
313
- included rake task::
314
-
315
- ```bash
316
- $ rake raven:test[https://public:secret@app.getsentry.com/3825]
317
- Client configuration:
318
- -> server: https://app.getsentry.com
319
- -> project_id: 3825
320
- -> public_key: public
321
- -> secret_key: secret
322
-
323
- Sending a test event:
324
- -> event ID: 033c343c852b45c2a3add98e425ea4b4
325
-
326
- Done!
327
- ```
328
-
329
- A couple of things to note:
330
-
331
- * This won't test your environment configuration. The test CLI forces your
332
- configuration to represent itself as if it were running in the production env.
333
- * If you're running within Rails (or anywhere else that will bootstrap the
334
- rake environment), you should be able to omit the DSN argument.
335
-
336
- ## Contributing
337
-
338
- ### Bootstrap
339
-
340
- ```bash
341
- $ bundle install
342
- ```
343
-
344
- ### Running the test suite
345
-
346
- ```bash
347
- $ rake spec
348
- ```
46
+ ## More Information
349
47
 
350
- Resources
351
- ---------
48
+ Full documentation and more information on advanced configuration, sending more information, scrubbing sensitive data, and more can be found on [the wiki](https://github.com/getsentry/raven-ruby/wiki).
352
49
 
50
+ * [Documentation](https://github.com/getsentry/raven-ruby/wiki)
353
51
  * [Bug Tracker](http://github.com/getsentry/raven-ruby/issues>)
354
52
  * [Code](http://github.com/getsentry/raven-ruby>)
355
53
  * [Mailing List](https://groups.google.com/group/getsentry>)
@@ -83,6 +83,9 @@ module Raven
83
83
  # Provide a configurable callback to block or send events
84
84
  attr_accessor :should_send
85
85
 
86
+ # additional fields to sanitize
87
+ attr_accessor :sanitize_fields
88
+
86
89
  IGNORE_DEFAULT = ['ActiveRecord::RecordNotFound',
87
90
  'ActionController::RoutingError',
88
91
  'ActionController::InvalidAuthenticityToken',
@@ -105,6 +108,7 @@ module Raven
105
108
  self.tags = {}
106
109
  self.async = false
107
110
  self.catch_debugged_exceptions = true
111
+ self.sanitize_fields = []
108
112
  end
109
113
 
110
114
  def server=(value)
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'socket'
3
- require 'uuidtools'
3
+ require 'securerandom'
4
4
 
5
5
  require 'raven/error'
6
6
  require 'raven/linecache'
@@ -32,7 +32,7 @@ module Raven
32
32
 
33
33
  context = options[:context] || Raven.context
34
34
 
35
- @id = options[:id] || UUIDTools::UUID.random_create.hexdigest
35
+ @id = options[:id] || generate_event_id
36
36
  @message = options[:message]
37
37
  @timestamp = options[:timestamp] || Time.now.utc
38
38
  @time_spent = options[:time_spent]
@@ -207,5 +207,17 @@ module Raven
207
207
  alias :capture_exception :from_exception
208
208
  alias :capture_message :from_message
209
209
  end
210
+
211
+ private
212
+
213
+ def generate_event_id
214
+ # generate a uuid. copy-pasted from SecureRandom, this method is not
215
+ # available in <1.9.
216
+ ary = SecureRandom.random_bytes(16).unpack("NnnnnN")
217
+ ary[2] = (ary[2] & 0x0fff) | 0x4000
218
+ ary[3] = (ary[3] & 0x3fff) | 0x8000
219
+ uuid = "%08x-%04x-%04x-%04x-%04x%08x" % ary
220
+ Digest::MD5.hexdigest(uuid)
221
+ end
210
222
  end
211
223
  end
@@ -2,8 +2,11 @@ require 'json'
2
2
 
3
3
  module Raven
4
4
  class Processor
5
+ attr_accessor :sanitize_fields
6
+
5
7
  def initialize(client)
6
8
  @client = client
9
+ @sanitize_fields = client.configuration.sanitize_fields
7
10
  end
8
11
 
9
12
  def process(data)
@@ -0,0 +1,11 @@
1
+ module Raven
2
+ class Processor::RemoveStacktrace < Processor
3
+
4
+ def process(value)
5
+ value['exception'].delete('stacktrace') if value['exception']
6
+
7
+ value
8
+ end
9
+
10
+ end
11
+ end
@@ -2,10 +2,12 @@ module Raven
2
2
  class Processor::SanitizeData < Processor
3
3
  STRING_MASK = '********'
4
4
  INT_MASK = 0
5
- FIELDS_RE = /(authorization|password|passwd|secret|ssn|social(.*)?sec)/i
5
+ DEFAULT_FIELDS = %w(authorization password passwd secret ssn social(.*)?sec)
6
6
  VALUES_RE = /^\d{16}$/
7
7
 
8
8
  def process(value)
9
+ fields_re = /(#{(DEFAULT_FIELDS + @sanitize_fields).join("|")})/i
10
+
9
11
  value.inject(value) do |value,(k,v)|
10
12
  v = k if v.nil?
11
13
  if v.is_a?(Hash) || v.is_a?(Array)
@@ -13,9 +15,9 @@ module Raven
13
15
  elsif v.is_a?(String) && (json = parse_json_or_nil(v))
14
16
  #if this string is actually a json obj, convert and sanitize
15
17
  value = modify_in_place(value, [k,v], process(json).to_json)
16
- elsif v.is_a?(Integer) && (VALUES_RE.match(v.to_s) || FIELDS_RE.match(k.to_s))
18
+ elsif v.is_a?(Integer) && (VALUES_RE.match(v.to_s) || fields_re.match(k.to_s))
17
19
  value = modify_in_place(value, [k,v], INT_MASK)
18
- elsif VALUES_RE.match(v.to_s) || FIELDS_RE.match(k.to_s)
20
+ elsif VALUES_RE.match(v.to_s) || fields_re.match(k.to_s)
19
21
  value = modify_in_place(value, [k,v], STRING_MASK)
20
22
  else
21
23
  value
@@ -1,3 +1,3 @@
1
1
  module Raven
2
- VERSION = "0.11.2"
2
+ VERSION = "0.12.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-raven
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2014-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.7.6
27
- - !ruby/object:Gem::Dependency
28
- name: uuidtools
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +94,7 @@ dependencies:
108
94
  - - ">="
109
95
  - !ruby/object:Gem::Version
110
96
  version: '0'
111
- description:
97
+ description: A gem that provides a client interface for the Sentry error logger
112
98
  email: getsentry@googlegroups.com
113
99
  executables:
114
100
  - raven
@@ -141,6 +127,7 @@ files:
141
127
  - lib/raven/okjson.rb
142
128
  - lib/raven/processor.rb
143
129
  - lib/raven/processor/removecircularreferences.rb
130
+ - lib/raven/processor/removestacktrace.rb
144
131
  - lib/raven/processor/sanitizedata.rb
145
132
  - lib/raven/processor/utf8conversion.rb
146
133
  - lib/raven/rack.rb