sentry-rails 4.1.7 → 4.3.1

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: 1e101fa2f42e1bf68db025a8c02a391ee510cfb43d286c63156397efcbcc1f6a
4
- data.tar.gz: 8673fc2ff559d18b09c41b05e373116feb1ae7b04cbe4de5f99637afaf05c8da
3
+ metadata.gz: 7ecadcb6d10a87fe8d032001ac1b970da69e7037f4b7a6d7378992ae2b232258
4
+ data.tar.gz: 2a517ac4894d2dfdbe9e626fee8bfe11f5b984204598c22f082daeac9c4e7995
5
5
  SHA512:
6
- metadata.gz: 156a36ae19a647b1b17e4278108296356339363f659d714b24dfcc095c14d59ae01ef85bc08c0c1a3331e401522bd7130214432a2a931f40fdeedff0ef6a0bcb
7
- data.tar.gz: 897b9c2f0d82266b2725cbbd30bd8478fda5e1c3dae80927e6e3f73917d8ab417066c1be545b552a39d1ed6560f5ca8c16e0247cbf3199d3cabe110f41cd175c
6
+ metadata.gz: f5ab30a925984910229746fc86f03f217198f3eb28fae3f0348c2fa876c227558aab0bdde1aa572c88f8f9b5452c317089851bd5de6859c2f249756d611a0015
7
+ data.tar.gz: b4b59011dd1d8142453c2dc5794b6cc6a8b6c350afd0f41109f85ca00390b4a19f7131874daae57cfc458ad14d0ff2bea78cbd34a5a3dff0dcf25bb92e4a139b
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,68 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.3.1
4
+
5
+ - Only apply background worker patch if ActiveRecord is loaded [#1350](https://github.com/getsentry/sentry-ruby/pull/1350)
6
+ - Fixes [#1342](https://github.com/getsentry/sentry-ruby/issues/1342) and [#1346](https://github.com/getsentry/sentry-ruby/issues/1346)
7
+
8
+ ## 4.3.0
9
+
10
+ ### Features
11
+
12
+ - Support performance monitoring on ActiveJob execution [#1304](https://github.com/getsentry/sentry-ruby/pull/1304)
13
+
14
+ ### Bug Fixes
15
+
16
+ - Prevent background workers from holding ActiveRecord connections [#1320](https://github.com/getsentry/sentry-ruby/pull/1320)
17
+
18
+ ## 4.2.2
19
+
20
+ - Always define Sentry::SendEventJob to avoid eager load issues [#1286](https://github.com/getsentry/sentry-ruby/pull/1286)
21
+ - Fixes [#1283](https://github.com/getsentry/sentry-ruby/issues/1283)
22
+
23
+ ## 4.2.1
24
+
25
+ - Add additional checks to SendEventJob's definition [#1275](https://github.com/getsentry/sentry-ruby/pull/1275)
26
+ - Fixes [#1270](https://github.com/getsentry/sentry-ruby/issues/1270)
27
+ - Fixes [#1277](https://github.com/getsentry/sentry-ruby/issues/1277)
28
+
29
+ ## 4.2.0
30
+
31
+ ### Features
32
+
33
+ - Make sentry-rails a Rails engine and provide default job class for async [#1181](https://github.com/getsentry/sentry-ruby/pull/1181)
34
+
35
+ `sentry-rails` now provides a default ActiveJob class for sending events asynchronously. You can use it directly without define your own one:
36
+
37
+ ```ruby
38
+ config.async = lambda { |event, hint| Sentry::SendEventJob.perform_later(event, hint) }
39
+ ```
40
+
41
+ - Add configuration option for trusted proxies [#1126](https://github.com/getsentry/sentry-ruby/pull/1126)
42
+
43
+ `sentry-rails` now injects `Rails.application.config.action_dispatch.trusted_proxies` into `Sentry.configuration.trusted_proxies` automatically.
44
+
45
+ - Allow users to configure ActiveJob adapters to ignore [#1256](https://github.com/getsentry/sentry-ruby/pull/1256)
46
+
47
+ ```ruby
48
+ # sentry-rails will skip active_job reporting for jobs that use ActiveJob::QueueAdapters::SidekiqAdapter
49
+ # you should use this option when:
50
+ # - you don't want to see events from a certain adapter
51
+ # - you already have a better reporting setup for the adapter (like having `sentry-sidekiq` installed)
52
+ config.rails.skippable_job_adapters = ["ActiveJob::QueueAdapters::SidekiqAdapter"]
53
+ ```
54
+
55
+ - Tag `job_id` and `provider_job_id` on ActiveJob events [#1259](https://github.com/getsentry/sentry-ruby/pull/1259)
56
+
57
+ <img width="1330" alt="example of tagged event" src="https://user-images.githubusercontent.com/5079556/106389781-3a03f100-6420-11eb-810c-a99869eb26dd.png">
58
+
59
+ - Use another method for post initialization callback [#1261](https://github.com/getsentry/sentry-ruby/pull/1261)
60
+
61
+ ### Bug Fixes
62
+
63
+ - Inspect exception cause by default & don't exclude ActiveJob::DeserializationError [#1180](https://github.com/getsentry/sentry-ruby/pull/1180)
64
+ - Fixes [#1071](https://github.com/getsentry/sentry-ruby/issues/1071)
65
+
3
66
  ## 4.1.7
4
67
 
5
68
  - Use env to carry original transaction name [#1255](https://github.com/getsentry/sentry-ruby/pull/1255)
@@ -75,4 +138,3 @@ Release test
75
138
  ## 0.1.0
76
139
 
77
140
  First version
78
-
data/Gemfile CHANGED
@@ -8,15 +8,25 @@ 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"
27
+
28
+ # TODO: Remove this if https://github.com/jruby/jruby/issues/6547 is addressed
29
+ gem "i18n", "<= 1.8.7"
20
30
 
21
31
  gem "sidekiq"
22
32
 
@@ -0,0 +1,34 @@
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
9
+
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
23
+
24
+ def perform(event, hint = {})
25
+ Sentry.send_event(event, hint)
26
+ end
27
+ end
28
+ end
29
+ else
30
+ module Sentry
31
+ class SendEventJob; end
32
+ end
33
+ end
34
+
data/lib/sentry/rails.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "sentry-ruby"
2
2
  require "sentry/integrable"
3
3
  require "sentry/rails/configuration"
4
+ require "sentry/rails/engine"
4
5
  require "sentry/rails/railtie"
5
6
  require "sentry/rails/tracing"
6
7
 
@@ -1,10 +1,6 @@
1
1
  module Sentry
2
2
  module Rails
3
3
  module ActiveJobExtensions
4
- ALREADY_SUPPORTED_SENTRY_ADAPTERS = %w(
5
- ActiveJob::QueueAdapters::SidekiqAdapter
6
- ).freeze
7
-
8
4
  def self.included(base)
9
5
  base.class_eval do
10
6
  around_perform do |job, block|
@@ -12,8 +8,8 @@ module Sentry
12
8
  if already_supported_by_specific_integration?(job)
13
9
  block.call
14
10
  else
15
- Sentry.with_scope do
16
- capture_and_reraise_with_sentry(job, block)
11
+ Sentry.with_scope do |scope|
12
+ capture_and_reraise_with_sentry(job, scope, block)
17
13
  end
18
14
  end
19
15
  else
@@ -23,34 +19,51 @@ module Sentry
23
19
  end
24
20
  end
25
21
 
26
- 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
+
27
28
  block.call
29
+
30
+ finish_transaction(transaction, 200)
28
31
  rescue Exception => e # rubocop:disable Lint/RescueException
29
32
  rescue_handler_result = rescue_with_handler(e)
33
+ finish_transaction(transaction, 500)
30
34
  return rescue_handler_result if rescue_handler_result
31
35
 
32
- Sentry::Rails.capture_exception(e, extra: sentry_context(job))
36
+ Sentry::Rails.capture_exception(
37
+ e,
38
+ extra: sentry_context(job),
39
+ tags: {
40
+ job_id: job.job_id,
41
+ provider_job_id: job.provider_job_id
42
+ }
43
+ )
33
44
  raise e
34
45
  end
35
46
 
47
+ def finish_transaction(transaction, status)
48
+ return unless transaction
49
+
50
+ transaction.set_http_status(status)
51
+ transaction.finish
52
+ end
53
+
36
54
  def already_supported_by_specific_integration?(job)
37
- ALREADY_SUPPORTED_SENTRY_ADAPTERS.include?(job.class.queue_adapter.class.to_s)
55
+ Sentry.configuration.rails.skippable_job_adapters.include?(job.class.queue_adapter.class.to_s)
38
56
  end
39
57
 
40
58
  def sentry_context(job)
41
- ctx = {
42
- :active_job => job.class.name,
43
- :arguments => job.arguments,
44
- :scheduled_at => job.scheduled_at,
45
- :job_id => job.job_id,
46
- :locale => job.locale
59
+ {
60
+ active_job: job.class.name,
61
+ arguments: job.arguments,
62
+ scheduled_at: job.scheduled_at,
63
+ job_id: job.job_id,
64
+ provider_job_id: job.provider_job_id,
65
+ locale: job.locale
47
66
  }
48
- # Add provider_job_id details if Rails 5
49
- if job.respond_to?(:provider_job_id)
50
- ctx[:provider_job_id] = job.provider_job_id
51
- end
52
-
53
- ctx
54
67
  end
55
68
  end
56
69
  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
@@ -2,7 +2,7 @@ module Sentry
2
2
  class Configuration
3
3
  attr_reader :rails
4
4
 
5
- def post_initialization_callback
5
+ add_post_initialization_callback do
6
6
  @rails = Sentry::Rails::Configuration.new
7
7
  @excluded_exceptions = @excluded_exceptions.concat(Sentry::Rails::IGNORE_DEFAULT)
8
8
  end
@@ -23,7 +23,6 @@ module Sentry
23
23
  'ActionDispatch::Http::MimeNegotiation::InvalidType',
24
24
  'ActionController::UnknownHttpMethod',
25
25
  'ActionDispatch::Http::Parameters::ParseError',
26
- 'ActiveJob::DeserializationError', # Can cause infinite loops
27
26
  'ActiveRecord::RecordNotFound'
28
27
  ].freeze
29
28
  class Configuration
@@ -33,8 +32,14 @@ module Sentry
33
32
  # will report exceptions even when they are rescued by these middlewares.
34
33
  attr_accessor :report_rescued_exceptions
35
34
 
35
+ # Some adapters, like sidekiq, already have their own sentry integration.
36
+ # In those cases, we should skip ActiveJob's reporting to avoid duplicated reports.
37
+ attr_accessor :skippable_job_adapters
38
+
36
39
  def initialize
37
40
  @report_rescued_exceptions = true
41
+ # TODO: Remove this in 4.2.0
42
+ @skippable_job_adapters = []
38
43
  end
39
44
  end
40
45
  end
@@ -0,0 +1,5 @@
1
+ module Sentry
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Sentry
4
+ end
5
+ end
@@ -22,8 +22,10 @@ module Sentry
22
22
 
23
23
  configure_project_root
24
24
  configure_sentry_logger
25
+ configure_trusted_proxies
25
26
  extend_controller_methods
26
27
  extend_active_job if defined?(ActiveJob)
28
+ patch_background_worker if defined?(ActiveRecord)
27
29
  override_streaming_reporter
28
30
  override_file_handler if app.config.public_file_server.enabled
29
31
  setup_backtrace_cleanup_callback
@@ -39,6 +41,10 @@ module Sentry
39
41
  Sentry.configuration.logger = ::Rails.logger
40
42
  end
41
43
 
44
+ def configure_trusted_proxies
45
+ Sentry.configuration.trusted_proxies += Array(::Rails.application.config.action_dispatch.trusted_proxies)
46
+ end
47
+
42
48
  def extend_active_job
43
49
  require "sentry/rails/active_job"
44
50
  ActiveJob::Base.send(:prepend, Sentry::Rails::ActiveJobExtensions)
@@ -52,6 +58,10 @@ module Sentry
52
58
  end
53
59
  end
54
60
 
61
+ def patch_background_worker
62
+ require "sentry/rails/background_worker"
63
+ end
64
+
55
65
  def inject_breadcrumbs_logger
56
66
  if Sentry.configuration.breadcrumbs_logger.include?(:active_support_logger)
57
67
  require 'sentry/rails/breadcrumb/active_support_logger'
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Rails
3
- VERSION = "4.1.7"
3
+ VERSION = "4.3.1"
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.1.2"
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.1.7
4
+ version: 4.3.1
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-01 00:00:00.000000000 Z
11
+ date: 2021-03-19 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.1.2
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.1.2
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: []
@@ -56,17 +56,20 @@ files:
56
56
  - Makefile
57
57
  - README.md
58
58
  - Rakefile
59
+ - app/jobs/sentry/send_event_job.rb
59
60
  - bin/console
60
61
  - bin/setup
61
62
  - lib/sentry-rails.rb
62
63
  - lib/sentry/rails.rb
63
64
  - lib/sentry/rails/active_job.rb
65
+ - lib/sentry/rails/background_worker.rb
64
66
  - lib/sentry/rails/backtrace_cleaner.rb
65
67
  - lib/sentry/rails/breadcrumb/active_support_logger.rb
66
68
  - lib/sentry/rails/capture_exceptions.rb
67
69
  - lib/sentry/rails/configuration.rb
68
70
  - lib/sentry/rails/controller_methods.rb
69
71
  - lib/sentry/rails/controller_transaction.rb
72
+ - lib/sentry/rails/engine.rb
70
73
  - lib/sentry/rails/overrides/file_handler.rb
71
74
  - lib/sentry/rails/overrides/streaming_reporter.rb
72
75
  - lib/sentry/rails/railtie.rb