sentry-raven 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

data/README.md CHANGED
@@ -6,7 +6,7 @@ A client and integration layer for the [Sentry](https://github.com/getsentry/sen
6
6
 
7
7
  ## Requirements
8
8
 
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.
9
+ We test on Ruby MRI 1.8.7, 1.9.3 and 2.0.0. Rubinius and JRuby support is experimental.
10
10
 
11
11
  ## Installation
12
12
 
@@ -41,12 +41,24 @@ No support for Rails 2 yet, but it is being worked on.
41
41
 
42
42
  ### Rack
43
43
 
44
- Add ```use Raven::Rack``` to your ```config.ru``` (or other rackup file).
44
+ Add ```use Raven::Rack``` to your ```config.ru``` (or other rackup file).
45
45
 
46
46
  ### Sinatra
47
47
 
48
48
  Like any other Rack middleware, add ```use Raven::Rack``` to your Sinatra app.
49
49
 
50
+ ### Sidekiq
51
+
52
+ Raven includes [Sidekiq middleware](https://github.com/mperham/sidekiq/wiki/Middleware) which takes
53
+ care of reporting errors that occur in Sidekiq jobs. To use it, just require the middleware by doing
54
+
55
+ ```ruby
56
+ require 'raven/sidekiq'
57
+ ```
58
+ after you require Sidekiq. If you are using Sidekiq with Rails, just put this
59
+ require somewhere in the initializers.
60
+
61
+
50
62
  ## Capturing Events
51
63
 
52
64
  Many implementations will automatically capture uncaught exceptions (such as Rails, Sidekiq or by using
@@ -97,6 +109,41 @@ The following attributes are available:
97
109
  * `tags`: a mapping of [tags](https://www.getsentry.com/docs/tags/) describing this event
98
110
  * `extra`: a mapping of arbitrary context
99
111
 
112
+ ## Providing Request Context
113
+
114
+ 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:
115
+
116
+ - Set some context via a middleware (e.g. the logged in user)
117
+ - Send all given context with any events during the request lifecycle
118
+ - Cleanup context
119
+
120
+ There are three primary methods for providing request context:
121
+
122
+ ```ruby
123
+ # bind the logged in user
124
+ Raven.user_context({'email' => 'foo@example.com'})
125
+
126
+ # tag the request with something interesting
127
+ Raven.tags_context({'interesting' => 'yes'})
128
+
129
+ # provide a bit of additional context
130
+ Raven.extra_context({'happiness' => 'very'})
131
+ ```
132
+
133
+ Additionally, if you're using Rack (without the middleware), you can easily provide context with the ``rack_context`` helper:
134
+
135
+ ```ruby
136
+ Raven.rack_context(env)
137
+ ```
138
+
139
+ 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:
140
+
141
+ ```ruby
142
+ Raven.context.clear!
143
+ ```
144
+
145
+ Note: the rack and user context will perform a set operation, whereas tags and extra context will merge with any existing request context.
146
+
100
147
  ## Configuration
101
148
 
102
149
  ### SENTRY_DSN
@@ -168,6 +215,20 @@ Raven.configure do |config|
168
215
  config.ssl_verification = true
169
216
  ```
170
217
 
218
+ ### Logging
219
+
220
+ You can use any logger with Raven - just set config.logger. Raven respects logger
221
+ levels.
222
+
223
+ ```ruby
224
+ logger = ::Logger.new(STDOUT)
225
+ logger.level = ::Logger::WARN
226
+
227
+ Raven.configure do |config|
228
+ config.logger = logger
229
+ end
230
+ ```
231
+
171
232
  ## Sanitizing Data (Processors)
172
233
 
173
234
  If you need to sanitize or pre-process (before its sent to the server) data, you can do so using the Processors
@@ -203,8 +264,8 @@ Done!
203
264
 
204
265
  A couple of things to note:
205
266
 
206
- * This won't test your environment configuration. The test CLI forces the your
207
- coniguration to represent itself as if it were running in the production env.
267
+ * This won't test your environment configuration. The test CLI forces your
268
+ configuration to represent itself as if it were running in the production env.
208
269
  * If you're running within Rails (or anywhere else that will bootstrap the
209
270
  rake environment), you should be able to omit the DSN argument.
210
271
 
data/lib/raven.rb CHANGED
@@ -118,6 +118,32 @@ module Raven
118
118
  end
119
119
  end
120
120
 
121
+ # Provides extra context to the exception prior to it being handled by
122
+ # Raven. An exception can have multiple annotations, which are merged
123
+ # together.
124
+ #
125
+ # The options (annotation) is treated the same as the ``options``
126
+ # parameter to ``capture_exception`` or ``Event.from_exception``, and
127
+ # can contain the same ``:user``, ``:tags``, etc. options as these
128
+ # methods.
129
+ #
130
+ # These will be merged with the ``options`` parameter to
131
+ # ``Event.from_exception`` at the top of execution.
132
+ #
133
+ # @example
134
+ # begin
135
+ # raise "Hello"
136
+ # rescue => exc
137
+ # Raven.annotate_exception(exc, :user => { 'id' => 1,
138
+ # 'email' => 'foo@example.com' })
139
+ # end
140
+ def annotate_exception(exc, options = {})
141
+ notes = exc.instance_variable_get(:@__raven_context) || {}
142
+ notes.merge!(options)
143
+ exc.instance_variable_set(:@__raven_context, notes)
144
+ exc
145
+ end
146
+
121
147
  # Bind user context. Merges with existing context (if any).
122
148
  #
123
149
  # It is recommending that you send at least the ``id`` and ``email``
@@ -126,7 +152,7 @@ module Raven
126
152
  # @example
127
153
  # Raven.user_context('id' => 1, 'email' => 'foo@example.com')
128
154
  def user_context(options={})
129
- self.context.user.merge!(options)
155
+ self.context.user = options
130
156
  end
131
157
 
132
158
  # Bind tags context. Merges with existing context (if any).
@@ -151,11 +177,16 @@ module Raven
151
177
  end
152
178
 
153
179
  def rack_context(env)
180
+ if env.empty?
181
+ env = nil
182
+ end
154
183
  self.context.rack_env = env
155
184
  end
156
185
 
157
186
  # For cross-language compat
158
187
  alias :captureException :capture_exception
159
188
  alias :captureMessage :capture_message
189
+ alias :annotateException :annotate_exception
190
+ alias :annotate :annotate_exception
160
191
  end
161
192
  end
data/lib/raven/client.rb CHANGED
@@ -37,6 +37,7 @@ module Raven
37
37
  :content_type => content_type)
38
38
  rescue => e
39
39
  Raven.logger.error "Unable to record event with remote Sentry server (#{e.class} - #{e.message})"
40
+ e.backtrace[0..10].each { |line| Raven.logger.error(line) }
40
41
  return
41
42
  end
42
43
 
data/lib/raven/context.rb CHANGED
@@ -3,14 +3,14 @@ module Raven
3
3
  def self.current
4
4
  Thread.current[:sentry_context] ||= new
5
5
  end
6
-
6
+
7
7
  def self.clear!
8
8
  Thread.current[:sentry_context] = nil
9
9
  end
10
-
11
- attr_reader :extra, :tags, :user
12
- attr_accessor :rack_env
13
-
10
+
11
+ attr_reader :extra, :tags
12
+ attr_accessor :rack_env, :user
13
+
14
14
  def initialize
15
15
  @extra = {}
16
16
  @tags = {}
data/lib/raven/event.rb CHANGED
@@ -58,9 +58,11 @@ module Raven
58
58
 
59
59
  block.call(self) if block
60
60
 
61
- if !self[:http] && context.rack_env
62
- self.interface :http do |int|
63
- int.from_rack(context.rack_env)
61
+ if @configuration.send_in_current_environment?
62
+ if !self[:http] && context.rack_env
63
+ self.interface :http do |int|
64
+ int.from_rack(context.rack_env)
65
+ end
64
66
  end
65
67
  end
66
68
 
@@ -118,6 +120,9 @@ module Raven
118
120
  end
119
121
 
120
122
  def self.from_exception(exc, options={}, &block)
123
+ notes = exc.instance_variable_get(:@__raven_context) || {}
124
+ options = notes.merge(options)
125
+
121
126
  configuration = options[:configuration] || Raven.configuration
122
127
  if exc.is_a?(Raven::Error)
123
128
  # Try to prevent error reporting loops
@@ -45,7 +45,7 @@ module Raven
45
45
  def filename
46
46
  return nil if self.abs_path.nil?
47
47
 
48
- prefix = $:.select {|s| self.abs_path.start_with?(s.to_s)}.sort_by {|s| s.length}.last
48
+ prefix = $:.select {|s| self.abs_path.start_with?(s.to_s)}.sort_by {|s| s.to_s.length}.last
49
49
  prefix ? self.abs_path[prefix.chomp(File::SEPARATOR).length+1..-1] : self.abs_path
50
50
  end
51
51
 
data/lib/raven/okjson.rb CHANGED
@@ -271,8 +271,7 @@ private
271
271
  elsif m[2]
272
272
  [:val, m[0], Float(m[0])]
273
273
  else
274
- # We don't convert scientific notation
275
- [:val, m[0], m[0]]
274
+ [:val, m[0], Integer(m[1])*(10**Integer(m[3][1..-1]))]
276
275
  end
277
276
  else
278
277
  []
@@ -604,4 +603,5 @@ private
604
603
  Spc = ' '[0]
605
604
  Unesc = {?b=>?\b, ?f=>?\f, ?n=>?\n, ?r=>?\r, ?t=>?\t}
606
605
  end
606
+
607
607
  end
@@ -32,10 +32,10 @@ module Raven
32
32
  def sanitize(key, value)
33
33
  if !value.is_a?(String) || value.empty?
34
34
  value
35
- elsif VALUES_RE.match(value) or FIELDS_RE.match(key)
35
+ elsif VALUES_RE.match(clean_invalid_utf8_bytes(value)) or FIELDS_RE.match(key)
36
36
  MASK
37
37
  else
38
- value
38
+ clean_invalid_utf8_bytes(value)
39
39
  end
40
40
  end
41
41
 
@@ -44,6 +44,21 @@ module Raven
44
44
  sanitize(key, value)
45
45
  end
46
46
  end
47
+
48
+ private
49
+ def clean_invalid_utf8_bytes(text)
50
+ if RUBY_VERSION <= '1.8.7'
51
+ text
52
+ else
53
+ text.encode(
54
+ 'UTF-8',
55
+ 'binary',
56
+ :invalid => :replace,
57
+ :undef => :replace,
58
+ :replace => ''
59
+ )
60
+ end
61
+ end
47
62
  end
48
63
  end
49
64
  end
data/lib/raven/tasks.rb CHANGED
@@ -5,6 +5,9 @@ require 'raven/cli'
5
5
  namespace :raven do
6
6
  desc "Send a test event to the remote Sentry server"
7
7
  task :test, [:dsn] do |t, args|
8
+ if defined? Rails
9
+ Rake::Task["environment"].invoke
10
+ end
8
11
  Raven::CLI::test(args.dsn)
9
12
  end
10
13
  end
data/lib/raven/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Raven
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-raven
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Noah Kantrowitz
@@ -9,92 +10,74 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-12-08 00:00:00.000000000 Z
13
+ date: 2013-12-04 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: faraday
16
- requirement: !ruby/object:Gem::Requirement
17
+ requirement: &70257293798340 !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
20
  - - ! '>='
19
21
  - !ruby/object:Gem::Version
20
22
  version: 0.7.6
21
23
  type: :runtime
22
24
  prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ! '>='
26
- - !ruby/object:Gem::Version
27
- version: 0.7.6
25
+ version_requirements: *70257293798340
28
26
  - !ruby/object:Gem::Dependency
29
27
  name: uuidtools
30
- requirement: !ruby/object:Gem::Requirement
28
+ requirement: &70257293797940 !ruby/object:Gem::Requirement
29
+ none: false
31
30
  requirements:
32
31
  - - ! '>='
33
32
  - !ruby/object:Gem::Version
34
33
  version: '0'
35
34
  type: :runtime
36
35
  prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ! '>='
40
- - !ruby/object:Gem::Version
41
- version: '0'
36
+ version_requirements: *70257293797940
42
37
  - !ruby/object:Gem::Dependency
43
38
  name: hashie
44
- requirement: !ruby/object:Gem::Requirement
39
+ requirement: &70257293797400 !ruby/object:Gem::Requirement
40
+ none: false
45
41
  requirements:
46
42
  - - ! '>='
47
43
  - !ruby/object:Gem::Version
48
44
  version: 1.1.0
49
45
  type: :runtime
50
46
  prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: 1.1.0
47
+ version_requirements: *70257293797400
56
48
  - !ruby/object:Gem::Dependency
57
49
  name: rake
58
- requirement: !ruby/object:Gem::Requirement
50
+ requirement: &70257293796920 !ruby/object:Gem::Requirement
51
+ none: false
59
52
  requirements:
60
53
  - - ! '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  type: :development
64
57
  prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
58
+ version_requirements: *70257293796920
70
59
  - !ruby/object:Gem::Dependency
71
60
  name: rspec
72
- requirement: !ruby/object:Gem::Requirement
61
+ requirement: &70257293796300 !ruby/object:Gem::Requirement
62
+ none: false
73
63
  requirements:
74
64
  - - ~>
75
65
  - !ruby/object:Gem::Version
76
66
  version: '2.10'
77
67
  type: :development
78
68
  prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ~>
82
- - !ruby/object:Gem::Version
83
- version: '2.10'
69
+ version_requirements: *70257293796300
84
70
  - !ruby/object:Gem::Dependency
85
71
  name: coveralls
86
- requirement: !ruby/object:Gem::Requirement
72
+ requirement: &70257293795880 !ruby/object:Gem::Requirement
73
+ none: false
87
74
  requirements:
88
75
  - - ! '>='
89
76
  - !ruby/object:Gem::Version
90
77
  version: '0'
91
78
  type: :development
92
79
  prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ! '>='
96
- - !ruby/object:Gem::Version
97
- version: '0'
80
+ version_requirements: *70257293795880
98
81
  description:
99
82
  email: noah@coderanger.net
100
83
  executables:
@@ -104,10 +87,6 @@ extra_rdoc_files:
104
87
  - README.md
105
88
  - LICENSE
106
89
  files:
107
- - LICENSE
108
- - README.md
109
- - bin/raven
110
- - lib/raven.rb
111
90
  - lib/raven/backtrace.rb
112
91
  - lib/raven/cli.rb
113
92
  - lib/raven/client.rb
@@ -115,11 +94,11 @@ files:
115
94
  - lib/raven/context.rb
116
95
  - lib/raven/error.rb
117
96
  - lib/raven/event.rb
118
- - lib/raven/interfaces.rb
119
97
  - lib/raven/interfaces/exception.rb
120
98
  - lib/raven/interfaces/http.rb
121
99
  - lib/raven/interfaces/message.rb
122
100
  - lib/raven/interfaces/stack_trace.rb
101
+ - lib/raven/interfaces.rb
123
102
  - lib/raven/linecache.rb
124
103
  - lib/raven/logger.rb
125
104
  - lib/raven/okjson.rb
@@ -131,32 +110,37 @@ files:
131
110
  - lib/raven/railtie.rb
132
111
  - lib/raven/sidekiq.rb
133
112
  - lib/raven/tasks.rb
134
- - lib/raven/transports.rb
135
113
  - lib/raven/transports/http.rb
136
114
  - lib/raven/transports/udp.rb
115
+ - lib/raven/transports.rb
137
116
  - lib/raven/version.rb
117
+ - lib/raven.rb
138
118
  - lib/sentry-raven.rb
119
+ - README.md
120
+ - LICENSE
121
+ - bin/raven
139
122
  homepage: http://github.com/getsentry/raven-ruby
140
123
  licenses: []
141
- metadata: {}
142
124
  post_install_message:
143
125
  rdoc_options: []
144
126
  require_paths:
145
127
  - lib
146
128
  required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
147
130
  requirements:
148
131
  - - ! '>='
149
132
  - !ruby/object:Gem::Version
150
133
  version: '0'
151
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
+ none: false
152
136
  requirements:
153
137
  - - ! '>='
154
138
  - !ruby/object:Gem::Version
155
139
  version: '0'
156
140
  requirements: []
157
141
  rubyforge_project:
158
- rubygems_version: 2.2.2
142
+ rubygems_version: 1.8.10
159
143
  signing_key:
160
- specification_version: 4
144
+ specification_version: 3
161
145
  summary: A gem that provides a client interface for the Sentry error logger
162
146
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NjY4OWQ0MWVmNzM5YjVjMzM2NGYwOGI5NTkzNmI2MGRjYjhjMWVjOQ==
5
- data.tar.gz: !binary |-
6
- MTYxZTM3ZDkwMjk3NGE0OGVhZTUyYjU1Nzk5ODE3ZGRlNjcyM2VjMQ==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- OTEyNzIyNjRiYTEzNmFkZDU0ZWI2NDRlYTJhYzVjMTcwYzcxNzQ2MjFkOWFm
10
- NjUzZjg5MWI2MGQzZTZkYjBhNGIxMmEzYThlMWYxMDVkNzAwYzYxZjAwYWZi
11
- MDAyMTgxZDA1MzQ2NzBhZWQwZmVjNzUwNmNhMWJjYzQ2ODQwNzM=
12
- data.tar.gz: !binary |-
13
- MDRlMTFkNTVjOWFkNWUyNjBiMmY4MjgyYTFlNjhlNTkzZTYwNDNkYzE5ZDM3
14
- ZTdjOTdiZDhjNjRmNjJkNWY1ZTI3NDYwNmIzYzhkMzc5YzlhZWRlODM3YjI3
15
- ZTJhNjAxYjY3ZjhlZGUxOTBhZTBiMGM4OWFmODU2N2IzMWE1YjI=