sentry-raven 3.0.4 → 3.1.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.craft.yml +9 -5
  3. data/.scripts/bump-version.rb +5 -0
  4. data/CHANGELOG.md +145 -1
  5. data/Gemfile +5 -1
  6. data/Makefile +3 -0
  7. data/README.md +26 -8
  8. data/lib/raven/backtrace.rb +2 -0
  9. data/lib/raven/base.rb +2 -0
  10. data/lib/raven/breadcrumbs/active_support_logger.rb +25 -0
  11. data/lib/raven/breadcrumbs/logger.rb +2 -92
  12. data/lib/raven/breadcrumbs/sentry_logger.rb +73 -0
  13. data/lib/raven/cli.rb +1 -1
  14. data/lib/raven/client.rb +1 -1
  15. data/lib/raven/configuration.rb +75 -4
  16. data/lib/raven/context.rb +13 -8
  17. data/lib/raven/event.rb +27 -13
  18. data/lib/raven/helpers/deprecation_helper.rb +17 -0
  19. data/lib/raven/instance.rb +15 -2
  20. data/lib/raven/integrations/delayed_job.rb +2 -1
  21. data/lib/raven/integrations/rack-timeout.rb +5 -1
  22. data/lib/raven/integrations/rack.rb +5 -4
  23. data/lib/raven/integrations/rails.rb +12 -3
  24. data/lib/raven/integrations/rails/active_job.rb +2 -1
  25. data/lib/raven/integrations/rails/backtrace_cleaner.rb +29 -0
  26. data/lib/raven/integrations/sidekiq.rb +4 -78
  27. data/lib/raven/integrations/sidekiq/cleanup_middleware.rb +13 -0
  28. data/lib/raven/integrations/sidekiq/error_handler.rb +38 -0
  29. data/lib/raven/transports/http.rb +2 -3
  30. data/lib/raven/utils/context_filter.rb +42 -0
  31. data/lib/raven/utils/request_id.rb +16 -0
  32. data/lib/raven/version.rb +1 -1
  33. data/lib/sentry-raven-without-integrations.rb +6 -1
  34. data/lib/sentry_raven_without_integrations.rb +1 -0
  35. data/sentry-raven.gemspec +7 -0
  36. metadata +18 -12
  37. data/.github/workflows/test.yml +0 -87
  38. data/.github/workflows/zeus_upload.yml +0 -32
  39. data/.gitignore +0 -15
  40. data/.gitmodules +0 -0
  41. data/.rspec +0 -1
  42. data/.rubocop.yml +0 -109
  43. data/.scripts/bump-version.sh +0 -9
  44. data/CONTRIUTING.md +0 -26
  45. data/lib/raven/breadcrumbs/activesupport.rb +0 -19
@@ -10,7 +10,11 @@ module RackTimeoutExtensions
10
10
  # Only rack-timeout 0.3.0+ provides the request environment, but we can't
11
11
  # gate this based on a gem version constant because rack-timeout does
12
12
  # not provide one.
13
- { :fingerprint => ["{{ default }}", env["REQUEST_URI"]] } if defined?(env)
13
+ if defined?(env)
14
+ { :fingerprint => ["{{ default }}", env["REQUEST_URI"]] }
15
+ else
16
+ {}
17
+ end
14
18
  end
15
19
  end
16
20
 
@@ -100,7 +100,7 @@ module Raven
100
100
  env_hash.each_with_object({}) do |(key, value), memo|
101
101
  begin
102
102
  key = key.to_s # rack env can contain symbols
103
- value = value.to_s
103
+ next memo['X-Request-Id'] ||= Utils::RequestId.read_from(env_hash) if Utils::RequestId::REQUEST_ID_HEADERS.include?(key)
104
104
  next unless key.upcase == key # Non-upper case stuff isn't either
105
105
 
106
106
  # Rack adds in an incorrect HTTP_VERSION key, which causes downstream
@@ -110,13 +110,12 @@ module Raven
110
110
  # See: https://github.com/rack/rack/blob/028438f/lib/rack/handler/cgi.rb#L29
111
111
  next if key == 'HTTP_VERSION' && value == env_hash['SERVER_PROTOCOL']
112
112
  next if key == 'HTTP_COOKIE' # Cookies don't go here, they go somewhere else
113
-
114
113
  next unless key.start_with?('HTTP_') || %w(CONTENT_TYPE CONTENT_LENGTH).include?(key)
115
114
 
116
115
  # Rack stores headers as HTTP_WHAT_EVER, we need What-Ever
117
116
  key = key.sub(/^HTTP_/, "")
118
117
  key = key.split('_').map(&:capitalize).join('-')
119
- memo[key] = value
118
+ memo[key] = value.to_s
120
119
  rescue StandardError => e
121
120
  # Rails adds objects to the Rack env that can sometimes raise exceptions
122
121
  # when `to_s` is called.
@@ -128,8 +127,10 @@ module Raven
128
127
  end
129
128
 
130
129
  def format_env_for_sentry(env_hash)
130
+ return env_hash if Raven.configuration.rack_env_whitelist.empty?
131
+
131
132
  env_hash.select do |k, _v|
132
- %w(REMOTE_ADDR SERVER_NAME SERVER_PORT).include? k.to_s
133
+ Raven.configuration.rack_env_whitelist.include? k.to_s
133
134
  end
134
135
  end
135
136
  end
@@ -5,6 +5,7 @@ module Raven
5
5
  require 'raven/integrations/rails/overrides/streaming_reporter'
6
6
  require 'raven/integrations/rails/controller_methods'
7
7
  require 'raven/integrations/rails/controller_transaction'
8
+ require 'raven/integrations/rails/backtrace_cleaner'
8
9
  require 'raven/integrations/rack'
9
10
 
10
11
  initializer "raven.use_rack_middleware" do |app|
@@ -37,12 +38,20 @@ module Raven
37
38
 
38
39
  config.before_initialize do
39
40
  Raven.configuration.logger = ::Rails.logger
41
+
42
+ backtrace_cleaner = Raven::Rails::BacktraceCleaner.new
43
+
44
+ Raven.configuration.backtrace_cleanup_callback = lambda do |backtrace|
45
+ backtrace_cleaner.clean(backtrace)
46
+ end
40
47
  end
41
48
 
42
49
  config.after_initialize do
43
- if Raven.configuration.rails_activesupport_breadcrumbs
44
- require 'raven/breadcrumbs/activesupport'
45
- Raven::ActiveSupportBreadcrumbs.inject
50
+ if Raven.configuration.breadcrumbs_logger.include?(:active_support_logger) ||
51
+ Raven.configuration.rails_activesupport_breadcrumbs
52
+
53
+ require 'raven/breadcrumbs/active_support_logger'
54
+ Raven::Breadcrumbs::ActiveSupportLogger.inject
46
55
  end
47
56
 
48
57
  if Raven.configuration.rails_report_rescued_exceptions
@@ -21,7 +21,8 @@ module Raven
21
21
  def capture_and_reraise_with_sentry(job, block)
22
22
  block.call
23
23
  rescue Exception => e # rubocop:disable Lint/RescueException
24
- return if rescue_with_handler(e)
24
+ rescue_handler_result = rescue_with_handler(e)
25
+ return rescue_handler_result if rescue_handler_result
25
26
 
26
27
  Raven.capture_exception(e, :extra => raven_context(job))
27
28
  raise e
@@ -0,0 +1,29 @@
1
+ require "active_support/backtrace_cleaner"
2
+ require "active_support/core_ext/string/access"
3
+
4
+ module Raven
5
+ class Rails
6
+ class BacktraceCleaner < ActiveSupport::BacktraceCleaner
7
+ APP_DIRS_PATTERN = /\A(?:\.\/)?(?:app|config|lib|test|\(\w*\))/.freeze
8
+ RENDER_TEMPLATE_PATTERN = /:in `.*_\w+_{2,3}\d+_\d+'/.freeze
9
+
10
+ def initialize
11
+ super
12
+ # we don't want any default silencers because they're too aggressive
13
+ remove_silencers!
14
+
15
+ @root = "#{Raven.configuration.project_root}/"
16
+ add_filter do |line|
17
+ line.start_with?(@root) ? line.from(@root.size) : line
18
+ end
19
+ add_filter do |line|
20
+ if line =~ RENDER_TEMPLATE_PATTERN
21
+ line.sub(RENDER_TEMPLATE_PATTERN, "")
22
+ else
23
+ line
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,87 +1,13 @@
1
1
  require 'time'
2
2
  require 'sidekiq'
3
-
4
- module Raven
5
- class SidekiqCleanupMiddleware
6
- def call(_worker, job, queue)
7
- Raven.context.transaction.push "Sidekiq/#{job['class']}"
8
- Raven.extra_context(:sidekiq => job.merge("queue" => queue))
9
- yield
10
- Context.clear!
11
- BreadcrumbBuffer.clear!
12
- end
13
- end
14
-
15
- class SidekiqErrorHandler
16
- ACTIVEJOB_RESERVED_PREFIX = "_aj_".freeze
17
- HAS_GLOBALID = const_defined?('GlobalID')
18
-
19
- def call(ex, context)
20
- context = filter_context(context)
21
- Raven.context.transaction.push transaction_from_context(context)
22
- Raven.capture_exception(
23
- ex,
24
- :message => ex.message,
25
- :extra => { :sidekiq => context }
26
- )
27
- Context.clear!
28
- BreadcrumbBuffer.clear!
29
- end
30
-
31
- private
32
-
33
- # Once an ActiveJob is queued, ActiveRecord references get serialized into
34
- # some internal reserved keys, such as _aj_globalid.
35
- #
36
- # The problem is, if this job in turn gets queued back into ActiveJob with
37
- # these magic reserved keys, ActiveJob will throw up and error. We want to
38
- # capture these and mutate the keys so we can sanely report it.
39
- def filter_context(context)
40
- case context
41
- when Array
42
- context.map { |arg| filter_context(arg) }
43
- when Hash
44
- Hash[context.map { |key, value| filter_context_hash(key, value) }]
45
- else
46
- format_globalid(context)
47
- end
48
- end
49
-
50
- def filter_context_hash(key, value)
51
- (key = key[3..-1]) if key [0..3] == ACTIVEJOB_RESERVED_PREFIX
52
- [key, filter_context(value)]
53
- end
54
-
55
- # this will change in the future:
56
- # https://github.com/mperham/sidekiq/pull/3161
57
- def transaction_from_context(context)
58
- classname = (context["wrapped"] || context["class"] ||
59
- (context[:job] && (context[:job]["wrapped"] || context[:job]["class"]))
60
- )
61
- if classname
62
- "Sidekiq/#{classname}"
63
- elsif context[:event]
64
- "Sidekiq/#{context[:event]}"
65
- else
66
- "Sidekiq"
67
- end
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
77
- end
78
- end
3
+ require 'raven/integrations/sidekiq/cleanup_middleware'
4
+ require 'raven/integrations/sidekiq/error_handler'
79
5
 
80
6
  if Sidekiq::VERSION > '3'
81
7
  Sidekiq.configure_server do |config|
82
- config.error_handlers << Raven::SidekiqErrorHandler.new
8
+ config.error_handlers << Raven::Sidekiq::ErrorHandler.new
83
9
  config.server_middleware do |chain|
84
- chain.add Raven::SidekiqCleanupMiddleware
10
+ chain.add Raven::Sidekiq::CleanupMiddleware
85
11
  end
86
12
  end
87
13
  end
@@ -0,0 +1,13 @@
1
+ module Raven
2
+ module Sidekiq
3
+ class CleanupMiddleware
4
+ def call(_worker, job, queue)
5
+ Raven.context.transaction.push "Sidekiq/#{job['class']}"
6
+ Raven.extra_context(:sidekiq => job.merge("queue" => queue))
7
+ yield
8
+ Context.clear!
9
+ BreadcrumbBuffer.clear!
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ require 'raven/utils/context_filter'
2
+
3
+ module Raven
4
+ module Sidekiq
5
+ class ErrorHandler
6
+ SIDEKIQ_NAME = "Sidekiq".freeze
7
+
8
+ def call(ex, context)
9
+ context = Utils::ContextFilter.filter_context(context)
10
+ Raven.context.transaction.push transaction_from_context(context)
11
+ Raven.capture_exception(
12
+ ex,
13
+ :message => ex.message,
14
+ :extra => { :sidekiq => context }
15
+ )
16
+ Context.clear!
17
+ BreadcrumbBuffer.clear!
18
+ end
19
+
20
+ private
21
+
22
+ # this will change in the future:
23
+ # https://github.com/mperham/sidekiq/pull/3161
24
+ def transaction_from_context(context)
25
+ classname = (context["wrapped"] || context["class"] ||
26
+ (context[:job] && (context[:job]["wrapped"] || context[:job]["class"]))
27
+ )
28
+ if classname
29
+ "#{SIDEKIQ_NAME}/#{classname}"
30
+ elsif context[:event]
31
+ "#{SIDEKIQ_NAME}/#{context[:event]}"
32
+ else
33
+ SIDEKIQ_NAME
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,7 +1,5 @@
1
1
  require 'faraday'
2
2
 
3
- require 'raven/transports'
4
-
5
3
  module Raven
6
4
  module Transports
7
5
  class HTTP < Transport
@@ -15,7 +13,8 @@ module Raven
15
13
 
16
14
  def send_event(auth_header, data, options = {})
17
15
  unless configuration.sending_allowed?
18
- logger.debug("Event not sent: #{configuration.error_messages}")
16
+ configuration.logger.debug("Event not sent: #{configuration.error_messages}")
17
+ return
19
18
  end
20
19
 
21
20
  project_id = configuration[:project_id]
@@ -0,0 +1,42 @@
1
+ module Raven
2
+ module Utils
3
+ module ContextFilter
4
+ class << self
5
+ ACTIVEJOB_RESERVED_PREFIX_REGEX = /^_aj_/.freeze
6
+ HAS_GLOBALID = const_defined?('GlobalID')
7
+
8
+ # Once an ActiveJob is queued, ActiveRecord references get serialized into
9
+ # some internal reserved keys, such as _aj_globalid.
10
+ #
11
+ # The problem is, if this job in turn gets queued back into ActiveJob with
12
+ # these magic reserved keys, ActiveJob will throw up and error. We want to
13
+ # capture these and mutate the keys so we can sanely report it.
14
+ def filter_context(context)
15
+ case context
16
+ when Array
17
+ context.map { |arg| filter_context(arg) }
18
+ when Hash
19
+ Hash[context.map { |key, value| filter_context_hash(key, value) }]
20
+ else
21
+ format_globalid(context)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def filter_context_hash(key, value)
28
+ key = key.to_s.sub(ACTIVEJOB_RESERVED_PREFIX_REGEX, "") if key.match(ACTIVEJOB_RESERVED_PREFIX_REGEX)
29
+ [key, filter_context(value)]
30
+ end
31
+
32
+ def format_globalid(context)
33
+ if HAS_GLOBALID && context.is_a?(GlobalID)
34
+ context.to_s
35
+ else
36
+ context
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ module Raven
2
+ module Utils
3
+ module RequestId
4
+ REQUEST_ID_HEADERS = %w(action_dispatch.request_id HTTP_X_REQUEST_ID).freeze
5
+
6
+ # Request ID based on ActionDispatch::RequestId
7
+ def self.read_from(env_hash)
8
+ REQUEST_ID_HEADERS.each do |key|
9
+ request_id = env_hash[key]
10
+ return request_id if request_id
11
+ end
12
+ nil
13
+ end
14
+ end
15
+ end
16
+ end
data/lib/raven/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raven
4
- VERSION = "3.0.4"
4
+ VERSION = "3.1.2"
5
5
  end
@@ -1 +1,6 @@
1
- require 'raven/base'
1
+ require "raven/helpers/deprecation_helper"
2
+
3
+ filename = "sentry_raven_without_integrations"
4
+ DeprecationHelper.deprecate_dasherized_filename(filename)
5
+
6
+ require filename
@@ -0,0 +1 @@
1
+ require 'raven/base'
data/sentry-raven.gemspec CHANGED
@@ -18,4 +18,11 @@ Gem::Specification.new do |gem|
18
18
  gem.executables = "raven"
19
19
 
20
20
  gem.add_dependency "faraday", ">= 1.0"
21
+
22
+ gem.post_install_message = <<~EOS
23
+ `sentry-raven` is deprecated! Please migrate to `sentry-ruby`
24
+
25
+ See https://docs.sentry.io/platforms/ruby/migration for the migration guide.
26
+
27
+ EOS
21
28
  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: 3.0.4
4
+ version: 3.1.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: 2020-08-28 00:00:00.000000000 Z
11
+ date: 2021-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -34,17 +34,11 @@ extra_rdoc_files:
34
34
  - LICENSE
35
35
  files:
36
36
  - ".craft.yml"
37
- - ".github/workflows/test.yml"
38
- - ".github/workflows/zeus_upload.yml"
39
- - ".gitignore"
40
- - ".gitmodules"
41
- - ".rspec"
42
- - ".rubocop.yml"
43
- - ".scripts/bump-version.sh"
37
+ - ".scripts/bump-version.rb"
44
38
  - CHANGELOG.md
45
- - CONTRIUTING.md
46
39
  - Gemfile
47
40
  - LICENSE
41
+ - Makefile
48
42
  - README.md
49
43
  - Rakefile
50
44
  - exe/raven
@@ -52,8 +46,9 @@ files:
52
46
  - lib/raven/backtrace.rb
53
47
  - lib/raven/base.rb
54
48
  - lib/raven/breadcrumbs.rb
55
- - lib/raven/breadcrumbs/activesupport.rb
49
+ - lib/raven/breadcrumbs/active_support_logger.rb
56
50
  - lib/raven/breadcrumbs/logger.rb
51
+ - lib/raven/breadcrumbs/sentry_logger.rb
57
52
  - lib/raven/cli.rb
58
53
  - lib/raven/client.rb
59
54
  - lib/raven/configuration.rb
@@ -61,12 +56,14 @@ files:
61
56
  - lib/raven/core_ext/object/deep_dup.rb
62
57
  - lib/raven/core_ext/object/duplicable.rb
63
58
  - lib/raven/event.rb
59
+ - lib/raven/helpers/deprecation_helper.rb
64
60
  - lib/raven/instance.rb
65
61
  - lib/raven/integrations/delayed_job.rb
66
62
  - lib/raven/integrations/rack-timeout.rb
67
63
  - lib/raven/integrations/rack.rb
68
64
  - lib/raven/integrations/rails.rb
69
65
  - lib/raven/integrations/rails/active_job.rb
66
+ - lib/raven/integrations/rails/backtrace_cleaner.rb
70
67
  - lib/raven/integrations/rails/controller_methods.rb
71
68
  - lib/raven/integrations/rails/controller_transaction.rb
72
69
  - lib/raven/integrations/rails/overrides/debug_exceptions_catcher.rb
@@ -74,6 +71,8 @@ files:
74
71
  - lib/raven/integrations/railties.rb
75
72
  - lib/raven/integrations/rake.rb
76
73
  - lib/raven/integrations/sidekiq.rb
74
+ - lib/raven/integrations/sidekiq/cleanup_middleware.rb
75
+ - lib/raven/integrations/sidekiq/error_handler.rb
77
76
  - lib/raven/integrations/tasks.rb
78
77
  - lib/raven/interface.rb
79
78
  - lib/raven/interfaces/exception.rb
@@ -95,18 +94,25 @@ files:
95
94
  - lib/raven/transports/dummy.rb
96
95
  - lib/raven/transports/http.rb
97
96
  - lib/raven/transports/stdout.rb
97
+ - lib/raven/utils/context_filter.rb
98
98
  - lib/raven/utils/deep_merge.rb
99
99
  - lib/raven/utils/exception_cause_chain.rb
100
100
  - lib/raven/utils/real_ip.rb
101
+ - lib/raven/utils/request_id.rb
101
102
  - lib/raven/version.rb
102
103
  - lib/sentry-raven-without-integrations.rb
103
104
  - lib/sentry-raven.rb
105
+ - lib/sentry_raven_without_integrations.rb
104
106
  - sentry-raven.gemspec
105
107
  homepage: https://github.com/getsentry/raven-ruby
106
108
  licenses:
107
109
  - Apache-2.0
108
110
  metadata: {}
109
- post_install_message:
111
+ post_install_message: |+
112
+ `sentry-raven` is deprecated! Please migrate to `sentry-ruby`
113
+
114
+ See https://docs.sentry.io/platforms/ruby/migration for the migration guide.
115
+
110
116
  rdoc_options: []
111
117
  require_paths:
112
118
  - lib