sentry-rails 4.2.0 → 4.3.2

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: 88b2f50f7497ed668cc86fda80d8bbd653e3e01b3a7d3c3f7643e5de81de697c
4
- data.tar.gz: e2ee2b20c9a85f947f4fcfe4f5c68b82226336aa54c73b5c116e767307bb4cd0
3
+ metadata.gz: 71d4bb2da0b6b6702dd19f4af1587d708d1cd74dabff09bb1419544851de273b
4
+ data.tar.gz: 306860e508e67cd7ba564dac54111c9bfac796ff6e7a96092cdba22e03c4336b
5
5
  SHA512:
6
- metadata.gz: 1c86549b0348fec623ed863f9f11147d6cf04c20a7c8cd4ba96755959084f8d8436a8ee768edf5011230b7dfe62155aafcca7f1aaebf298a30d2dff1799c9310
7
- data.tar.gz: f6ee86657ef5960e22fe72c826b86ee0992a16769416429ab791821b2d974672ebe83d3c8fead135554ad2acdda6c0f59ad4a1c291d0ae3e6e7dc8d1584dfee4
6
+ metadata.gz: 5ef3910fbe7c2ab373e0642949d7d82babb83e0569cdd7481e423346fa89b26b26426d9175137e0293be99152c27489978ac4c02d29539de5ef0e386f4b31bcc
7
+ data.tar.gz: b36840b16c8c46ddc1e8d5036135a250f5d2f391cbc94916b85dda206fd17b68194192625d0c4a89e86ae0ef8e5ba8288083e897eb533bfa8c7f5303650de04b
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,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.3.2
4
+
5
+ - Avoid recording SendEventJob's transaction [#1351](https://github.com/getsentry/sentry-ruby/pull/1351)
6
+ - Fixes [#1348](https://github.com/getsentry/sentry-ruby/issues/1348)
7
+
8
+ ## 4.3.1
9
+
10
+ - Only apply background worker patch if ActiveRecord is loaded [#1350](https://github.com/getsentry/sentry-ruby/pull/1350)
11
+ - Fixes [#1342](https://github.com/getsentry/sentry-ruby/issues/1342) and [#1346](https://github.com/getsentry/sentry-ruby/issues/1346)
12
+ - Avoid recording SendEventJob's transaction [#1351](https://github.com/getsentry/sentry-ruby/pull/1351)
13
+ - Fixes [#1348](https://github.com/getsentry/sentry-ruby/issues/1348)
14
+
15
+ ## 4.3.0
16
+
17
+ ### Features
18
+
19
+ - Support performance monitoring on ActiveJob execution [#1304](https://github.com/getsentry/sentry-ruby/pull/1304)
20
+
21
+ ### Bug Fixes
22
+
23
+ - Prevent background workers from holding ActiveRecord connections [#1320](https://github.com/getsentry/sentry-ruby/pull/1320)
24
+
25
+ ## 4.2.2
26
+
27
+ - Always define Sentry::SendEventJob to avoid eager load issues [#1286](https://github.com/getsentry/sentry-ruby/pull/1286)
28
+ - Fixes [#1283](https://github.com/getsentry/sentry-ruby/issues/1283)
29
+
30
+ ## 4.2.1
31
+
32
+ - Add additional checks to SendEventJob's definition [#1275](https://github.com/getsentry/sentry-ruby/pull/1275)
33
+ - Fixes [#1270](https://github.com/getsentry/sentry-ruby/issues/1270)
34
+ - Fixes [#1277](https://github.com/getsentry/sentry-ruby/issues/1277)
35
+
3
36
  ## 4.2.0
4
37
 
5
38
  ### Features
data/Gemfile CHANGED
@@ -8,15 +8,22 @@ rails_version = "6.1.0" if rails_version.nil?
8
8
 
9
9
  gem 'activerecord-jdbcmysql-adapter', platform: :jruby
10
10
  gem "jdbc-sqlite3", platform: :jruby
11
- gem "sqlite3", platform: :ruby
11
+
12
+ if rails_version.to_f < 6
13
+ gem "sqlite3", "~> 1.3.0", platform: :ruby
14
+ else
15
+ gem "sqlite3", platform: :ruby
16
+ end
12
17
 
13
18
  gem "rails", "~> #{rails_version}"
14
19
  gem "sprockets-rails"
20
+
21
+ gem "rspec", "~> 3.0"
22
+ gem "rspec-retry"
15
23
  gem "rspec-rails", "~> 4.0"
16
24
  gem "codecov", "0.2.12"
17
25
 
18
26
  gem "rake", "~> 12.0"
19
- gem "rspec", "~> 3.0"
20
27
 
21
28
  # TODO: Remove this if https://github.com/jruby/jruby/issues/6547 is addressed
22
29
  gem "i18n", "<= 1.8.7"
@@ -1,20 +1,39 @@
1
- return unless defined?(ActiveJob)
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
2
9
 
3
- module Sentry
4
- parent_job =
5
- if defined?(ApplicationJob)
6
- ApplicationJob
7
- else
8
- ActiveJob::Base
9
- end
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=)
13
+
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
+ end
10
23
 
11
- class SendEventJob < parent_job
12
- self.log_arguments = false if ::Rails.version.to_f >= 6.1
13
- discard_on ActiveJob::DeserializationError # this will prevent infinite loop when there's an issue deserializing SentryJob
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
14
29
 
15
- def perform(event, hint = {})
16
- Sentry.send_event(event, hint)
30
+ Sentry.send_event(event, hint)
31
+ end
17
32
  end
18
33
  end
34
+ else
35
+ module Sentry
36
+ class SendEventJob; end
37
+ end
19
38
  end
20
39
 
@@ -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
@@ -25,6 +25,7 @@ module Sentry
25
25
  configure_trusted_proxies
26
26
  extend_controller_methods
27
27
  extend_active_job if defined?(ActiveJob)
28
+ patch_background_worker if defined?(ActiveRecord)
28
29
  override_streaming_reporter
29
30
  override_file_handler if app.config.public_file_server.enabled
30
31
  setup_backtrace_cleanup_callback
@@ -57,6 +58,10 @@ module Sentry
57
58
  end
58
59
  end
59
60
 
61
+ def patch_background_worker
62
+ require "sentry/rails/background_worker"
63
+ end
64
+
60
65
  def inject_breadcrumbs_logger
61
66
  if Sentry.configuration.breadcrumbs_logger.include?(:active_support_logger)
62
67
  require 'sentry/rails/breadcrumb/active_support_logger'
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Rails
3
- VERSION = "4.2.0"
3
+ VERSION = "4.3.2"
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 "rails", ">= 5.0"
26
- spec.add_dependency "sentry-ruby-core", "~> 4.2.0"
26
+ spec.add_dependency "sentry-ruby-core", "~> 4.3.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: 4.2.0
4
+ version: 4.3.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: 2021-02-04 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -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