sentry-raven 2.7.1 → 2.7.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 720bbe2b86e0c01584514a17c2f6299bb1313af1
4
- data.tar.gz: 0410c196dffd1e8d0617ff1d01335c120b9dfa3c
2
+ SHA256:
3
+ metadata.gz: 65c91464c7999bd385921487a02e931b3f178412bd22d43ca614c289c6d72c6d
4
+ data.tar.gz: 789a54b1f5c20db0246ce310a8c7993a9472b8594a7feae8c18843c56ca6963d
5
5
  SHA512:
6
- metadata.gz: 81eb505ebd43d3946a29ecd8e73ea67349c64907eee5821e1259e36353b6b204c7a42c7b584a4f2e93b1d45ee4a5fddf43c7c1f8315f5e63ff123caad2f73656
7
- data.tar.gz: f81baee39e752d97874a88f6c37457325d0ab3baa9a8d3b54a495842bf08095879940854965023cda72397d85ee00e8839b51c6bd7954a0c8668143df57c0c2f
6
+ metadata.gz: 6f7b6f3d3cb85364b94892c851c8c9dd0ebe17ea21438f596fafe805125275b6acb3e3bc9ba93850c6a0a2d5b1ce5429db37c29604841b4792cc795be50cc870
7
+ data.tar.gz: 77e29bf73bb328e51844ffb067730511fd130765c798d5611de1c714681d9fa6a88a552560b097a3cc2074387d2a965c381f6f51125fde81ed8b2e7b3f5900bf
data/.gitignore CHANGED
@@ -11,3 +11,4 @@ Gemfile.lock
11
11
  .ruby-version
12
12
  .ruby-gemset
13
13
  .idea
14
+ *.rdb
@@ -7,23 +7,23 @@ AllCops:
7
7
  - 'vendor/**/*'
8
8
 
9
9
  Metrics/ClassLength:
10
- Max: 262
10
+ Max: 268
11
11
  CountComments: false
12
12
 
13
13
  Metrics/AbcSize:
14
- Max: 58
14
+ Max: 30
15
15
 
16
16
  Metrics/CyclomaticComplexity:
17
- Max: 13
17
+ Max: 12
18
18
 
19
19
  Metrics/PerceivedComplexity:
20
- Max: 13
20
+ Max: 11
21
21
 
22
22
  Metrics/LineLength:
23
23
  Max: 155
24
24
 
25
25
  Metrics/MethodLength:
26
- Max: 41
26
+ Max: 30
27
27
 
28
28
  Style/SignalException:
29
29
  Enabled: false
@@ -4,13 +4,17 @@ sudo: false
4
4
  group: beta
5
5
  cache: bundler
6
6
 
7
+ services:
8
+ - redis-server
9
+
7
10
  branches:
8
11
  only: [master]
9
12
 
10
13
  rvm:
11
- - 2.2.8
12
- - 2.3.5
13
- - 2.4.2
14
+ - 2.2.9
15
+ - 2.3.6
16
+ - 2.4.3
17
+ - 2.5.0
14
18
 
15
19
  env:
16
20
  - RAILS_VERSION=4
@@ -24,7 +28,8 @@ addons:
24
28
 
25
29
  before_install:
26
30
  - service haveged start
27
- - gem install bundler
31
+ # Pin bundler version due to https://github.com/rubygems/rubygems/issues/2055
32
+ - gem install bundler -v 1.16.0
28
33
 
29
34
  matrix:
30
35
  include:
@@ -32,9 +37,9 @@ matrix:
32
37
  env: RAILS_VERSION=4
33
38
  - rvm: jruby-1.7.27
34
39
  env: JRUBY_OPTS="--dev" RAILS_VERSION=4
35
- - rvm: jruby-9.1.13.0
40
+ - rvm: jruby-9.1.15.0
36
41
  env: JRUBY_OPTS="--dev -J-Djruby.launch.inproc=true -J-Xmx1024M" RAILS_VERSION=4
37
- - rvm: jruby-9.1.13.0
42
+ - rvm: jruby-9.1.15.0
38
43
  env: JRUBY_OPTS="--dev -J-Djruby.launch.inproc=true -J-Xmx1024M" RAILS_VERSION=5
39
44
  - rvm: ruby-head
40
45
  env: RAILS_VERSION=0
data/Gemfile CHANGED
@@ -17,9 +17,11 @@ if RUBY_VERSION < '2.0'
17
17
  gem "nokogiri", "~> 1.6.8"
18
18
  gem "rack", "~> 1.6.8"
19
19
  gem "sidekiq", "< 3.2"
20
+ gem "rack-timeout", "0.3.0"
20
21
  else
21
22
  gem "rack"
22
23
  gem "sidekiq"
24
+ gem "rack-timeout"
23
25
  end
24
26
  gem "pry"
25
27
  gem "pry-coolline"
@@ -29,5 +31,8 @@ gem "ruby-prof", platform: :mri
29
31
  gem "rake"
30
32
  gem "rubocop", "~> 0.41.1"
31
33
  gem "rspec"
34
+ gem "capybara" # rspec system tests
35
+ gem "puma" # rspec system tests
36
+
32
37
  gem "timecop"
33
38
  gem "test-unit", platform: :mri if RUBY_VERSION > '2.2'
@@ -1,3 +1,12 @@
1
+ 2.7.2
2
+ -----
3
+
4
+ * BUGFIX: GlobalIDs are now displayed correctly in Sidekiq contexts [@louim, #798]
5
+ * BUGFIX: If git is not installed, fail silently during release detection [@nateberkopec]
6
+ * BUGFIX: We do not support rack-timeout <= 0.2, fix errors when incompat version present [@nateberkopec]
7
+ * BUGFIX: Put cookies in the correct spot of event [@nateberkopec, #812]
8
+ * BUGFIX: Exception context is deep_merged [@janklimo, #782]
9
+
1
10
  2.7.1
2
11
  -----
3
12
 
@@ -130,9 +130,9 @@ element of the array) will be used as the ``transaction`` for any events:
130
130
 
131
131
  .. sourcecode:: ruby
132
132
 
133
- Raven.context.transactions.push "User Import"
133
+ Raven.context.transaction.push "User Import"
134
134
  # import some users
135
- Raven.context.transactions.pop
135
+ Raven.context.transaction.pop
136
136
 
137
137
  Transactions may also be overridden/set explicitly during event creation:
138
138
 
@@ -3,7 +3,7 @@ Ruby on Rails
3
3
 
4
4
  In Rails, all uncaught exceptions will be automatically reported.
5
5
 
6
- We support Rails 3 and newer.
6
+ We support Rails 4 and newer.
7
7
 
8
8
  Installation
9
9
  ------------
@@ -130,7 +130,7 @@ module Raven
130
130
  # Note that the object passed into the block will be a String (messages) or
131
131
  # an exception.
132
132
  # e.g. lambda { |exc_or_msg| exc_or_msg.some_attr == false }
133
- attr_accessor :should_capture
133
+ attr_reader :should_capture
134
134
 
135
135
  # Silences ready message when true.
136
136
  attr_accessor :silence_ready
@@ -186,7 +186,7 @@ module Raven
186
186
  def initialize
187
187
  self.async = false
188
188
  self.context_lines = 3
189
- self.current_environment = ENV['SENTRY_CURRENT_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
189
+ self.current_environment = current_environment_from_env
190
190
  self.encoding = 'gzip'
191
191
  self.environments = []
192
192
  self.exclude_loggers = []
@@ -196,7 +196,6 @@ module Raven
196
196
  self.open_timeout = 1
197
197
  self.processors = DEFAULT_PROCESSORS.dup
198
198
  self.project_root = detect_project_root
199
- self.proxy = nil
200
199
  self.rails_activesupport_breadcrumbs = false
201
200
  self.rails_report_rescued_exceptions = true
202
201
  self.release = detect_release
@@ -206,8 +205,8 @@ module Raven
206
205
  self.sanitize_fields_excluded = []
207
206
  self.sanitize_http_headers = []
208
207
  self.send_modules = true
209
- self.server = ENV['SENTRY_DSN'] if ENV['SENTRY_DSN']
210
- self.server_name = heroku_dyno_name || resolve_hostname
208
+ self.server = ENV['SENTRY_DSN']
209
+ self.server_name = server_name_from_env
211
210
  self.should_capture = false
212
211
  self.ssl_verification = true
213
212
  self.tags = {}
@@ -216,6 +215,7 @@ module Raven
216
215
  end
217
216
 
218
217
  def server=(value)
218
+ return if value.nil?
219
219
  uri = URI.parse(value)
220
220
  uri_path = uri.path.split('/')
221
221
 
@@ -296,22 +296,6 @@ module Raven
296
296
  Backtrace::Line.instance_variable_set(:@in_app_pattern, nil) # blow away cache
297
297
  end
298
298
 
299
- def detect_release
300
- detect_release_from_git ||
301
- detect_release_from_capistrano ||
302
- detect_release_from_heroku
303
- rescue => ex
304
- logger.error "Error detecting release: #{ex.message}"
305
- end
306
-
307
- def detect_project_root
308
- if defined? Rails.root # we are in a Rails application
309
- Rails.root.to_s
310
- else
311
- Dir.pwd
312
- end
313
- end
314
-
315
299
  def exception_class_allowed?(exc)
316
300
  if exc.is_a?(Raven::Error)
317
301
  # Try to prevent error reporting loops
@@ -327,6 +311,22 @@ module Raven
327
311
 
328
312
  private
329
313
 
314
+ def detect_project_root
315
+ if defined? Rails.root # we are in a Rails application
316
+ Rails.root.to_s
317
+ else
318
+ Dir.pwd
319
+ end
320
+ end
321
+
322
+ def detect_release
323
+ detect_release_from_git ||
324
+ detect_release_from_capistrano ||
325
+ detect_release_from_heroku
326
+ rescue => ex
327
+ logger.error "Error detecting release: #{ex.message}"
328
+ end
329
+
330
330
  def excluded_exception?(exc)
331
331
  excluded_exceptions.any? { |x| get_exception_class(x) === exc }
332
332
  end
@@ -375,7 +375,7 @@ module Raven
375
375
  end
376
376
 
377
377
  def detect_release_from_git
378
- `git rev-parse --short HEAD`.strip if File.directory?(".git") rescue nil
378
+ Raven.sys_command("git rev-parse --short HEAD") if File.directory?(".git")
379
379
  end
380
380
 
381
381
  def capture_in_current_environment?
@@ -402,11 +402,6 @@ module Raven
402
402
  false
403
403
  end
404
404
 
405
- def heroku_dyno_name
406
- return unless running_on_heroku?
407
- ENV['DYNO']
408
- end
409
-
410
405
  def sample_allowed?
411
406
  return true if sample_rate == 1.0
412
407
  if Random::DEFAULT.rand >= sample_rate
@@ -423,5 +418,17 @@ module Raven
423
418
  Socket.gethostname ||
424
419
  Socket.gethostbyname(hostname).first rescue server_name
425
420
  end
421
+
422
+ def current_environment_from_env
423
+ ENV['SENTRY_CURRENT_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
424
+ end
425
+
426
+ def server_name_from_env
427
+ if running_on_heroku?
428
+ ENV['DYNO']
429
+ else
430
+ resolve_hostname
431
+ end
432
+ end
426
433
  end
427
434
  end
@@ -10,23 +10,24 @@ module Raven
10
10
 
11
11
  SDK = { "name" => "raven-ruby", "version" => Raven::VERSION }.freeze
12
12
 
13
- attr_accessor :id, :timestamp, :time_spent, :level, :logger,
14
- :transaction, :server_name, :release, :modules, :extra, :tags,
15
- :context, :configuration, :checksum, :fingerprint, :environment,
16
- :server_os, :runtime, :breadcrumbs, :user, :backtrace, :platform,
17
- :sdk
13
+ attr_accessor :id, :logger, :transaction, :server_name, :release, :modules,
14
+ :extra, :tags, :context, :configuration, :checksum,
15
+ :fingerprint, :environment, :server_os, :runtime,
16
+ :breadcrumbs, :user, :backtrace, :platform, :sdk
18
17
  alias event_id id
19
18
 
19
+ attr_reader :level, :timestamp, :time_spent
20
+
20
21
  def initialize(init = {})
21
- self.configuration = Raven.configuration
22
- self.breadcrumbs = Raven.breadcrumbs
23
- self.context = Raven.context
22
+ # Set some simple default values
24
23
  self.id = SecureRandom.uuid.delete("-")
25
24
  self.timestamp = Time.now.utc
26
25
  self.level = :error
27
26
  self.logger = :ruby
28
27
  self.platform = :ruby
29
28
  self.sdk = SDK
29
+
30
+ # Set some attributes with empty hashes to allow merging
30
31
  @interfaces = {}
31
32
  self.user = {} # TODO: contexts
32
33
  self.extra = {} # TODO: contexts
@@ -34,27 +35,14 @@ module Raven
34
35
  self.runtime = {} # TODO: contexts
35
36
  self.tags = {} # TODO: contexts
36
37
 
37
- yield self if block_given?
38
+ copy_initial_state
38
39
 
40
+ # Allow attributes to be set on the event at initialization
41
+ yield self if block_given?
39
42
  init.each_pair { |key, val| public_send("#{key}=", val) }
40
43
 
41
- self.transaction ||= context.transaction.last
42
- self.server_name ||= configuration.server_name
43
- self.release ||= configuration.release
44
- self.modules = list_gem_specs if configuration.send_modules
45
- self.environment ||= configuration.current_environment
46
-
47
- if !self[:http] && context.rack_env
48
- interface :http do |int|
49
- int.from_rack(context.rack_env)
50
- end
51
-
52
- context.user[:ip_address] = calculate_real_ip_from_rack
53
- end
54
-
55
- self.user = context.user.merge(user) # TODO: contexts
56
- self.extra = context.extra.merge(extra) # TODO: contexts
57
- self.tags = configuration.tags.merge(context.tags).merge(tags) # TODO: contexts
44
+ set_core_attributes_from_configuration
45
+ set_core_attributes_from_context
58
46
  end
59
47
 
60
48
  def self.from_exception(exc, options = {}, &block)
@@ -199,6 +187,38 @@ module Raven
199
187
 
200
188
  private
201
189
 
190
+ def copy_initial_state
191
+ self.configuration = Raven.configuration
192
+ self.breadcrumbs = Raven.breadcrumbs
193
+ self.context = Raven.context
194
+ end
195
+
196
+ def set_core_attributes_from_configuration
197
+ self.server_name ||= configuration.server_name
198
+ self.release ||= configuration.release
199
+ self.modules = list_gem_specs if configuration.send_modules
200
+ self.environment ||= configuration.current_environment
201
+ end
202
+
203
+ def set_core_attributes_from_context
204
+ self.transaction ||= context.transaction.last
205
+
206
+ # If this is a Rack event, merge Rack context
207
+ add_rack_context if !self[:http] && context.rack_env
208
+
209
+ # Merge contexts
210
+ self.user = context.user.merge(user) # TODO: contexts
211
+ self.extra = context.extra.merge(extra) # TODO: contexts
212
+ self.tags = configuration.tags.merge(context.tags).merge!(tags) # TODO: contexts
213
+ end
214
+
215
+ def add_rack_context
216
+ interface :http do |int|
217
+ int.from_rack(context.rack_env)
218
+ end
219
+ context.user[:ip_address] = calculate_real_ip_from_rack
220
+ end
221
+
202
222
  # When behind a proxy (or if the user is using a proxy), we can't use
203
223
  # REMOTE_ADDR to determine the Event IP, and must use other headers instead.
204
224
  def calculate_real_ip_from_rack
@@ -158,7 +158,7 @@ module Raven
158
158
  # end
159
159
  def annotate_exception(exc, options = {})
160
160
  notes = (exc.instance_variable_defined?(:@__raven_context) && exc.instance_variable_get(:@__raven_context)) || {}
161
- notes.merge!(options)
161
+ Raven::Utils::DeepMergeHash.deep_merge!(notes, options)
162
162
  exc.instance_variable_set(:@__raven_context, notes)
163
163
  exc
164
164
  end
@@ -7,9 +7,13 @@ require "rack/timeout/base" unless defined?(Rack::Timeout)
7
7
  # that will distinguish exceptions in the way you desire.
8
8
  module RackTimeoutExtensions
9
9
  def raven_context
10
- { :fingerprint => ["{{ default }}", env["REQUEST_URI"]] }
10
+ # Only rack-timeout 0.3.0+ provides the request environment, but we can't
11
+ # gate this based on a gem version constant because rack-timeout does
12
+ # not provide one.
13
+ { :fingerprint => ["{{ default }}", env["REQUEST_URI"]] } if defined?(env)
11
14
  end
12
15
  end
13
16
 
14
- Rack::Timeout::Error.include RackTimeoutExtensions
15
- Rack::Timeout::RequestTimeoutException.include RackTimeoutExtensions
17
+ # Include is private in Ruby 1.9
18
+ Rack::Timeout::Error.__send__(:include, RackTimeoutExtensions)
19
+ Rack::Timeout::RequestTimeoutException.__send__(:include, RackTimeoutExtensions)
@@ -74,9 +74,10 @@ module Raven
74
74
  self.method = req.request_method
75
75
  self.query_string = req.query_string
76
76
  self.data = read_data_from(req)
77
+ self.cookies = req.cookies
77
78
 
78
79
  self.headers = format_headers_for_sentry(env_hash)
79
- self.env = format_env_for_sentry(env_hash)
80
+ self.env = format_env_for_sentry(env_hash)
80
81
  end
81
82
 
82
83
  private
@@ -108,6 +109,7 @@ module Raven
108
109
  # if the request has legitimately sent a Version header themselves.
109
110
  # See: https://github.com/rack/rack/blob/028438f/lib/rack/handler/cgi.rb#L29
110
111
  next if key == 'HTTP_VERSION' && value == env_hash['SERVER_PROTOCOL']
112
+ next if key == 'HTTP_COOKIE' # Cookies don't go here, they go somewhere else
111
113
 
112
114
  next unless key.start_with?('HTTP_') || %w(CONTENT_TYPE CONTENT_LENGTH).include?(key)
113
115
  # Rack stores headers as HTTP_WHAT_EVER, we need What-Ever
@@ -14,6 +14,7 @@ module Raven
14
14
 
15
15
  class SidekiqErrorHandler
16
16
  ACTIVEJOB_RESERVED_PREFIX = "_aj_".freeze
17
+ HAS_GLOBALID = const_defined?('GlobalID')
17
18
 
18
19
  def call(ex, context)
19
20
  context = filter_context(context)
@@ -42,7 +43,7 @@ module Raven
42
43
  when Hash
43
44
  Hash[context.map { |key, value| filter_context_hash(key, value) }]
44
45
  else
45
- context
46
+ format_globalid(context)
46
47
  end
47
48
  end
48
49
 
@@ -65,6 +66,14 @@ module Raven
65
66
  "Sidekiq"
66
67
  end
67
68
  end
69
+
70
+ def format_globalid(context)
71
+ if HAS_GLOBALID && context.is_a?(GlobalID)
72
+ context.to_s
73
+ else
74
+ context
75
+ end
76
+ end
68
77
  end
69
78
  end
70
79
 
@@ -39,26 +39,27 @@ module Raven
39
39
  def set_conn
40
40
  configuration.logger.debug "Raven HTTP Transport connecting to #{configuration.server}"
41
41
 
42
- ssl_configuration = configuration.ssl || {}
43
- ssl_configuration[:verify] = configuration.ssl_verification
44
- ssl_configuration[:ca_file] = configuration.ssl_ca_file
45
-
46
- conn = Faraday.new(
47
- :url => configuration[:server],
48
- :ssl => ssl_configuration
49
- ) do |builder|
42
+ Faraday.new(configuration.server, :ssl => ssl_configuration) do |builder|
50
43
  configuration.faraday_builder.call(builder) if configuration.faraday_builder
51
44
  builder.response :raise_error
45
+ builder.options.merge! faraday_opts
46
+ builder.headers[:user_agent] = "sentry-ruby/#{Raven::VERSION}"
52
47
  builder.adapter(*adapter)
53
48
  end
49
+ end
54
50
 
55
- conn.headers[:user_agent] = "sentry-ruby/#{Raven::VERSION}"
56
-
57
- conn.options[:proxy] = configuration.proxy if configuration.proxy
58
- conn.options[:timeout] = configuration.timeout if configuration.timeout
59
- conn.options[:open_timeout] = configuration.open_timeout if configuration.open_timeout
51
+ # TODO: deprecate and replace where possible w/Faraday Builder
52
+ def faraday_opts
53
+ [:proxy, :timeout, :open_timeout].each_with_object({}) do |opt, memo|
54
+ memo[opt] = configuration.public_send(opt) if configuration.public_send(opt)
55
+ end
56
+ end
60
57
 
61
- conn
58
+ def ssl_configuration
59
+ (configuration.ssl || {}).merge(
60
+ :verify => configuration.ssl_verification,
61
+ :ca_file => configuration.ssl_ca_file
62
+ )
62
63
  end
63
64
  end
64
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Raven
3
3
  # Freezing this constant breaks in 1.9.x
4
- VERSION = "2.7.1" # rubocop:disable Style/MutableConstant
4
+ VERSION = "2.7.2" # rubocop:disable Style/MutableConstant
5
5
  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: 2.7.1
4
+ version: 2.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-11 00:00:00.000000000 Z
11
+ date: 2018-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  requirements: []
138
138
  rubyforge_project:
139
- rubygems_version: 2.6.13
139
+ rubygems_version: 2.7.3
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: A gem that provides a client interface for the Sentry error logger