sentry-rails 5.2.1 → 5.4.0

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
  SHA256:
3
- metadata.gz: 8abb9b42e0bad172e91125577c9e675687a6b4a2b1a905c83258fcbc1b1b4402
4
- data.tar.gz: '095d6e8fbc545a88ecc6ec0d4a8e2cd046e0d1cfa4816e13cfa5b1f40b656d5d'
3
+ metadata.gz: ea442f30a8d61b36170660802c51be9e98ffd3591d5298e6a17a39556dcfba5f
4
+ data.tar.gz: '079dbb354bc8c43a25308fb84a63bfedfe67d51aa5c4265ed78441dd39e989e9'
5
5
  SHA512:
6
- metadata.gz: 84fdcf91056c8502fa63880a0d456e3677adafa15c7df35c7a1949249623d07c0217fa9286c3edda6ce7f1dcb0f096f48f25bbb54555e598124f67652b168576
7
- data.tar.gz: e91d36c193548d10575a3e45c1023c1eb4d7628ded62f604d1659fd9589a5f5ed450592bc3d50ea64fbdc8517385ab439d547e80e8031382e8120b5f3af7dd25
6
+ metadata.gz: 10116c6cad137020fcbb2569ce0f6d3e57311e28e69851f0ee8bf368c1a382bc8502545a4fd1ae9c8df29bf23495776a7ac4c78161f799c0aa4ee3661561a88c
7
+ data.tar.gz: b78500b50cad9faad612a8e085f4263bcac024b59fda04457751fc3fe85deae1557af6cde9c5a5c820bab7e9427c1fcb7a31ca2149369e08c8fccc41686ab535
data/Gemfile CHANGED
@@ -18,12 +18,14 @@ else
18
18
  gem "sqlite3", platform: :ruby
19
19
  end
20
20
 
21
- if rails_version >= Gem::Version.new("7.0.0")
22
- gem "rails", github: "rails/rails", branch: "7-0-stable"
21
+ if rails_version > Gem::Version.new("7.0.0")
22
+ gem "rails", github: "rails/rails"
23
23
  else
24
24
  gem "rails", "~> #{rails_version}"
25
25
  end
26
26
 
27
+ gem "mini_magick"
28
+
27
29
  gem "sprockets-rails"
28
30
 
29
31
  gem "sidekiq"
@@ -1,10 +1,10 @@
1
1
  module Sentry
2
2
  class BackgroundWorker
3
3
  def _perform(&block)
4
+ block.call
5
+ ensure
4
6
  # make sure the background worker returns AR connection if it accidentally acquire one during serialization
5
- ActiveRecord::Base.connection_pool.with_connection do
6
- block.call
7
- end
7
+ ActiveRecord::Base.connection_pool.release_connection
8
8
  end
9
9
  end
10
10
  end
@@ -20,14 +20,21 @@ module Sentry
20
20
  "rails.request".freeze
21
21
  end
22
22
 
23
- def capture_exception(exception)
23
+ def capture_exception(exception, env)
24
+ request = ActionDispatch::Request.new(env)
25
+
26
+ # the exception will be swallowed by ShowExceptions middleware
27
+ return if request.show_exceptions? && !Sentry.configuration.rails.report_rescued_exceptions
28
+
24
29
  current_scope = Sentry.get_current_scope
25
30
 
26
- if original_transaction = current_scope.rack_env["sentry.original_transaction"]
31
+ if original_transaction = env["sentry.original_transaction"]
27
32
  current_scope.set_transaction_name(original_transaction)
28
33
  end
29
34
 
30
- Sentry::Rails.capture_exception(exception)
35
+ Sentry::Rails.capture_exception(exception).tap do |event|
36
+ env[ERROR_EVENT_ID_KEY] = event.event_id if event
37
+ end
31
38
  end
32
39
 
33
40
  def start_transaction(env, scope)
@@ -39,7 +46,7 @@ module Sentry
39
46
  end
40
47
 
41
48
  transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace
42
- Sentry.start_transaction(transaction: transaction, **options)
49
+ Sentry.start_transaction(transaction: transaction, custom_sampling_context: { env: env }, **options)
43
50
  end
44
51
  end
45
52
  end
@@ -42,6 +42,12 @@ module Sentry
42
42
  'ActiveRecord::RecordNotFound'
43
43
  ].freeze
44
44
  class Configuration
45
+ # Rails 7.0 introduced a new error reporter feature, which the SDK once opted-in by default.
46
+ # But after receiving multiple issue reports, the integration seemed to cause serious troubles to some users.
47
+ # So the integration is now controlled by this configuration, which is disabled (false) by default.
48
+ # More information can be found from: https://github.com/rails/rails/pull/43625#issuecomment-1072514175
49
+ attr_accessor :register_error_subscriber
50
+
45
51
  # Rails catches exceptions in the ActionDispatch::ShowExceptions or
46
52
  # ActionDispatch::DebugExceptions middlewares, depending on the environment.
47
53
  # When `rails_report_rescued_exceptions` is true (it is by default), Sentry
@@ -55,6 +61,7 @@ module Sentry
55
61
  attr_accessor :tracing_subscribers
56
62
 
57
63
  def initialize
64
+ @register_error_subscriber = false
58
65
  @report_rescued_exceptions = true
59
66
  @skippable_job_adapters = []
60
67
  @tracing_subscribers = Set.new([
@@ -3,8 +3,17 @@ module Sentry
3
3
  # This is not a user-facing class. You should use it with Rails 7.0's error reporter feature and its interfaces.
4
4
  # See https://github.com/rails/rails/blob/main/activesupport/lib/active_support/error_reporter.rb for more information.
5
5
  class ErrorSubscriber
6
- def report(error, handled:, severity:, context:)
7
- Sentry::Rails.capture_exception(error, level: severity, contexts: { "rails.error" => context }, tags: { handled: handled })
6
+ SKIP_SOURCES = Regexp.union([/.*_cache_store.active_support/])
7
+
8
+ def report(error, handled:, severity:, context:, source: nil)
9
+ tags = { handled: handled }
10
+
11
+ if source
12
+ return if SKIP_SOURCES.match?(source)
13
+ tags[:source] = source
14
+ end
15
+
16
+ Sentry::Rails.capture_exception(error, level: severity, contexts: { "rails.error" => context }, tags: tags)
8
17
  end
9
18
  end
10
19
  end
@@ -47,12 +47,17 @@ module Sentry
47
47
  inject_breadcrumbs_logger
48
48
  activate_tracing
49
49
 
50
- register_error_subscriber(app) if ::Rails.version.to_f >= 7.0
50
+ register_error_subscriber(app) if ::Rails.version.to_f >= 7.0 && Sentry.configuration.rails.register_error_subscriber
51
51
  end
52
52
 
53
53
  runner do
54
54
  next unless Sentry.initialized?
55
55
  Sentry.configuration.background_worker_threads = 0
56
+
57
+ at_exit do
58
+ # TODO: Add a condition for Rails 7.1 to avoid confliction with https://github.com/rails/rails/pull/44999
59
+ Sentry::Rails.capture_exception($ERROR_INFO, tags: { source: "runner" }) if $ERROR_INFO
60
+ end
56
61
  end
57
62
 
58
63
  def configure_project_root
@@ -40,15 +40,12 @@ module Sentry
40
40
  def record_on_current_span(duration:, **options)
41
41
  return unless options[:start_timestamp]
42
42
 
43
- scope = Sentry.get_current_scope
44
- transaction = scope.get_transaction
45
- return unless transaction && transaction.sampled
46
-
47
- span = transaction.start_child(**options)
48
- # duration in ActiveSupport is computed in millisecond
49
- # so we need to covert it as second before calculating the timestamp
50
- span.set_timestamp(span.start_timestamp + duration / 1000)
51
- yield(span) if block_given?
43
+ Sentry.with_child_span(**options) do |child_span|
44
+ # duration in ActiveSupport is computed in millisecond
45
+ # so we need to covert it as second before calculating the timestamp
46
+ child_span.set_timestamp(child_span.start_timestamp + duration / 1000)
47
+ yield(child_span) if block_given?
48
+ end
52
49
  end
53
50
  end
54
51
  end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Rails
3
- VERSION = "5.2.1"
3
+ VERSION = "5.4.0"
4
4
  end
5
5
  end
data/sentry-rails.gemspec CHANGED
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ["lib"]
24
24
 
25
25
  spec.add_dependency "railties", ">= 5.0"
26
- spec.add_dependency "sentry-ruby-core", "~> 5.2.1"
26
+ spec.add_dependency "sentry-ruby", "~> 5.4.0"
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.1
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-18 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: sentry-ruby-core
28
+ name: sentry-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 5.2.1
33
+ version: 5.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 5.2.1
40
+ version: 5.4.0
41
41
  description: A gem that provides Rails integration for the Sentry error logger
42
42
  email: accounts@sentry.io
43
43
  executables: []