Skip to content

Commit 7b0578a

Browse files
committed
Slim down README, transfer documentation to Github Wiki
1 parent 39895a6 commit 7b0578a

File tree

1 file changed

+17
-319
lines changed

1 file changed

+17
-319
lines changed

README.md

Lines changed: 17 additions & 319 deletions
Original file line numberDiff line numberDiff line change
@@ -10,346 +10,44 @@ A client and integration layer for the [Sentry](https://github.com/getsentry/sen
1010

1111
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.
1212

13-
## Installation
14-
13+
## Getting Started
14+
### Install
1515
```ruby
1616
gem "sentry-raven", :require => 'raven' #, :github => "getsentry/raven-ruby"
1717
```
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+
```
3223
```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
3428
```
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.
3531

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:
5733
```ruby
5834
Raven.capture do
5935
# capture any exceptions which happen during execution of this block
6036
1 / 0
6137
end
62-
```
63-
64-
### Capture an Exception by Value
6538

66-
```ruby
6739
begin
6840
1 / 0
6941
rescue ZeroDivisionError => exception
7042
Raven.capture_exception(exception)
7143
end
7244
```
7345

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
34947

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).
35249

50+
* [Documentation](https://github.com/getsentry/raven-ruby/wiki)
35351
* [Bug Tracker](http://github.com/getsentry/raven-ruby/issues>)
35452
* [Code](http://github.com/getsentry/raven-ruby>)
35553
* [Mailing List](https://groups.google.com/group/getsentry>)

0 commit comments

Comments
 (0)