sentry-rails 4.3.4 → 4.5.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: 48f0349352e2f19b3be18c7ea0e5b7a600ad72d01ed1d2ce4052e55b7df471c3
4
- data.tar.gz: 7f2c6d5f3e2f2ec40cd797e81856951beced5fde6897cc993dfa8c2046ba7800
3
+ metadata.gz: 1e0dee67e1b51a9ca85ea36f5d740b94f1fc343c5fdc2b7dc04d3ae31a49559e
4
+ data.tar.gz: 332e269d839197cf59059a14c80ec59408b9d3d4fbac68b49fa3fb96f570f2ca
5
5
  SHA512:
6
- metadata.gz: 0eef4c4a1a50168a669fdf786f78842ca45c6c0d04e1ec1b9f783ad86f0a70bf94a40b6207ab8334a6cfaec953bdbdbe7dc8f04c3301dbf62a02656ebb0e24b8
7
- data.tar.gz: c5d28ee621ed6ad90a520a6e5c8fce8047a38907a493c706c5bb9f77304884b70e0564ddc90689214a0e919e6a8f6ea5d3ecbfea44de3c32bf934a74dd9459ec
6
+ metadata.gz: 4240894f140b915157eb8984c7c5c8d468212bb04162e35b7f1d162771bbe51e693dfacf3056c15f4d046a66f2f17c069d4fd948a1e0005731629f603cc56398
7
+ data.tar.gz: 670f13e2bd13862784fec3fc91fd6ed6c9c2291a9fa285b55bdaa113557919fdce60258d8c869dc679d152f033f63dad7c87456bca7ad09438d85418d0b2c21a
data/.craft.yml CHANGED
@@ -11,9 +11,9 @@ artifactProvider:
11
11
  name: github
12
12
  targets:
13
13
  - name: gem
14
- - name: github
15
- tagPrefix: sentry-rails-v
16
14
  - name: registry
17
15
  type: sdk
18
16
  config:
19
17
  canonical: 'gem:sentry-rails'
18
+ - name: github
19
+ tagPrefix: sentry-rails-v
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ Individual gem's changelog has been deprecated. Please check the [project changelog](https://github.com/getsentry/sentry-ruby/blob/master/CHANGELOG.md).
4
+
5
+ ## 4.4.0
6
+
7
+ ### Features
8
+
9
+ - Make tracing subscribers configurable [#1344](https://github.com/getsentry/sentry-ruby/pull/1344)
10
+
11
+ ```ruby
12
+ # current default:
13
+ # - Sentry::Rails::Tracing::ActionControllerSubscriber
14
+ # - Sentry::Rails::Tracing::ActionViewSubscriber
15
+ # - Sentry::Rails::Tracing::ActiveRecordSubscriber
16
+
17
+ # you can add a new subscriber
18
+ config.rails.tracing_subscribers << MySubscriber
19
+ # or replace the set completely
20
+ config.rails.tracing_subscribers = [MySubscriber]
21
+ ```
22
+
23
+ ### Bug Fixes
24
+
25
+ - Report exceptions from the interceptor middleware for exceptions app [#1379](https://github.com/getsentry/sentry-ruby/pull/1379)
26
+ - Fixes [#1371](https://github.com/getsentry/sentry-ruby/issues/1371)
27
+ - Re-position CaptureExceptions middleware to reduce tracing noise [#1405](https://github.com/getsentry/sentry-ruby/pull/1405)
28
+
3
29
  ## 4.3.4
4
30
 
5
31
  - Don't assign Rails.logger if it's not present [#1387](https://github.com/getsentry/sentry-ruby/pull/1387)
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in sentry-ruby.gemspec
4
4
  gemspec
5
+ gem "sentry-ruby", path: "../sentry-ruby"
5
6
 
6
7
  rails_version = ENV["RAILS_VERSION"]
7
8
  rails_version = "6.1.0" if rails_version.nil?
@@ -18,6 +19,8 @@ end
18
19
  gem "rails", "~> #{rails_version}"
19
20
  gem "sprockets-rails"
20
21
 
22
+ gem "sidekiq"
23
+
21
24
  gem "rspec", "~> 3.0"
22
25
  gem "rspec-retry"
23
26
  gem "rspec-rails", "~> 4.0"
@@ -25,13 +28,8 @@ gem "codecov", "0.2.12"
25
28
 
26
29
  gem "rake", "~> 12.0"
27
30
 
28
- # TODO: Remove this if https://github.com/jruby/jruby/issues/6547 is addressed
29
- gem "i18n", "<= 1.8.7"
30
-
31
- gem "sidekiq"
32
-
33
- gem "sentry-ruby", path: "../sentry-ruby"
34
-
31
+ gem "object_tracer"
32
+ gem "debug", github: "ruby/debug" if RUBY_VERSION.to_f >= 2.6
35
33
  gem "pry"
36
34
 
37
35
  gem "benchmark-ips"
@@ -1,9 +1,11 @@
1
+ require "sentry/rails/instrument_payload_cleanup_helper"
2
+
1
3
  module Sentry
2
4
  module Rails
3
5
  module Breadcrumb
4
6
  module ActiveSupportLogger
5
7
  class << self
6
- IGNORED_DATA_TYPES = [:request, :headers, :exception, :exception_object]
8
+ include InstrumentPayloadCleanupHelper
7
9
 
8
10
  def add(name, started, _finished, _unique_id, data)
9
11
  # skip Rails' internal events
@@ -23,12 +25,6 @@ module Sentry
23
25
  Sentry.add_breadcrumb(crumb)
24
26
  end
25
27
 
26
- def cleanup_data(data)
27
- IGNORED_DATA_TYPES.each do |key|
28
- data.delete(key) if data.key?(key)
29
- end
30
- end
31
-
32
28
  def inject
33
29
  @subscriber = ::ActiveSupport::Notifications.subscribe(/.*/) do |name, started, finished, unique_id, data|
34
30
  # we only record events that has a started timestamp
@@ -12,6 +12,7 @@ module Sentry
12
12
  private
13
13
 
14
14
  def collect_exception(env)
15
+ return nil if env["sentry.already_captured"]
15
16
  super || env["action_dispatch.exception"] || env["sentry.rescued_exception"]
16
17
  end
17
18
 
@@ -30,15 +31,15 @@ module Sentry
30
31
  end
31
32
 
32
33
  def start_transaction(env, scope)
33
- transaction = super
34
+ sentry_trace = env["HTTP_SENTRY_TRACE"]
35
+ options = { name: scope.transaction_name, op: transaction_op }
34
36
 
35
- return unless transaction
36
-
37
- if @assets_regex && transaction.name.match?(@assets_regex)
38
- transaction.instance_variable_set(:@sampled, false)
37
+ if @assets_regex && scope.transaction_name.match?(@assets_regex)
38
+ options.merge!(sampled: false)
39
39
  end
40
40
 
41
- transaction
41
+ transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace
42
+ Sentry.start_transaction(transaction: transaction, **options)
42
43
  end
43
44
  end
44
45
  end
@@ -1,3 +1,7 @@
1
+ require "sentry/rails/tracing/action_controller_subscriber"
2
+ require "sentry/rails/tracing/action_view_subscriber"
3
+ require "sentry/rails/tracing/active_record_subscriber"
4
+
1
5
  module Sentry
2
6
  class Configuration
3
7
  attr_reader :rails
@@ -47,10 +51,16 @@ module Sentry
47
51
  # In those cases, we should skip ActiveJob's reporting to avoid duplicated reports.
48
52
  attr_accessor :skippable_job_adapters
49
53
 
54
+ attr_accessor :tracing_subscribers
55
+
50
56
  def initialize
51
57
  @report_rescued_exceptions = true
52
- # TODO: Remove this in 4.2.0
53
58
  @skippable_job_adapters = []
59
+ @tracing_subscribers = Set.new([
60
+ Sentry::Rails::Tracing::ActionControllerSubscriber,
61
+ Sentry::Rails::Tracing::ActionViewSubscriber,
62
+ Sentry::Rails::Tracing::ActiveRecordSubscriber
63
+ ])
54
64
  end
55
65
  end
56
66
  end
@@ -0,0 +1,13 @@
1
+ module Sentry
2
+ module Rails
3
+ module InstrumentPayloadCleanupHelper
4
+ IGNORED_DATA_TYPES = [:request, :response, :headers, :exception, :exception_object]
5
+
6
+ def cleanup_data(data)
7
+ IGNORED_DATA_TYPES.each do |key|
8
+ data.delete(key) if data.key?(key)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -6,27 +6,37 @@ module Sentry
6
6
  class Railtie < ::Rails::Railtie
7
7
  # middlewares can't be injected after initialize
8
8
  initializer "sentry.use_rack_middleware" do |app|
9
- # need to be placed at first to capture as many errors as possible
10
- app.config.middleware.insert 0, Sentry::Rails::CaptureExceptions
9
+ # placed after all the file-sending middlewares so we can avoid unnecessary transactions
10
+ app.config.middleware.insert_after ActionDispatch::Executor, Sentry::Rails::CaptureExceptions
11
11
  # need to be placed at last to smuggle app exceptions via env
12
12
  app.config.middleware.use(Sentry::Rails::RescuedExceptionInterceptor)
13
13
  end
14
14
 
15
+ # because the extension works by registering the around_perform callcack, it should always be ran
16
+ # before the application is eager-loaded (before user's jobs register their own callbacks)
17
+ # See https://github.com/getsentry/sentry-ruby/issues/1249#issuecomment-853871871 for the detail explanation
18
+ initializer "sentry.extend_active_job", before: :eager_load! do |app|
19
+ extend_active_job if defined?(ActiveJob)
20
+ end
21
+
15
22
  config.after_initialize do |app|
16
23
  next unless Sentry.initialized?
17
24
 
18
25
  configure_project_root
19
26
  configure_trusted_proxies
20
27
  extend_controller_methods if defined?(ActionController)
21
- extend_active_job if defined?(ActiveJob)
22
28
  patch_background_worker if defined?(ActiveRecord)
23
29
  override_streaming_reporter if defined?(ActionView)
24
- override_file_handler if defined?(ActionDispatch) && app.config.public_file_server.enabled
25
30
  setup_backtrace_cleanup_callback
26
31
  inject_breadcrumbs_logger
27
32
  activate_tracing
28
33
  end
29
34
 
35
+ runner do
36
+ next unless Sentry.initialized?
37
+ Sentry.configuration.background_worker_threads = 0
38
+ end
39
+
30
40
  def configure_project_root
31
41
  Sentry.configuration.project_root = ::Rails.root.to_s
32
42
  end
@@ -79,16 +89,10 @@ module Sentry
79
89
  end
80
90
  end
81
91
 
82
- def override_file_handler
83
- require "sentry/rails/overrides/file_handler"
84
-
85
- ActiveSupport.on_load :action_controller do
86
- ActionDispatch::FileHandler.send(:prepend, Sentry::Rails::Overrides::FileHandler)
87
- end
88
- end
89
-
90
92
  def activate_tracing
91
93
  if Sentry.configuration.tracing_enabled?
94
+ subscribers = Sentry.configuration.rails.tracing_subscribers
95
+ Sentry::Rails::Tracing.register_subscribers(subscribers)
92
96
  Sentry::Rails::Tracing.subscribe_tracing_events
93
97
  Sentry::Rails::Tracing.patch_active_support_notifications
94
98
  end
@@ -20,12 +20,21 @@ module Sentry
20
20
  copied_env = scope.rack_env.dup
21
21
  copied_env["sentry.original_transaction"] = scope.transaction_name
22
22
  scope.set_rack_env(copied_env)
23
+
24
+ if report_rescued_exceptions?
25
+ Sentry::Rails.capture_exception(e)
26
+ env["sentry.already_captured"] = true
27
+ end
23
28
  end
24
29
 
25
- env["sentry.rescued_exception"] = e if Sentry.configuration.rails.report_rescued_exceptions
30
+ env["sentry.rescued_exception"] = e if report_rescued_exceptions?
26
31
  raise e
27
32
  end
28
33
  end
34
+
35
+ def report_rescued_exceptions?
36
+ Sentry.configuration.rails.report_rescued_exceptions
37
+ end
29
38
  end
30
39
  end
31
40
  end
@@ -1,18 +1,19 @@
1
- require "sentry/rails/tracing/abstract_subscriber"
2
- require "sentry/rails/tracing/active_record_subscriber"
3
- require "sentry/rails/tracing/action_controller_subscriber"
4
- require "sentry/rails/tracing/action_view_subscriber"
5
-
6
1
  module Sentry
7
2
  module Rails
8
3
  module Tracing
9
- AVAILABLE_SUBSCRIBERS = [ActionViewSubscriber, ActiveRecordSubscriber, ActionControllerSubscriber]
4
+ def self.register_subscribers(subscribers)
5
+ @subscribers = subscribers
6
+ end
7
+
8
+ def self.subscribers
9
+ @subscribers
10
+ end
10
11
 
11
12
  def self.subscribe_tracing_events
12
13
  # need to avoid duplicated subscription
13
14
  return if @subscribed
14
15
 
15
- AVAILABLE_SUBSCRIBERS.each(&:subscribe!)
16
+ subscribers.each(&:subscribe!)
16
17
 
17
18
  @subscribed = true
18
19
  end
@@ -20,7 +21,7 @@ module Sentry
20
21
  def self.unsubscribe_tracing_events
21
22
  return unless @subscribed
22
23
 
23
- AVAILABLE_SUBSCRIBERS.each(&:unsubscribe!)
24
+ subscribers.each(&:unsubscribe!)
24
25
 
25
26
  @subscribed = false
26
27
  end
@@ -1,7 +1,12 @@
1
+ require "sentry/rails/tracing/abstract_subscriber"
2
+ require "sentry/rails/instrument_payload_cleanup_helper"
3
+
1
4
  module Sentry
2
5
  module Rails
3
6
  module Tracing
4
7
  class ActionControllerSubscriber < AbstractSubscriber
8
+ extend InstrumentPayloadCleanupHelper
9
+
5
10
  EVENT_NAME = "process_action.action_controller".freeze
6
11
 
7
12
  def self.subscribe!
@@ -16,8 +21,7 @@ module Sentry
16
21
  duration: duration
17
22
  ) do |span|
18
23
  payload = payload.dup
19
- payload.delete(:headers)
20
- payload.delete(:request)
24
+ cleanup_data(payload)
21
25
  span.set_data(:payload, payload)
22
26
  span.set_http_status(payload[:status])
23
27
  end
@@ -1,3 +1,5 @@
1
+ require "sentry/rails/tracing/abstract_subscriber"
2
+
1
3
  module Sentry
2
4
  module Rails
3
5
  module Tracing
@@ -1,3 +1,5 @@
1
+ require "sentry/rails/tracing/abstract_subscriber"
2
+
1
3
  module Sentry
2
4
  module Rails
3
5
  module Tracing
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Rails
3
- VERSION = "4.3.4"
3
+ VERSION = "4.5.1"
4
4
  end
5
5
  end
data/sentry-rails.gemspec CHANGED
@@ -16,12 +16,12 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = spec.homepage
19
- spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/sentry-rails/CHANGELOG.md"
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
20
20
 
21
21
  spec.bindir = "exe"
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
25
  spec.add_dependency "railties", ">= 5.0"
26
- spec.add_dependency "sentry-ruby-core", "~> 4.3.0"
26
+ spec.add_dependency "sentry-ruby-core", "~> 4.5.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.3.4
4
+ version: 4.5.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-04-06 00:00:00.000000000 Z
11
+ date: 2021-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 4.3.0
33
+ version: 4.5.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.3.0
40
+ version: 4.5.0
41
41
  description: A gem that provides Rails integration for the Sentry error logger
42
42
  email: accounts@sentry.io
43
43
  executables: []
@@ -70,7 +70,7 @@ files:
70
70
  - lib/sentry/rails/controller_methods.rb
71
71
  - lib/sentry/rails/controller_transaction.rb
72
72
  - lib/sentry/rails/engine.rb
73
- - lib/sentry/rails/overrides/file_handler.rb
73
+ - lib/sentry/rails/instrument_payload_cleanup_helper.rb
74
74
  - lib/sentry/rails/overrides/streaming_reporter.rb
75
75
  - lib/sentry/rails/railtie.rb
76
76
  - lib/sentry/rails/rescued_exception_interceptor.rb
@@ -87,7 +87,7 @@ licenses:
87
87
  metadata:
88
88
  homepage_uri: https://github.com/getsentry/sentry-ruby
89
89
  source_code_uri: https://github.com/getsentry/sentry-ruby
90
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/CHANGELOG.md
90
+ changelog_uri: https://github.com/getsentry/sentry-ruby/blob/master/CHANGELOG.md
91
91
  post_install_message:
92
92
  rdoc_options: []
93
93
  require_paths:
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.0.3.1
106
+ rubygems_version: 3.1.6
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: A gem that provides Rails integration for the Sentry error logger
@@ -1,16 +0,0 @@
1
- module Sentry
2
- module Rails
3
- module Overrides
4
- module FileHandler
5
- def serve(*args)
6
- if Sentry.initialized? && current_transaction = Sentry.get_current_scope.span
7
- # we don't want to expose a setter for @sampled just for this case
8
- current_transaction.instance_variable_set(:@sampled, false)
9
- end
10
-
11
- super
12
- end
13
- end
14
- end
15
- end
16
- end