sentry-raven 0.15.2 → 0.15.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35cd02edfcecacab72ec05f5e21e6a49099d60c2
4
- data.tar.gz: eb2e610878a3dc5a05158880951afb0c5ce9f8f8
3
+ metadata.gz: dc70253c8534fa8631331cbabf07e6cb4c4d31d2
4
+ data.tar.gz: 3d956a4c483a317b359332de520c3b402f8317bf
5
5
  SHA512:
6
- metadata.gz: 533c27c8a509e7ce2ca90dd1da725d50750c8273f41afc9b273ca625eb62cb08b55aa85c7dee0bf6ee72d5dd0d0596cf2c21c09157e843ec8d28c20883978948
7
- data.tar.gz: 4152a65f5a7775349b05e3fb88d13ba4ddbb92671d629a0125d450c84f9cd35ac46d97daf9a72de56c85b00d4f355a2c1241e50529a5011c0181ae6d8fc83366
6
+ metadata.gz: 2354d4020c5379674e12700beae4d39188a8f4b212832fa9bf1862977af062e84c9f9b559f0822a4b7430dd42c3ad2580778b55795a65b95586b9714860df462
7
+ data.tar.gz: 1842f5311c0d807b3595f26941b2162d400fb806b0c2d314cd5053d0e280dbcf832d05b3fb9c1a4633f42ea17a12fb7929b88237bdae0a0926d6b1a98167d079
data/README.md CHANGED
@@ -26,7 +26,7 @@ Raven.configure do |config|
26
26
  end
27
27
  ```
28
28
  ### Call
29
- 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.
29
+ If you use Rails, you're already done - no more configuration required! Check [Integrations](https://docs.getsentry.com/hosted/clients/ruby/integrations/) for more details on other gems Sentry integrates with automatically.
30
30
 
31
31
  Otherwise, Raven supports two methods of capturing exceptions:
32
32
  ```ruby
@@ -44,9 +44,7 @@ end
44
44
 
45
45
  ## More Information
46
46
 
47
- 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).
48
-
49
- * [Documentation](https://github.com/getsentry/raven-ruby/wiki)
47
+ * [Documentation](https://docs.getsentry.com/hosted/clients/ruby/)
50
48
  * [Bug Tracker](https://github.com/getsentry/raven-ruby/issues>)
51
49
  * [Code](https://github.com/getsentry/raven-ruby>)
52
50
  * [Mailing List](https://groups.google.com/group/getsentry>)
@@ -49,7 +49,7 @@ module URI
49
49
  # This decodes + to SP.
50
50
  #
51
51
  # See URI.encode_www_form_component, URI.decode_www_form
52
- def self.decode_www_form_component(str, enc=nil)
52
+ def self.decode_www_form_component(str, enc = nil)
53
53
  raise ArgumentError, "invalid %-encoding (#{str})" unless /\A(?:%[0-9a-fA-F]{2}|[^%])*\z/ =~ str
54
54
  str.gsub(/\+|%[0-9a-fA-F]{2}/) {|m| TBLDECWWWCOMP_[m]}
55
55
  end
@@ -4,17 +4,15 @@ module Raven
4
4
 
5
5
  # Front end to parsing the backtrace for each notice
6
6
  class Backtrace
7
-
8
7
  # Handles backtrace parsing line by line
9
8
  class Line
10
-
11
9
  # regexp (optionnally allowing leading X: for windows support)
12
10
  RUBY_INPUT_FORMAT = %r{^((?:[a-zA-Z]:)?[^:]+|<.*>):(\d+)(?::in `([^']+)')?$}.freeze
13
11
 
14
12
  # org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
15
13
  JAVA_INPUT_FORMAT = %r{^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$}.freeze
16
14
 
17
- APP_DIRS_PATTERN = /(bin|app|config|lib|test)/
15
+ APP_DIRS_PATTERN = /(bin|exe|app|config|lib|test)/
18
16
 
19
17
  # The file portion of the line (such as app/models/user.rb)
20
18
  attr_reader :file
@@ -108,7 +106,7 @@ module Raven
108
106
  end
109
107
 
110
108
  def inspect
111
- "<Backtrace: " + lines.map { |line| line.inspect }.join(", ") + ">"
109
+ "<Backtrace: " + lines.map(&inspect).join(", ") + ">"
112
110
  end
113
111
 
114
112
  def to_s
@@ -85,12 +85,6 @@ module Raven
85
85
  client.send_event(event)
86
86
  end
87
87
 
88
- def send(event)
89
- Raven.logger.warn "DEPRECATION WARNING: Calling #send on Raven::Base will be \
90
- removed in Raven-Ruby 0.14! Use #send_event instead!"
91
- client.send_event(event)
92
- end
93
-
94
88
  # Capture and process any exceptions from the given block, or globally if
95
89
  # no block is given
96
90
  #
@@ -158,7 +152,7 @@ module Raven
158
152
  # 'email' => 'foo@example.com' })
159
153
  # end
160
154
  def annotate_exception(exc, options = {})
161
- notes = exc.instance_variable_get(:@__raven_context) || {}
155
+ notes = (exc.instance_variable_defined?(:@__raven_context) && exc.instance_variable_get(:@__raven_context)) || {}
162
156
  notes.merge!(options)
163
157
  exc.instance_variable_set(:@__raven_context, notes)
164
158
  exc
@@ -1,5 +1,3 @@
1
- require 'raven'
2
-
3
1
  module Raven
4
2
  class CLI
5
3
  def self.test(dsn = nil)
@@ -49,10 +49,18 @@ module Raven
49
49
  event
50
50
  end
51
51
 
52
- def send(event)
53
- Raven.logger.warn "DEPRECATION WARNING: Calling #send on a Client will be \
54
- removed in Raven-Ruby 0.14! Use #send_event instead!"
55
- send_event(event)
52
+ def transport
53
+ @transport ||=
54
+ case configuration.scheme
55
+ when 'udp'
56
+ Transports::UDP.new(configuration)
57
+ when 'http', 'https'
58
+ Transports::HTTP.new(configuration)
59
+ when 'dummy'
60
+ Transports::Dummy.new(configuration)
61
+ else
62
+ fail "Unknown transport scheme '#{configuration.scheme}'"
63
+ end
56
64
  end
57
65
 
58
66
  private
@@ -82,18 +90,6 @@ module Raven
82
90
  (event && event[:message]) || '<no message value>'
83
91
  end
84
92
 
85
- def transport
86
- @transport ||=
87
- case configuration.scheme
88
- when 'udp'
89
- Transports::UDP.new(configuration)
90
- when 'http', 'https'
91
- Transports::HTTP.new(configuration)
92
- else
93
- raise Error, "Unknown transport scheme '#{self.configuration.scheme}'"
94
- end
95
- end
96
-
97
93
  def generate_auth_header
98
94
  now = Time.now.to_i.to_s
99
95
  fields = {
@@ -124,7 +120,6 @@ module Raven
124
120
  e.backtrace[0..10].each { |line| Raven.logger.error(line) }
125
121
  Raven.logger.error("Failed to submit event: #{get_log_message(event)}")
126
122
  end
127
-
128
123
  end
129
124
 
130
125
  class ClientState
@@ -3,7 +3,6 @@ require 'uri'
3
3
 
4
4
  module Raven
5
5
  class Configuration
6
-
7
6
  # Simple server string (setter provided below)
8
7
  attr_reader :server
9
8
 
@@ -101,13 +100,16 @@ module Raven
101
100
  # Sanitize values that look like credit card numbers
102
101
  attr_accessor :sanitize_credit_cards
103
102
 
104
- IGNORE_DEFAULT = ['ActiveRecord::RecordNotFound',
105
- 'ActionController::RoutingError',
106
- 'ActionController::InvalidAuthenticityToken',
107
- 'CGI::Session::CookieStore::TamperedWithCookie',
108
- 'ActionController::UnknownAction',
109
- 'AbstractController::ActionNotFound',
110
- 'Mongoid::Errors::DocumentNotFound']
103
+ IGNORE_DEFAULT = [
104
+ 'AbstractController::ActionNotFound',
105
+ 'ActionController::InvalidAuthenticityToken',
106
+ 'ActionController::RoutingError',
107
+ 'ActionController::UnknownAction',
108
+ 'ActiveRecord::RecordNotFound',
109
+ 'CGI::Session::CookieStore::TamperedWithCookie',
110
+ 'Mongoid::Errors::DocumentNotFound',
111
+ 'Sinatra::NotFound',
112
+ ]
111
113
 
112
114
  def initialize
113
115
  self.server = ENV['SENTRY_DSN'] if ENV['SENTRY_DSN']
@@ -127,6 +129,16 @@ module Raven
127
129
  self.sanitize_fields = []
128
130
  self.sanitize_credit_cards = true
129
131
  self.environments = []
132
+
133
+ self.release = ENV['HEROKU_SLUG_COMMIT']
134
+
135
+ if self.release.nil? || self.release.empty?
136
+ self.release = File.read(File.join(Rails.root, 'REVISION')).strip rescue nil
137
+ end
138
+
139
+ if self.release.nil? || self.release.empty?
140
+ self.release = `git rev-parse --short HEAD`.strip rescue nil
141
+ end
130
142
  end
131
143
 
132
144
  def server=(value)
@@ -152,14 +164,14 @@ module Raven
152
164
  end
153
165
 
154
166
  def encoding=(encoding)
155
- raise Error.new('Unsupported encoding') unless ['gzip', 'json'].include? encoding
167
+ raise Error.new('Unsupported encoding') unless %w(gzip json).include? encoding
156
168
  @encoding = encoding
157
169
  end
158
170
 
159
171
  alias_method :dsn=, :server=
160
172
 
161
173
  def async=(value)
162
- raise ArgumentError.new("async must be callable (or false to disable)") unless (value == false || value.respond_to?(:call))
174
+ raise ArgumentError.new("async must be callable (or false to disable)") unless value == false || value.respond_to?(:call)
163
175
  @async = value
164
176
  end
165
177
 
@@ -9,7 +9,6 @@ require 'raven/linecache'
9
9
  module Raven
10
10
 
11
11
  class Event
12
-
13
12
  LOG_LEVELS = {
14
13
  "debug" => 10,
15
14
  "info" => 20,
@@ -33,15 +32,16 @@ module Raven
33
32
  @interfaces = {}
34
33
  @context = Raven.context
35
34
  @id = generate_event_id
35
+ @project = nil
36
36
  @message = nil
37
37
  @timestamp = Time.now.utc
38
38
  @time_spent = nil
39
39
  @level = :error
40
40
  @logger = ''
41
41
  @culprit = nil
42
- @server_name = @configuration.server_name || get_hostname
42
+ @server_name = @configuration.server_name || resolve_hostname
43
43
  @release = @configuration.release
44
- @modules = get_modules if @configuration.send_modules
44
+ @modules = list_gem_specs if @configuration.send_modules
45
45
  @user = {}
46
46
  @extra = {}
47
47
  @tags = {}
@@ -56,7 +56,7 @@ module Raven
56
56
  end
57
57
  end
58
58
 
59
- init.each_pair { |key, val| instance_variable_set('@' + key.to_s, val) }
59
+ init.each_pair { |key, val| instance_variable_set('@' + key.to_s, val) }
60
60
 
61
61
  @user = @context.user.merge(@user)
62
62
  @extra = @context.extra.merge(@extra)
@@ -68,13 +68,13 @@ module Raven
68
68
  @level = LOG_LEVELS[@level.to_s.downcase] if @level.is_a?(String) || @level.is_a?(Symbol)
69
69
  end
70
70
 
71
- def get_hostname
71
+ def resolve_hostname
72
72
  # Try to resolve the hostname to an FQDN, but fall back to whatever the load name is
73
73
  hostname = Socket.gethostname
74
74
  Socket.gethostbyname(hostname).first rescue hostname
75
75
  end
76
76
 
77
- def get_modules
77
+ def list_gem_specs
78
78
  # Older versions of Rubygems don't support iterating over all specs
79
79
  Hash[Gem::Specification.map { |spec| [spec.name, spec.version.to_s] }] if Gem::Specification.respond_to?(:map)
80
80
  end
@@ -121,7 +121,7 @@ module Raven
121
121
  end
122
122
 
123
123
  def self.from_exception(exc, options = {}, &block)
124
- notes = exc.instance_variable_get(:@__raven_context) || {}
124
+ notes = (exc.instance_variable_defined?(:@__raven_context) && exc.instance_variable_get(:@__raven_context)) || {}
125
125
  options = notes.merge(options)
126
126
 
127
127
  configuration = options[:configuration] || Raven.configuration
@@ -178,17 +178,18 @@ module Raven
178
178
  end
179
179
  exceptions.reverse!
180
180
 
181
- exc_int.values = exceptions.map do |exc|
181
+ exc_int.values = exceptions.map do |e|
182
182
  SingleExceptionInterface.new do |int|
183
- int.type = exc.class.to_s
184
- int.value = exc.to_s
185
- int.module = exc.class.to_s.split('::')[0...-1].join('::')
186
-
187
- int.stacktrace = if exc.backtrace
188
- StacktraceInterface.new do |stacktrace|
189
- stacktrace_interface_from(stacktrace, evt, exc.backtrace)
183
+ int.type = e.class.to_s
184
+ int.value = e.to_s
185
+ int.module = e.class.to_s.split('::')[0...-1].join('::')
186
+
187
+ int.stacktrace =
188
+ if e.backtrace
189
+ StacktraceInterface.new do |stacktrace|
190
+ stacktrace_interface_from(stacktrace, evt, e.backtrace)
191
+ end
190
192
  end
191
- end
192
193
  end
193
194
  end
194
195
  end
@@ -209,7 +210,7 @@ module Raven
209
210
  evt.get_file_context(frame.abs_path, frame.lineno, evt.configuration[:context_lines])
210
211
  end
211
212
  end
212
- end.select { |f| f.filename }
213
+ end.select(&:filename)
213
214
 
214
215
  evt.culprit = evt.get_culprit(int.frames)
215
216
  end
@@ -227,7 +228,7 @@ module Raven
227
228
  end
228
229
 
229
230
  def get_culprit(frames)
230
- lastframe = frames.reverse.find { |f| f.in_app } || frames.last
231
+ lastframe = frames.reverse.find(&:in_app) || frames.last
231
232
  "#{lastframe.filename} in #{lastframe.function} at line #{lastframe.lineno}" if lastframe
232
233
  end
233
234
 
@@ -12,27 +12,32 @@ module Delayed
12
12
 
13
13
  rescue Exception => exception
14
14
  # Log error to Sentry
15
+ extra = {
16
+ :delayed_job => {
17
+ :id => job.id,
18
+ :priority => job.priority,
19
+ :attempts => job.attempts,
20
+ # handlers are YAML objects in strings, we definitely can't
21
+ # report all of that or the event will get truncated randomly
22
+ :handler => job.handler[0...100],
23
+ :last_error => job.last_error,
24
+ :run_at => job.run_at,
25
+ :locked_at => job.locked_at,
26
+ :locked_by => job.locked_by,
27
+ :queue => job.queue,
28
+ :created_at => job.created_at
29
+ }
30
+ }
31
+ if job.respond_to?('payload_object') && job.payload_object.respond_to?('job_data')
32
+ extra.merge!(:active_job => job.payload_object.job_data)
33
+ end
15
34
  ::Raven.capture_exception(exception,
16
35
  :logger => 'delayed_job',
17
36
  :tags => {
18
37
  :delayed_job_queue => job.queue,
19
38
  :delayed_job_id => job.id
20
39
  },
21
- :extra => {
22
- :delayed_job => {
23
- :id => job.id,
24
- :priority => job.priority,
25
- :attempts => job.attempts,
26
- :handler => job.handler,
27
- :last_error => job.last_error,
28
- :run_at => job.run_at,
29
- :locked_at => job.locked_at,
30
- #failed_at => job.failed_at,
31
- :locked_by => job.locked_by,
32
- :queue => job.queue,
33
- :created_at => job.created_at
34
- }
35
- })
40
+ :extra => extra)
36
41
 
37
42
  # Make sure we propagate the failure!
38
43
  raise exception
@@ -21,7 +21,6 @@ module Raven
21
21
  #
22
22
  # Use a standard Raven.configure call to configure your server credentials.
23
23
  class Rack
24
-
25
24
  def self.capture_type(exception, env, options = {})
26
25
  if env['raven.requested_at']
27
26
  options[:time_spent] = Time.now - env['raven.requested_at']
@@ -60,11 +59,68 @@ module Raven
60
59
  raise
61
60
  end
62
61
 
63
- error = env['rack.exception'] || env['sinatra.error'] || env['action_dispatch.exception']
64
-
62
+ error = env['rack.exception'] || env['sinatra.error']
65
63
  Raven::Rack.capture_exception(error, env) if error
66
64
 
67
65
  response
68
66
  end
69
67
  end
68
+
69
+ module RackInterface
70
+ def from_rack(env_hash)
71
+ req = ::Rack::Request.new(env_hash)
72
+
73
+ self.url = req.scheme && req.url.split('?').first
74
+ self.method = req.request_method
75
+ self.query_string = req.query_string
76
+ self.data = read_data_from(req)
77
+
78
+ self.headers = format_headers_for_sentry(env_hash)
79
+ self.env = format_env_for_sentry(env_hash)
80
+ end
81
+
82
+ private
83
+
84
+ def read_data_from(request)
85
+ if request.form_data?
86
+ request.POST
87
+ elsif request.body
88
+ data = request.body.read
89
+ request.body.rewind
90
+ data
91
+ end
92
+ end
93
+
94
+ def format_headers_for_sentry(env_hash)
95
+ env_hash.each_with_object({}) do |(key, value), memo|
96
+ key = key.to_s # rack env can contain symbols
97
+ value = value.to_s
98
+ next unless key.upcase == key # Non-upper case stuff isn't either
99
+ # Rack adds in an incorrect HTTP_VERSION key, which causes downstream
100
+ # to think this is a Version header. Instead, this is mapped to
101
+ # env['SERVER_PROTOCOL']. But we don't want to ignore a valid header
102
+ # if the request has legitimately sent a Version header themselves.
103
+ # See: https://github.com/rack/rack/blob/028438f/lib/rack/handler/cgi.rb#L29
104
+ next if key == 'HTTP_VERSION' && value == ENV['SERVER_PROTOCOL']
105
+ if key.start_with?('HTTP_')
106
+ # Header
107
+ http_key = key[5..key.length - 1].split('_').map(&:capitalize).join('-')
108
+ memo[http_key] = value
109
+ elsif %w(CONTENT_TYPE CONTENT_LENGTH).include? key
110
+ memo[key.capitalize] = value
111
+ end
112
+ end
113
+ end
114
+
115
+ def format_env_for_sentry(env_hash)
116
+ trimmed_hash = env_hash.select do |k, _v|
117
+ %w(REMOTE_ADDR SERVER_NAME SERVER_PORT).include? k.to_s
118
+ end
119
+ Hash[trimmed_hash] # select returns an Array in Ruby 1.8
120
+ end
121
+ end
122
+
123
+ class HttpInterface
124
+ include RackInterface
125
+ end
70
126
  end
@@ -1,4 +1,3 @@
1
- require 'raven'
2
1
  require 'rails'
3
2
 
4
3
  module Raven
@@ -35,8 +34,10 @@ module Raven
35
34
  require 'raven/integrations/tasks'
36
35
  end
37
36
 
38
- runner do
39
- Raven.capture
37
+ if defined?(runner)
38
+ runner do
39
+ Raven.capture
40
+ end
40
41
  end
41
42
  end
42
43
  end
@@ -10,4 +10,4 @@ module Rake
10
10
  orig_display_error_messsage(ex)
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -23,6 +23,33 @@ if Sidekiq::VERSION < '3'
23
23
  end
24
24
  else
25
25
  Sidekiq.configure_server do |config|
26
- config.error_handlers << Proc.new {|ex,context| Raven.capture_exception(ex, :extra => {:sidekiq => context}) }
26
+ config.error_handlers << Proc.new do |ex, context|
27
+ Raven.capture_exception(ex, :extra => {
28
+ :sidekiq => filter_context(context)
29
+ })
30
+ end
31
+ end
32
+ end
33
+
34
+ def filter_context(context)
35
+ case context
36
+ when Array
37
+ context.map { |arg| filter_context(arg) }
38
+ when Hash
39
+ Hash[context.map { |key, value| filter_context_hash(key, value) }]
40
+ else
41
+ context
27
42
  end
28
43
  end
44
+
45
+ def filter_context_hash(key, value)
46
+ # Strip any `_aj` prefixes from keys.
47
+ # These keys come from an internal serialized object from ActiveJob.
48
+ # Internally, there are a subset of keys that ActiveJob references, but
49
+ # these are declared as private, and I don't think it's wise
50
+ # to keep chasing what this list is. But they all use a common prefix, so
51
+ # we want to strip this becuase ActiveJob will complain.
52
+ # e.g.: _aj_globalid -> _globalid
53
+ (key = key[3..-1]) if key [0..3] == "_aj_"
54
+ [key, filter_context(value)]
55
+ end
@@ -1,5 +1,4 @@
1
1
  require 'rake'
2
- require 'raven'
3
2
  require 'raven/cli'
4
3
 
5
4
  namespace :raven do
@@ -2,7 +2,6 @@ require 'raven/interfaces'
2
2
 
3
3
  module Raven
4
4
  class ExceptionInterface < Interface
5
-
6
5
  name 'exception'
7
6
  attr_accessor :values
8
7
 
@@ -2,7 +2,6 @@ require 'raven/interfaces'
2
2
 
3
3
  module Raven
4
4
  class HttpInterface < Interface
5
-
6
5
  name 'request'
7
6
  attr_accessor :url
8
7
  attr_accessor :method
@@ -18,36 +17,6 @@ module Raven
18
17
  self.cookies = nil
19
18
  super(*arguments)
20
19
  end
21
-
22
- def from_rack(env)
23
- req = ::Rack::Request.new(env)
24
- self.url = req.scheme && req.url.split('?').first
25
- self.method = req.request_method
26
- self.query_string = req.query_string
27
- env.each_pair do |key, value|
28
- key = key.to_s #rack env can contain symbols
29
- next unless key.upcase == key # Non-upper case stuff isn't either
30
- if key.start_with?('HTTP_')
31
- # Header
32
- http_key = key[5..key.length - 1].split('_').map { |s| s.capitalize }.join('-')
33
- self.headers[http_key] = value.to_s
34
- elsif ['CONTENT_TYPE', 'CONTENT_LENGTH'].include? key
35
- self.headers[key.capitalize] = value.to_s
36
- elsif ['REMOTE_ADDR', 'SERVER_NAME', 'SERVER_PORT'].include? key
37
- # Environment
38
- self.env[key] = value.to_s
39
- end
40
- end
41
-
42
- self.data =
43
- if req.form_data?
44
- req.POST
45
- elsif req.body
46
- data = req.body.read
47
- req.body.rewind
48
- data
49
- end
50
- end
51
20
  end
52
21
 
53
22
  register_interface :http => HttpInterface
@@ -2,7 +2,6 @@ require 'raven/interfaces'
2
2
 
3
3
  module Raven
4
4
  class MessageInterface < Interface
5
-
6
5
  name 'sentry.interfaces.Message'
7
6
  attr_accessor :message
8
7
  attr_accessor :params
@@ -2,7 +2,6 @@ require 'raven/interfaces'
2
2
 
3
3
  module Raven
4
4
  class SingleExceptionInterface < Interface
5
-
6
5
  attr_accessor :type
7
6
  attr_accessor :value
8
7
  attr_accessor :module
@@ -2,7 +2,6 @@ require 'raven/interfaces'
2
2
 
3
3
  module Raven
4
4
  class StacktraceInterface < Interface
5
-
6
5
  name 'stacktrace'
7
6
  attr_accessor :frames
8
7
 
@@ -13,7 +12,7 @@ module Raven
13
12
 
14
13
  def to_hash(*args)
15
14
  data = super(*args)
16
- data[:frames] = data[:frames].map { |frame| frame.to_hash }
15
+ data[:frames] = data[:frames].map(&:to_hash)
17
16
  data
18
17
  end
19
18
 
@@ -37,13 +36,14 @@ module Raven
37
36
  def filename
38
37
  return nil if self.abs_path.nil?
39
38
 
40
- prefix = if under_project_root? && in_app
41
- project_root
42
- elsif under_project_root?
43
- longest_load_path || project_root
44
- else
45
- longest_load_path
46
- end
39
+ prefix =
40
+ if under_project_root? && in_app
41
+ project_root
42
+ elsif under_project_root?
43
+ longest_load_path || project_root
44
+ else
45
+ longest_load_path
46
+ end
47
47
 
48
48
  prefix ? self.abs_path[prefix.to_s.chomp(File::SEPARATOR).length+1..-1] : self.abs_path
49
49
  end
@@ -7,7 +7,7 @@ module Raven
7
7
 
8
8
  def is_valid_file(path)
9
9
  lines = getlines(path)
10
- return lines != nil
10
+ !lines.nil?
11
11
  end
12
12
 
13
13
  def getlines(path)
@@ -21,7 +21,7 @@ module Raven
21
21
  def getline(path, n)
22
22
  return nil if n < 1
23
23
  lines = getlines(path)
24
- return nil if lines == nil
24
+ return nil if lines.nil?
25
25
  lines[n - 1]
26
26
  end
27
27
  end
@@ -221,7 +221,7 @@ private
221
221
  ts = []
222
222
  while s.length > 0
223
223
  typ, lexeme, val = tok(s)
224
- if typ == nil
224
+ if typ.nil?
225
225
  raise Error, "invalid character at #{s[0,10].inspect}"
226
226
  end
227
227
  if typ != :space
@@ -289,7 +289,7 @@ private
289
289
 
290
290
  def strtok(s)
291
291
  m = /"([^"\\]|\\["\/\\bfnrt]|\\u[0-9a-fA-F]{4})*"/.match(s)
292
- if ! m
292
+ unless m
293
293
  raise Error, "invalid string literal at #{abbrev(s)}"
294
294
  end
295
295
  [:str, m[0], unquote(m[0])]
@@ -448,6 +448,7 @@ private
448
448
  case k
449
449
  when String then strenc(k)
450
450
  when Symbol then strenc(k.to_s)
451
+ when Fixnum then strenc(k.to_s)
451
452
  else
452
453
  raise Error, "Hash key is not a string: #{k.inspect}"
453
454
  end
@@ -4,7 +4,7 @@ module Raven
4
4
  @client = client
5
5
  end
6
6
 
7
- def process(data)
7
+ def process(_data)
8
8
  raise NotImplementedError
9
9
  end
10
10
  end
@@ -1,17 +1,15 @@
1
1
  module Raven
2
2
  class Processor::RemoveCircularReferences < Processor
3
-
4
3
  def process(v, visited = [])
5
4
  return "(...)" if visited.include?(v.__id__)
6
5
  visited += [v.__id__]
7
6
  if v.is_a?(Hash)
8
- v.reduce({}) { |memo, (k, v_)| memo[k] = process(v_, visited); memo }
7
+ v.each_with_object({}) { |(k, v_), memo| memo[k] = process(v_, visited) }
9
8
  elsif v.is_a?(Array)
10
9
  v.map { |v_| process(v_, visited) }
11
10
  else
12
11
  v
13
12
  end
14
13
  end
15
-
16
14
  end
17
15
  end
@@ -1,6 +1,5 @@
1
1
  module Raven
2
2
  class Processor::RemoveStacktrace < Processor
3
-
4
3
  def process(value)
5
4
  if value[:exception]
6
5
  value[:exception][:values].map do |single_exception|
@@ -10,6 +9,5 @@ module Raven
10
9
 
11
10
  value
12
11
  end
13
-
14
12
  end
15
13
  end
@@ -16,7 +16,7 @@ module Raven
16
16
  end
17
17
 
18
18
  def process(value)
19
- value.inject(value) { |memo,(k,v)| memo[k] = sanitize(k,v); memo }
19
+ value.each_with_object(value) { |(k,v), memo| memo[k] = sanitize(k,v) }
20
20
  end
21
21
 
22
22
  def sanitize(k,v)
@@ -45,7 +45,7 @@ module Raven
45
45
  private
46
46
 
47
47
  def sanitize_query_string(query_string)
48
- query_hash = CGI::parse(query_string)
48
+ query_hash = CGI.parse(query_string)
49
49
  processed_query_hash = process(query_hash)
50
50
  URI.encode_www_form(processed_query_hash)
51
51
  end
@@ -1,11 +1,14 @@
1
1
  module Raven
2
2
  class Processor::UTF8Conversion < Processor
3
-
4
3
  def process(value)
5
4
  if value.is_a? Array
6
5
  value.map { |v| process v }
7
6
  elsif value.is_a? Hash
8
7
  value.merge(value) { |_, v| process v }
8
+ elsif value.is_a?(Exception) && !value.message.valid_encoding?
9
+ clean_exc = value.class.new(clean_invalid_utf8_bytes(value.message))
10
+ clean_exc.set_backtrace(value.backtrace)
11
+ clean_exc
9
12
  else
10
13
  clean_invalid_utf8_bytes(value)
11
14
  end
@@ -3,14 +3,13 @@ require 'raven/error'
3
3
  module Raven
4
4
  module Transports
5
5
  class Transport
6
-
7
6
  attr_accessor :configuration
8
7
 
9
8
  def initialize(configuration)
10
9
  @configuration = configuration
11
10
  end
12
11
 
13
- def send_event#(auth_header, data, options = {})
12
+ def send_event #(auth_header, data, options = {})
14
13
  raise NotImplementedError.new('Abstract method not implemented')
15
14
  end
16
15
 
@@ -0,0 +1,16 @@
1
+ module Raven
2
+ module Transports
3
+ class Dummy < Transport
4
+ attr_accessor :events
5
+
6
+ def initialize(*)
7
+ super
8
+ @events = []
9
+ end
10
+
11
+ def send_event(auth_header, data, options = {})
12
+ @events << [auth_header, data, options]
13
+ end
14
+ end
15
+ end
16
+ end
@@ -6,9 +6,17 @@ require 'raven/error'
6
6
  module Raven
7
7
  module Transports
8
8
  class HTTP < Transport
9
+ attr_accessor :conn, :adapter
10
+
11
+ def initialize(*args)
12
+ super
13
+ self.adapter = configuration.http_adapter || Faraday.default_adapter
14
+ self.conn = set_conn
15
+ end
16
+
9
17
  def send_event(auth_header, data, options = {})
10
- project_id = self.configuration[:project_id]
11
- path = self.configuration[:path] + "/"
18
+ project_id = configuration[:project_id]
19
+ path = configuration[:path] + "/"
12
20
 
13
21
  response = conn.post "#{path}api/#{project_id}/store/" do |req|
14
22
  req.headers['Content-Type'] = options[:content_type]
@@ -19,48 +27,31 @@ module Raven
19
27
  response
20
28
  end
21
29
 
22
- def send(auth_header, data, options = {})
23
- Raven.logger.warn "DEPRECATION WARNING: Calling #send on a Transport will be \
24
- removed in Raven-Ruby 0.14! Use #send_event instead!"
25
- send_event(auth_header, data, options)
26
- end
27
-
28
30
  private
29
31
 
30
- def conn
31
- @conn ||= begin
32
- self.verify_configuration
32
+ def set_conn
33
+ verify_configuration
33
34
 
34
- Raven.logger.debug "Raven HTTP Transport connecting to #{self.configuration.server}"
35
+ Raven.logger.debug "Raven HTTP Transport connecting to #{configuration.server}"
35
36
 
36
- ssl_configuration = self.configuration.ssl || {}
37
- ssl_configuration[:verify] = self.configuration.ssl_verification
38
- ssl_configuration[:ca_file] = self.configuration.ssl_ca_file
37
+ ssl_configuration = configuration.ssl || {}
38
+ ssl_configuration[:verify] = configuration.ssl_verification
39
+ ssl_configuration[:ca_file] = configuration.ssl_ca_file
39
40
 
40
- conn = Faraday.new(
41
- :url => self.configuration[:server],
42
- :ssl => ssl_configuration
43
- ) do |builder|
44
- builder.adapter(*adapter)
45
- end
46
-
47
- if self.configuration.proxy
48
- conn.options[:proxy] = self.configuration.proxy
49
- end
41
+ conn = Faraday.new(
42
+ :url => configuration[:server],
43
+ :ssl => ssl_configuration
44
+ ) do |builder|
45
+ builder.adapter(*adapter)
46
+ end
50
47
 
51
- if self.configuration.timeout
52
- conn.options[:timeout] = self.configuration.timeout
53
- end
54
- if self.configuration.open_timeout
55
- conn.options[:open_timeout] = self.configuration.open_timeout
56
- end
48
+ conn.headers[:user_agent] = "sentry-ruby/#{Raven::VERSION}"
57
49
 
58
- conn
59
- end
60
- end
50
+ conn.options[:proxy] = configuration.proxy if configuration.proxy
51
+ conn.options[:timeout] = configuration.timeout if configuration.timeout
52
+ conn.options[:open_timeout] = configuration.open_timeout if configuration.open_timeout
61
53
 
62
- def adapter
63
- configuration.http_adapter || Faraday.default_adapter
54
+ conn
64
55
  end
65
56
  end
66
57
  end
@@ -10,12 +10,6 @@ module Raven
10
10
  conn.send "#{auth_header}\n\n#{data}", 0
11
11
  end
12
12
 
13
- def send(auth_header, data, options = {})
14
- Raven.logger.warn "DEPRECATION WARNING: Calling #send on a Transport will be \
15
- removed in Raven-Ruby 0.14! Use #send_event instead!"
16
- send_event(auth_header, data, options)
17
- end
18
-
19
13
  private
20
14
 
21
15
  def conn
@@ -1,3 +1,3 @@
1
1
  module Raven
2
- VERSION = "0.15.2"
2
+ VERSION = "0.15.3"
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.15.2
4
+ version: 0.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-22 00:00:00.000000000 Z
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: mime-types
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,10 +122,23 @@ dependencies:
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: test-unit
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
97
139
  description: A gem that provides a client interface for the Sentry error logger
98
140
  email: getsentry@googlegroups.com
99
- executables:
100
- - raven
141
+ executables: []
101
142
  extensions: []
102
143
  extra_rdoc_files:
103
144
  - README.md
@@ -105,7 +146,6 @@ extra_rdoc_files:
105
146
  files:
106
147
  - LICENSE
107
148
  - README.md
108
- - bin/raven
109
149
  - lib/raven.rb
110
150
  - lib/raven/backports/uri.rb
111
151
  - lib/raven/backtrace.rb
@@ -141,6 +181,7 @@ files:
141
181
  - lib/raven/processor/sanitizedata.rb
142
182
  - lib/raven/processor/utf8conversion.rb
143
183
  - lib/raven/transports.rb
184
+ - lib/raven/transports/dummy.rb
144
185
  - lib/raven/transports/http.rb
145
186
  - lib/raven/transports/udp.rb
146
187
  - lib/raven/version.rb
@@ -158,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
199
  requirements:
159
200
  - - ">="
160
201
  - !ruby/object:Gem::Version
161
- version: '0'
202
+ version: 1.8.7
162
203
  required_rubygems_version: !ruby/object:Gem::Requirement
163
204
  requirements:
164
205
  - - ">="
@@ -166,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
207
  version: '0'
167
208
  requirements: []
168
209
  rubyforge_project:
169
- rubygems_version: 2.4.6
210
+ rubygems_version: 2.5.1
170
211
  signing_key:
171
212
  specification_version: 4
172
213
  summary: A gem that provides a client interface for the Sentry error logger
data/bin/raven DELETED
@@ -1,40 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "raven"
4
- require "raven/cli"
5
- require "optparse"
6
-
7
- parser = OptionParser.new do |opt|
8
- opt.banner = "Usage: raven COMMAND [OPTIONS]"
9
- opt.separator ""
10
- opt.separator "Commands"
11
- opt.separator " test: send a test event"
12
- opt.separator ""
13
- opt.separator "Options"
14
-
15
- # opt.on("-e","--environment ENVIRONMENT","which environment you want server run") do |environment|
16
- # options[:environment] = environment
17
- # end
18
-
19
- # opt.on("-d","--daemon","runing on daemon mode?") do
20
- # options[:daemon] = true
21
- # end
22
-
23
- opt.on("-h","--help","help") do
24
- puts parser
25
- end
26
- end
27
-
28
- parser.parse!
29
-
30
- case ARGV[0]
31
- when "test"
32
- dsn = ARGV[1] if ARGV.length > 1
33
- if !dsn
34
- puts "Usage: raven test <dsn>"
35
- else
36
- Raven::CLI::test(dsn)
37
- end
38
- else
39
- puts parser
40
- end