sentry-rails 4.2.1 → 4.3.3.pre.beta.0

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
2
  SHA256:
3
- metadata.gz: ab83fdc945ddfb3c5dbd4a38c34c8748acfc9745f5f9bbf39e47c188778760b6
4
- data.tar.gz: 05ac3bde183e9615d292c2c978224b06567347c4b461cd8281d4f308d2b61bdc
3
+ metadata.gz: 0eb34ee9c167f2366fce7bdacec1876ac5735bc8cce4c587c5d40f353ab1e897
4
+ data.tar.gz: 4b652a985aeae4fdf14181b4b3f5a46c7d4b0c4168241aa85efd6cb3f09fd957
5
5
  SHA512:
6
- metadata.gz: 28819d457892ae94280d5f6f5ec44e23eeec4d52f338b68ccc31ccd5f090b63a560eb9b72b626c1bb011288e9beb0e3762eb14229a6b689d8f957aaf7a0ea867
7
- data.tar.gz: 2e095079c8ea3e1f8ad552bbe0c94a0a93a87c199832cb19de2beaa242cacea95383bca18529316133949f4ba807fe0b1898783a36db26aacca74eac8c0fcf79
6
+ metadata.gz: 24fb610289426dc62e67447b4c27b7746b4dfca7283a908888ac53afdf572eb0f7071201776ae8dae3a07cde4d07ce487924ebc28639eca496ef590201fd885f
7
+ data.tar.gz: 13e584471a08019ececbf409c4e4283aace72e20a18b9b0a7e74f7fdf6ea38a1d027944d92bd8514d959e6d8361c8b6ae3c3a8dc1840e29a2dfa19f8df718480
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
+ /spec/support/test_rails_app/db
8
9
  /tmp/
9
10
 
10
11
  # rspec failure tracking
data/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.3.3-beta.0
4
+
5
+ - Minimize sentry-rails' dependency requirement [#1352](https://github.com/getsentry/sentry-ruby/pull/1352)
6
+
7
+ ## 4.3.2
8
+
9
+ - Avoid recording SendEventJob's transaction [#1351](https://github.com/getsentry/sentry-ruby/pull/1351)
10
+ - Fixes [#1348](https://github.com/getsentry/sentry-ruby/issues/1348)
11
+
12
+ ## 4.3.1
13
+
14
+ - Only apply background worker patch if ActiveRecord is loaded [#1350](https://github.com/getsentry/sentry-ruby/pull/1350)
15
+ - Fixes [#1342](https://github.com/getsentry/sentry-ruby/issues/1342) and [#1346](https://github.com/getsentry/sentry-ruby/issues/1346)
16
+
17
+ ## 4.3.0
18
+
19
+ ### Features
20
+
21
+ - Support performance monitoring on ActiveJob execution [#1304](https://github.com/getsentry/sentry-ruby/pull/1304)
22
+
23
+ ### Bug Fixes
24
+
25
+ - Prevent background workers from holding ActiveRecord connections [#1320](https://github.com/getsentry/sentry-ruby/pull/1320)
26
+
27
+ ## 4.2.2
28
+
29
+ - Always define Sentry::SendEventJob to avoid eager load issues [#1286](https://github.com/getsentry/sentry-ruby/pull/1286)
30
+ - Fixes [#1283](https://github.com/getsentry/sentry-ruby/issues/1283)
31
+
3
32
  ## 4.2.1
4
33
 
5
34
  - Add additional checks to SendEventJob's definition [#1275](https://github.com/getsentry/sentry-ruby/pull/1275)
data/Gemfile CHANGED
@@ -17,11 +17,13 @@ end
17
17
 
18
18
  gem "rails", "~> #{rails_version}"
19
19
  gem "sprockets-rails"
20
+
21
+ gem "rspec", "~> 3.0"
22
+ gem "rspec-retry"
20
23
  gem "rspec-rails", "~> 4.0"
21
24
  gem "codecov", "0.2.12"
22
25
 
23
26
  gem "rake", "~> 12.0"
24
- gem "rspec", "~> 3.0"
25
27
 
26
28
  # TODO: Remove this if https://github.com/jruby/jruby/issues/6547 is addressed
27
29
  gem "i18n", "<= 1.8.7"
@@ -1,30 +1,39 @@
1
- return unless defined?(ActiveJob)
2
-
3
- module Sentry
4
- parent_job =
5
- if defined?(::ApplicationJob) && ::ApplicationJob.ancestors.include?(::ActiveJob::Base)
6
- ::ApplicationJob
7
- else
8
- ::ActiveJob::Base
9
- end
1
+ if defined?(ActiveJob)
2
+ module Sentry
3
+ parent_job =
4
+ if defined?(::ApplicationJob) && ::ApplicationJob.ancestors.include?(::ActiveJob::Base)
5
+ ::ApplicationJob
6
+ else
7
+ ::ActiveJob::Base
8
+ end
10
9
 
11
- class SendEventJob < parent_job
12
- # the event argument is usually large and creates noise
13
- self.log_arguments = false if respond_to?(:log_arguments=)
10
+ class SendEventJob < parent_job
11
+ # the event argument is usually large and creates noise
12
+ self.log_arguments = false if respond_to?(:log_arguments=)
14
13
 
15
- # this will prevent infinite loop when there's an issue deserializing SentryJob
16
- if respond_to?(:discard_on)
17
- discard_on ActiveJob::DeserializationError
18
- else
19
- # mimic what discard_on does for Rails 5.0
20
- rescue_from ActiveJob::DeserializationError do
21
- logger.error "Discarded #{self.class} due to a #{exception}. The original exception was #{error.cause.inspect}."
14
+ # this will prevent infinite loop when there's an issue deserializing SentryJob
15
+ if respond_to?(:discard_on)
16
+ discard_on ActiveJob::DeserializationError
17
+ else
18
+ # mimic what discard_on does for Rails 5.0
19
+ rescue_from ActiveJob::DeserializationError do
20
+ logger.error "Discarded #{self.class} due to a #{exception}. The original exception was #{error.cause.inspect}."
21
+ end
22
22
  end
23
- end
24
23
 
25
- def perform(event, hint = {})
26
- Sentry.send_event(event, hint)
24
+ def perform(event, hint = {})
25
+ # users don't need the tracing result of this job
26
+ if transaction = Sentry.get_current_scope.span
27
+ transaction.instance_variable_set(:@sampled, false)
28
+ end
29
+
30
+ Sentry.send_event(event, hint)
31
+ end
27
32
  end
28
33
  end
34
+ else
35
+ module Sentry
36
+ class SendEventJob; end
37
+ end
29
38
  end
30
39
 
data/lib/sentry/rails.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "rails"
1
2
  require "sentry-ruby"
2
3
  require "sentry/integrable"
3
4
  require "sentry/rails/configuration"
@@ -8,8 +8,8 @@ module Sentry
8
8
  if already_supported_by_specific_integration?(job)
9
9
  block.call
10
10
  else
11
- Sentry.with_scope do
12
- capture_and_reraise_with_sentry(job, block)
11
+ Sentry.with_scope do |scope|
12
+ capture_and_reraise_with_sentry(job, scope, block)
13
13
  end
14
14
  end
15
15
  else
@@ -19,10 +19,18 @@ module Sentry
19
19
  end
20
20
  end
21
21
 
22
- def capture_and_reraise_with_sentry(job, block)
22
+ def capture_and_reraise_with_sentry(job, scope, block)
23
+ scope.set_transaction_name(job.class.name)
24
+ transaction = Sentry.start_transaction(name: scope.transaction_name, op: "active_job")
25
+
26
+ scope.set_span(transaction) if transaction
27
+
23
28
  block.call
29
+
30
+ finish_transaction(transaction, 200)
24
31
  rescue Exception => e # rubocop:disable Lint/RescueException
25
32
  rescue_handler_result = rescue_with_handler(e)
33
+ finish_transaction(transaction, 500)
26
34
  return rescue_handler_result if rescue_handler_result
27
35
 
28
36
  Sentry::Rails.capture_exception(
@@ -36,6 +44,13 @@ module Sentry
36
44
  raise e
37
45
  end
38
46
 
47
+ def finish_transaction(transaction, status)
48
+ return unless transaction
49
+
50
+ transaction.set_http_status(status)
51
+ transaction.finish
52
+ end
53
+
39
54
  def already_supported_by_specific_integration?(job)
40
55
  Sentry.configuration.rails.skippable_job_adapters.include?(job.class.queue_adapter.class.to_s)
41
56
  end
@@ -0,0 +1,12 @@
1
+ module Sentry
2
+ class BackgroundWorker
3
+ def perform(&block)
4
+ @executor.post do
5
+ # make sure the background worker returns AR connection if it accidentally acquire one during serialization
6
+ ActiveRecord::Base.connection_pool.with_connection do
7
+ block.call
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -29,11 +29,16 @@ module Sentry
29
29
  Sentry::Rails.capture_exception(exception)
30
30
  end
31
31
 
32
- def finish_span(span, status_code)
33
- if @assets_regex.nil? || !span.name.match?(@assets_regex)
34
- span.set_http_status(status_code)
35
- span.finish
32
+ def start_transaction(env, scope)
33
+ transaction = super
34
+
35
+ return unless transaction
36
+
37
+ if @assets_regex && transaction.name.match?(@assets_regex)
38
+ transaction.instance_variable_set(:@sampled, false)
36
39
  end
40
+
41
+ transaction
37
42
  end
38
43
  end
39
44
  end
@@ -1,11 +1,6 @@
1
- require "rails"
2
1
  require "sentry/rails/capture_exceptions"
3
2
  require "sentry/rails/rescued_exception_interceptor"
4
3
  require "sentry/rails/backtrace_cleaner"
5
- require "sentry/rails/controller_methods"
6
- require "sentry/rails/controller_transaction"
7
- require "sentry/rails/overrides/streaming_reporter"
8
- require "sentry/rails/overrides/file_handler"
9
4
 
10
5
  module Sentry
11
6
  class Railtie < ::Rails::Railtie
@@ -23,10 +18,11 @@ module Sentry
23
18
  configure_project_root
24
19
  configure_sentry_logger
25
20
  configure_trusted_proxies
26
- extend_controller_methods
21
+ extend_controller_methods if defined?(ActionController)
27
22
  extend_active_job if defined?(ActiveJob)
28
- override_streaming_reporter
29
- override_file_handler if app.config.public_file_server.enabled
23
+ patch_background_worker if defined?(ActiveRecord)
24
+ override_streaming_reporter if defined?(ActionView)
25
+ override_file_handler if defined?(ActionDispatch) && app.config.public_file_server.enabled
30
26
  setup_backtrace_cleanup_callback
31
27
  inject_breadcrumbs_logger
32
28
  activate_tracing
@@ -50,6 +46,10 @@ module Sentry
50
46
  end
51
47
 
52
48
  def extend_controller_methods
49
+ require "sentry/rails/controller_methods"
50
+ require "sentry/rails/controller_transaction"
51
+ require "sentry/rails/overrides/streaming_reporter"
52
+
53
53
  ActiveSupport.on_load :action_controller do
54
54
  include Sentry::Rails::ControllerMethods
55
55
  include Sentry::Rails::ControllerTransaction
@@ -57,6 +57,10 @@ module Sentry
57
57
  end
58
58
  end
59
59
 
60
+ def patch_background_worker
61
+ require "sentry/rails/background_worker"
62
+ end
63
+
60
64
  def inject_breadcrumbs_logger
61
65
  if Sentry.configuration.breadcrumbs_logger.include?(:active_support_logger)
62
66
  require 'sentry/rails/breadcrumb/active_support_logger'
@@ -73,12 +77,16 @@ module Sentry
73
77
  end
74
78
 
75
79
  def override_streaming_reporter
80
+ require "sentry/rails/overrides/streaming_reporter"
81
+
76
82
  ActiveSupport.on_load :action_view do
77
83
  ActionView::StreamingTemplateRenderer::Body.send(:prepend, Sentry::Rails::Overrides::StreamingReporter)
78
84
  end
79
85
  end
80
86
 
81
87
  def override_file_handler
88
+ require "sentry/rails/overrides/file_handler"
89
+
82
90
  ActiveSupport.on_load :action_controller do
83
91
  ActionDispatch::FileHandler.send(:prepend, Sentry::Rails::Overrides::FileHandler)
84
92
  end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Rails
3
- VERSION = "4.2.1"
3
+ VERSION = "4.3.3-beta.0"
4
4
  end
5
5
  end
data/sentry-rails.gemspec CHANGED
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "rails", ">= 5.0"
26
- spec.add_dependency "sentry-ruby-core", "~> 4.2.0"
25
+ spec.add_dependency "railties", ">= 5.0"
26
+ spec.add_dependency "sentry-ruby-core", "~> 4.3.0"
27
27
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.1
4
+ version: 4.3.3.pre.beta.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: 2021-02-10 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 4.2.0
33
+ version: 4.3.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: 4.2.0
40
+ version: 4.3.0
41
41
  description: A gem that provides Rails integration for the Sentry error logger
42
42
  email: accounts@sentry.io
43
43
  executables: []
@@ -62,6 +62,7 @@ files:
62
62
  - lib/sentry-rails.rb
63
63
  - lib/sentry/rails.rb
64
64
  - lib/sentry/rails/active_job.rb
65
+ - lib/sentry/rails/background_worker.rb
65
66
  - lib/sentry/rails/backtrace_cleaner.rb
66
67
  - lib/sentry/rails/breadcrumb/active_support_logger.rb
67
68
  - lib/sentry/rails/capture_exceptions.rb
@@ -98,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
99
  version: '2.4'
99
100
  required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  requirements:
101
- - - ">="
102
+ - - ">"
102
103
  - !ruby/object:Gem::Version
103
- version: '0'
104
+ version: 1.3.1
104
105
  requirements: []
105
106
  rubygems_version: 3.0.3
106
107
  signing_key: