You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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```:
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
rescueZeroDivisionError => exception
70
42
Raven.capture_exception(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```:
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
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.
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:
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:
* 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).
0 commit comments