sentry-raven 0.4.5 → 0.4.6

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.

data/README.md CHANGED
@@ -1,92 +1,54 @@
1
1
  # Raven-Ruby
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/getsentry/raven-ruby.png?branch=master)](http://travis-ci.org/getsentry/raven-ruby)
3
+ [![Gem Version](https://badge.fury.io/rb/sentry-raven.png)](http://badge.fury.io/rb/sentry-raven) [![Build Status](https://secure.travis-ci.org/getsentry/raven-ruby.png?branch=master)](http://travis-ci.org/getsentry/raven-ruby) [![Coverage Status](https://coveralls.io/repos/getsentry/raven-ruby/badge.png?branch=master)](https://coveralls.io/r/getsentry/raven-ruby)
4
4
 
5
5
  A client and integration layer for the [Sentry](https://github.com/getsentry/sentry) error reporting API.
6
6
 
7
- This library is still forming, so if you are looking to just use it, please check back in a few weeks.
7
+ ## Requirements
8
8
 
9
- ## Installation
9
+ We test on Ruby MRI 1.8.7, 1.9.2, 1.9.3 and 2.0.0. Other versions/VMs are untested but we will accept pull requests to support them.
10
10
 
11
- Add the following to your `Gemfile`:
11
+ ## Installation
12
12
 
13
13
  ```ruby
14
- gem "sentry-raven", :git => "https://github.com/getsentry/raven-ruby.git"
15
- ```
16
-
17
- Or install manually
18
- ```bash
19
- $ gem install sentry-raven
14
+ gem "sentry-raven" #, :github => "getsentry/raven-ruby"
20
15
  ```
21
16
 
22
17
  ## Usage
23
18
 
19
+ You'll want to set your ```SENTRY_DSN``` environment variable to the URL on your project's API Keys setting page (e.g. ```https://secret:public@app.getsentry.com/9999```). For more information, see [Configuration](#configuration).
20
+
24
21
  ### Rails 3
25
22
 
26
- Add a `config/initializers/raven.rb` containing:
23
+ In Rails 3, Sentry will "just work," capturing any exceptions thrown in your app. All Rails integrations also
24
+ have mixed-in methods for capturing exceptions you've rescued yourself inside of controllers:
27
25
 
28
26
  ```ruby
29
- require 'raven'
30
-
31
- Raven.configure do |config|
32
- config.dsn = 'http://public:secret@example.com/project-id'
33
- end
27
+ # ...
28
+ rescue => exception
29
+ capture_exception(exception) # or capture_message('Flux overload')
30
+ flash[:error] = 'Your flux capacitor is overloaded!'
31
+ end
34
32
  ```
35
33
 
36
34
  ### Rails 2
37
35
 
38
- No support for Rails 2 yet.
36
+ No support for Rails 2 yet, but it is being worked on.
39
37
 
40
38
  ### Rack
41
39
 
42
- Basic RackUp file.
43
-
44
- ```ruby
45
- require 'raven'
46
-
47
- Raven.configure do |config|
48
- config.dsn = 'http://public:secret@example.com/project-id'
49
- end
50
-
51
- use Raven::Rack
52
- ```
40
+ Add ```use Raven::Rack``` to your ```config.ru``` (or other rackup file).
53
41
 
54
42
  ### Sinatra
55
43
 
56
- ```ruby
57
- require 'sinatra'
58
- require 'raven'
59
-
60
- Raven.configure do |config|
61
- config.dsn = 'http://public:secret@example.com/project-id'
62
- end
63
-
64
- use Raven::Rack
65
-
66
- get '/' do
67
- 1 / 0
68
- end
69
- ```
70
-
71
- ### Other Ruby
72
-
73
- ```ruby
74
- require 'raven'
75
-
76
- Raven.configure do |config|
77
- config.dsn = 'http://public:secret@example.com/project-id'
78
-
79
- # manually configure environment if ENV['RACK_ENV'] is not defined
80
- config.current_environment = 'production'
81
- end
82
- ```
44
+ Like any other Rack middleware, add ```use Raven::Rack``` to your Sinatra app.
83
45
 
84
46
  ## Capturing Events
85
47
 
86
48
  Many implementations will automatically capture uncaught exceptions (such as Rails, Sidekiq or by using
87
49
  the Rack middleware). Sometimes you may want to catch those exceptions, but still report on them.
88
50
 
89
- Several helps are available to assist with this.
51
+ Several helpers are available to assist with this.
90
52
 
91
53
  ### Capture Exceptions in a Block
92
54
 
@@ -128,7 +90,7 @@ The following attributes are available:
128
90
  * `logger`: the logger name to record this event under
129
91
  * `level`: a string representing the level of this event (fatal, error, warning, info, debug)
130
92
  * `server_name`: the hostname of the server
131
- * `tags`: a mapping of tags describing this event
93
+ * `tags`: a mapping of [tags](https://www.getsentry.com/docs/tags/) describing this event
132
94
  * `extra`: a mapping of arbitrary context
133
95
 
134
96
  ## Testing
@@ -138,32 +100,48 @@ $ bundle install
138
100
  $ rake spec
139
101
  ```
140
102
 
141
- ## Notifications in development mode
103
+ ## Configuration
142
104
 
143
- By default events will only be sent to Sentry if your application is running in a production environment. This is configured by default if you are running a Rack application (i.e. anytime `ENV['RACK_ENV']` is set).
105
+ ### SENTRY_DSN
144
106
 
145
- You can configure Raven to run in non-production environments by configuring the `environments` whitelist:
107
+ 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.
146
108
 
147
- ```ruby
148
- require 'raven'
109
+ With Raven, you may either set the ```SENTRY_DSN``` environment variable (recommended), or set your DSN manually in a config block:
149
110
 
111
+ ```ruby
150
112
  Raven.configure do |config|
151
113
  config.dsn = 'http://public:secret@example.com/project-id'
152
- config.environments = %w[ development production ]
153
114
  end
154
115
  ```
155
116
 
156
- ## Excluding Exceptions
117
+ ### Environments
118
+
119
+ By default events will be sent to Sentry in all environments except 'test', 'development', and 'cucumber'.
120
+
121
+ You can configure Raven to run only in certain environments by configuring the `environments` whitelist. For example, to only run Sentry in production:
122
+
123
+ ```ruby
124
+ Raven.configure do |config|
125
+ config.environments = %w[ production ]
126
+ end
127
+ ```
128
+
129
+ 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:
130
+
131
+ ```ruby
132
+ Raven.configure do |config|
133
+ config.current_environment = 'my_cool_environment'
134
+ end
135
+ ```
136
+
137
+ ### Excluding Exceptions
157
138
 
158
139
  If you never wish to be notified of certain exceptions, specify 'excluded_exceptions' in your config file.
159
140
 
160
141
  In the example below, the exceptions Rails uses to generate 404 responses will be suppressed.
161
142
 
162
143
  ```ruby
163
- require 'raven'
164
-
165
144
  Raven.configure do |config|
166
- config.dsn = 'http://public:secret@example.com/project-id'
167
145
  config.excluded_exceptions = ['ActionController::RoutingError', 'ActiveRecord::RecordNotFound']
168
146
  end
169
147
  ```
@@ -177,10 +155,7 @@ sanitize keys that match various patterns (e.g. password) and values that resemb
177
155
  To specify your own (or to remove the defaults), simply pass them with your configuration:
178
156
 
179
157
  ```ruby
180
- require 'raven'
181
-
182
158
  Raven.configure do |config|
183
- config.dsn = 'http://public:secret@example.com/project-id'
184
159
  config.processors = [Raven::Processor::SanitizeData]
185
160
  end
186
161
  ```
data/lib/raven.rb CHANGED
@@ -104,13 +104,17 @@ module Raven
104
104
  end
105
105
 
106
106
  def capture_exception(exception, options={})
107
- evt = Event.capture_exception(exception, options)
108
- send(evt) if evt
107
+ if evt = Event.capture_exception(exception, options)
108
+ yield evt if block_given?
109
+ send(evt)
110
+ end
109
111
  end
110
112
 
111
113
  def capture_message(message, options={})
112
- evt = Event.capture_message(message, options)
113
- send(evt) if evt
114
+ if evt = Event.capture_message(message, options)
115
+ yield evt if block_given?
116
+ send(evt)
117
+ end
114
118
  end
115
119
 
116
120
  # Bind user context. Merges with existing context (if any).
data/lib/raven/client.rb CHANGED
@@ -33,7 +33,7 @@ module Raven
33
33
  transport.send(generate_auth_header(encoded_data), encoded_data,
34
34
  :content_type => content_type)
35
35
  rescue
36
- logger.error "Unable to record event with remote Sentry server"
36
+ Raven.logger.error "Unable to record event with remote Sentry server"
37
37
  end
38
38
  end
39
39
 
@@ -70,8 +70,7 @@ module Raven
70
70
  def initialize
71
71
  self.server = ENV['SENTRY_DSN'] if ENV['SENTRY_DSN']
72
72
  @context_lines = 3
73
- self.environments = %w[ production ]
74
- self.current_environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
73
+ self.current_environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
75
74
  self.send_modules = true
76
75
  self.excluded_exceptions = IGNORE_DEFAULT
77
76
  self.processors = [Raven::Processor::SanitizeData]
@@ -122,7 +121,11 @@ module Raven
122
121
  end
123
122
 
124
123
  def send_in_current_environment?
125
- environments.include? current_environment
124
+ if environments
125
+ environments.include?(current_environment)
126
+ else
127
+ !%w[test cucumber development].include?(current_environment)
128
+ end
126
129
  end
127
130
 
128
131
  end
data/lib/raven/event.rb CHANGED
@@ -150,15 +150,6 @@ module Raven
150
150
  end
151
151
  end
152
152
 
153
- def self.capture_rack_exception(exc, rack_env, options={}, &block)
154
- capture_exception(exc, options) do |evt|
155
- evt.interface :http do |int|
156
- int.from_rack(rack_env)
157
- end
158
- block.call(evt) if block
159
- end
160
- end
161
-
162
153
  def self.capture_message(message, options={})
163
154
  new(options) do |evt|
164
155
  evt.message = message
data/lib/raven/rack.rb CHANGED
@@ -18,6 +18,22 @@ module Raven
18
18
  #
19
19
  # Use a standard Raven.configure call to configure your server credentials.
20
20
  class Rack
21
+ def self.capture_exception(exception, env, options = {})
22
+ Raven.capture_exception(exception, options) do |evt|
23
+ evt.interface :http do |int|
24
+ int.from_rack(env)
25
+ end
26
+ end
27
+ end
28
+
29
+ def self.capture_message(message, env, options = {})
30
+ Raven.capture_message(message, options) do |evt|
31
+ evt.interface :http do |int|
32
+ int.from_rack(env)
33
+ end
34
+ end
35
+ end
36
+
21
37
  def initialize(app)
22
38
  @app = app
23
39
  end
@@ -28,8 +44,7 @@ module Raven
28
44
  rescue Error => e
29
45
  raise # Don't capture Raven errors
30
46
  rescue Exception => e
31
- evt = Event.capture_rack_exception(e, env)
32
- Raven.send(evt)
47
+ Raven::Rack.capture_exception(e, env)
33
48
  raise
34
49
  ensure
35
50
  Context.clear!
@@ -38,8 +53,7 @@ module Raven
38
53
  error = env['rack.exception'] || env['sinatra.error']
39
54
 
40
55
  if error
41
- evt = Event.capture_rack_exception(error, env)
42
- Raven.send(evt) if evt
56
+ Raven::Rack.capture_exception(error, env)
43
57
  end
44
58
 
45
59
  response
@@ -0,0 +1,13 @@
1
+ module Raven
2
+ module Rails
3
+ module ControllerMethods
4
+ def capture_message(message, options = {})
5
+ Raven::Rack.capture_message(message, request.env, options)
6
+ end
7
+
8
+ def capture_exception(exception, options = {})
9
+ Raven::Rack.capture_exception(exception, request.env, options)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -7,8 +7,7 @@ module Raven
7
7
  end
8
8
 
9
9
  def render_exception_with_raven(env, exception)
10
- evt = Raven::Event.capture_rack_exception(exception, env)
11
- Raven.send(evt) if evt
10
+ Raven::Rack.capture_exception(exception, env)
12
11
  render_exception_without_raven(env, exception)
13
12
  end
14
13
  end
data/lib/raven/railtie.rb CHANGED
@@ -7,6 +7,13 @@ module Raven
7
7
  app.config.middleware.insert 0, "Raven::Rack"
8
8
  end
9
9
 
10
+ initializer 'raven.action_controller' do
11
+ ActiveSupport.on_load :action_controller do
12
+ require 'raven/rails/controller_methods'
13
+ include Raven::Rails::ControllerMethods
14
+ end
15
+ end
16
+
10
17
  config.after_initialize do
11
18
  Raven.configure(true) do |config|
12
19
  config.logger ||= ::Rails.logger
@@ -23,3 +30,4 @@ module Raven
23
30
  end
24
31
  end
25
32
  end
33
+
@@ -10,7 +10,8 @@ module Raven
10
10
  class HTTP < Transport
11
11
 
12
12
  def send(auth_header, data, options = {})
13
- response = conn.post '/api/store/' do |req|
13
+ project_id = self.configuration[:project_id]
14
+ response = conn.post "/api/#{project_id}/store/" do |req|
14
15
  req.headers['Content-Type'] = options[:content_type]
15
16
  req.headers['X-Sentry-Auth'] = auth_header
16
17
  req.body = data
data/lib/raven/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Raven
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-raven
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-18 00:00:00.000000000 Z
13
+ date: 2013-04-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
17
- requirement: &70093744928500 !ruby/object:Gem::Requirement
17
+ requirement: &70157840148660 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.7.6
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70093744928500
25
+ version_requirements: *70157840148660
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: uuidtools
28
- requirement: &70093744926620 !ruby/object:Gem::Requirement
28
+ requirement: &70157840148260 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70093744926620
36
+ version_requirements: *70157840148260
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: multi_json
39
- requirement: &70093744923680 !ruby/object:Gem::Requirement
39
+ requirement: &70157840147720 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '1.0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70093744923680
47
+ version_requirements: *70157840147720
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: hashie
50
- requirement: &70093744938880 !ruby/object:Gem::Requirement
50
+ requirement: &70157840147300 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,51 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *70093744938880
58
+ version_requirements: *70157840147300
59
+ - !ruby/object:Gem::Dependency
60
+ name: rake
61
+ requirement: &70157840163200 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *70157840163200
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: &70157840162700 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.10'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *70157840162700
81
+ - !ruby/object:Gem::Dependency
82
+ name: simplecov
83
+ requirement: &70157840162260 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *70157840162260
92
+ - !ruby/object:Gem::Dependency
93
+ name: coveralls
94
+ requirement: &70157840161800 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *70157840161800
59
103
  description:
60
104
  email: noah@coderanger.net
61
105
  executables:
@@ -81,6 +125,7 @@ files:
81
125
  - lib/raven/processor.rb
82
126
  - lib/raven/processors/sanitizedata.rb
83
127
  - lib/raven/rack.rb
128
+ - lib/raven/rails/controller_methods.rb
84
129
  - lib/raven/rails/middleware/debug_exceptions_catcher.rb
85
130
  - lib/raven/railtie.rb
86
131
  - lib/raven/sidekiq.rb