sentry-rails 4.1.0 → 4.1.5

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: 9e5e6de4bbd5e0e1530fcd38e5978b153c846bac123e92db1941fd8c58318eef
4
- data.tar.gz: 3b0ea04fd34eab29d19052fde261954890e3ce59e8f090592e23653e1aab7a4f
3
+ metadata.gz: ea1c3fea4d0f1f017e5b56786e85414e459a181e8e4cebe2a45374b6c3e648dc
4
+ data.tar.gz: b41da6b3dc3a3a7836ed533029821b4f53dc40e8b7cb0d10023a52af13236218
5
5
  SHA512:
6
- metadata.gz: 785b7d05b9ff2a18e5e3939aeac265ae02426a617f9fda15865fc69d1d196706fcc658a4a54731dd3eb918f714e6825651002528c2f20ad0b426e5fa0b248d24
7
- data.tar.gz: f9065c5331efae105803df2fcaed4e7c7cf18286d2b07ae046e1e48004cde67c0c3e171a5ca82cfae2cada9f23bb4a9ee12442fc3391415e2634389799ead5af
6
+ metadata.gz: 359b3757908046fa6dfde636715b598a6977c3a131b11e4a7f8d8df3666246e867867ca3c32161bbb645fe9bc0110c50efac415ed42b4db754e21cf36878af86
7
+ data.tar.gz: 4605d701de78b04adc04c74dc7b7dd1a1e02c1d500a663965d4ba9de35cf35db4a70331d21afd2b2c07a5c2917d2ccb0e2b7a7cced8f5026188e189cf119ecdb
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.1.5
4
+
5
+ - Add `ActionDispatch::Http::MimeNegotiation::InvalidType` to the list of default ignored Rails exceptions [#1215](https://github.com/getsentry/sentry-ruby/pull/1215) (by @agrobbin)
6
+ - Continue ActiveJob execution if Sentry is not initialized [#1217](https://github.com/getsentry/sentry-ruby/pull/1217)
7
+ - Fixes [#1211](https://github.com/getsentry/sentry-ruby/issues/1211) and [#1216](https://github.com/getsentry/sentry-ruby/issues/1216)
8
+ - Only extend ActiveJob when it's defined [#1218](https://github.com/getsentry/sentry-ruby/pull/1218)
9
+ - Fixes [#1210](https://github.com/getsentry/sentry-ruby/issues/1210)
10
+ - Filter out redundant event/payload from breadcrumbs logger [#1222](https://github.com/getsentry/sentry-ruby/pull/1222)
11
+ - Copy request env before Rails' ShowExceptions middleware [#1223](https://github.com/getsentry/sentry-ruby/pull/1223)
12
+ - Don't subscribe render_partial and render_collection events [#1224](https://github.com/getsentry/sentry-ruby/pull/1224)
13
+
14
+ ## 4.1.4
15
+
16
+ - Don't include headers & request info in tracing span or breadcrumb [#1199](https://github.com/getsentry/sentry-ruby/pull/1199)
17
+ - Don't run RescuedExceptionInterceptor unless Sentry is initialized [#1204](https://github.com/getsentry/sentry-ruby/pull/1204)
18
+
19
+ ## 4.1.3
20
+
21
+ - Remove DelayedJobAdapter from ignored list [#1179](https://github.com/getsentry/sentry-ruby/pull/1179)
22
+
23
+ ## 4.1.2
24
+
25
+ - Use middleware instead of method override to handle rescued exceptions [#1168](https://github.com/getsentry/sentry-ruby/pull/1168)
26
+ - Fixes [#738](https://github.com/getsentry/sentry-ruby/issues/738)
27
+ - Adopt Integrable module [#1177](https://github.com/getsentry/sentry-ruby/pull/1177)
28
+
29
+ ## 4.1.1
30
+
31
+ - Use stricter dependency declaration [#1159](https://github.com/getsentry/sentry-ruby/pull/1159)
32
+
3
33
  ## 4.1.0
4
34
 
5
35
  - Merge & rename 2 Rack middlewares [#1147](https://github.com/getsentry/sentry-ruby/pull/1147)
data/Gemfile CHANGED
@@ -12,7 +12,7 @@ gem "sqlite3", platform: :ruby
12
12
 
13
13
  gem "rails", "~> #{rails_version}"
14
14
  gem "rspec-rails", "~> 4.0"
15
- gem "codecov"
15
+ gem "codecov", "0.2.12"
16
16
 
17
17
  gem "rake", "~> 12.0"
18
18
  gem "rspec", "~> 3.0"
data/README.md CHANGED
@@ -44,7 +44,7 @@ Sentry.init do |config|
44
44
  # the default value is true
45
45
  config.rails.report_rescued_exceptions = true
46
46
 
47
- # this gem also provides a new breadcrumb logger that accepts instrumentaions from ActiveSupport
47
+ # this gem also provides a new breadcrumb logger that accepts instrumentations from ActiveSupport
48
48
  # it's not activated by default, but you can enable it with
49
49
  config.breadcrumbs_logger = [:active_support_logger]
50
50
  end
@@ -1,14 +1,12 @@
1
1
  require "sentry-ruby"
2
+ require "sentry/integrable"
2
3
  require "sentry/rails/configuration"
3
4
  require "sentry/rails/railtie"
4
5
  require "sentry/rails/tracing"
5
6
 
6
7
  module Sentry
7
8
  module Rails
8
- META = { "name" => "sentry.ruby.rails", "version" => Sentry::Rails::VERSION }.freeze
9
- end
10
-
11
- def self.sdk_meta
12
- Sentry::Rails::META
9
+ extend Integrable
10
+ register_integration name: "rails", version: Sentry::Rails::VERSION
13
11
  end
14
12
  end
@@ -3,18 +3,21 @@ module Sentry
3
3
  module ActiveJobExtensions
4
4
  ALREADY_SUPPORTED_SENTRY_ADAPTERS = %w(
5
5
  ActiveJob::QueueAdapters::SidekiqAdapter
6
- ActiveJob::QueueAdapters::DelayedJobAdapter
7
6
  ).freeze
8
7
 
9
8
  def self.included(base)
10
9
  base.class_eval do
11
10
  around_perform do |job, block|
12
- if already_supported_by_specific_integration?(job)
13
- block.call
14
- else
15
- Sentry.with_scope do
16
- capture_and_reraise_with_sentry(job, block)
11
+ if Sentry.initialized?
12
+ if already_supported_by_specific_integration?(job)
13
+ block.call
14
+ else
15
+ Sentry.with_scope do
16
+ capture_and_reraise_with_sentry(job, block)
17
+ end
17
18
  end
19
+ else
20
+ block.call
18
21
  end
19
22
  end
20
23
  end
@@ -26,7 +29,7 @@ module Sentry
26
29
  rescue_handler_result = rescue_with_handler(e)
27
30
  return rescue_handler_result if rescue_handler_result
28
31
 
29
- Sentry.capture_exception(e, :extra => sentry_context(job))
32
+ Sentry::Rails.capture_exception(e, extra: sentry_context(job))
30
33
  raise e
31
34
  end
32
35
 
@@ -3,7 +3,18 @@ module Sentry
3
3
  module Breadcrumb
4
4
  module ActiveSupportLogger
5
5
  class << self
6
+ IGNORED_DATA_TYPES = [:request, :headers, :exception, :exception_object]
7
+
6
8
  def add(name, started, _finished, _unique_id, data)
9
+ # skip Rails' internal events
10
+ return if name.start_with?("!")
11
+
12
+ if data.is_a?(Hash)
13
+ # we should only mutate the copy of the data
14
+ data = data.dup
15
+ cleanup_data(data)
16
+ end
17
+
7
18
  crumb = Sentry::Breadcrumb.new(
8
19
  data: data,
9
20
  category: name,
@@ -12,6 +23,12 @@ module Sentry
12
23
  Sentry.add_breadcrumb(crumb)
13
24
  end
14
25
 
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
+
15
32
  def inject
16
33
  @subscriber = ::ActiveSupport::Notifications.subscribe(/.*/) do |name, started, finished, unique_id, data|
17
34
  # we only record events that has a started timestamp
@@ -1,8 +1,18 @@
1
1
  module Sentry
2
2
  module Rails
3
3
  class CaptureExceptions < Sentry::Rack::CaptureExceptions
4
+ private
5
+
4
6
  def collect_exception(env)
5
- super || env["action_dispatch.exception"]
7
+ super || env["action_dispatch.exception"] || env["sentry.rescued_exception"]
8
+ end
9
+
10
+ def transaction_op
11
+ "rails.request".freeze
12
+ end
13
+
14
+ def capture_exception(exception)
15
+ Sentry::Rails.capture_exception(exception)
6
16
  end
7
17
  end
8
18
  end
@@ -20,6 +20,7 @@ module Sentry
20
20
  'ActionController::RoutingError',
21
21
  'ActionController::UnknownAction',
22
22
  'ActionController::UnknownFormat',
23
+ 'ActionDispatch::Http::MimeNegotiation::InvalidType',
23
24
  'ActionController::UnknownHttpMethod',
24
25
  'ActionDispatch::Http::Parameters::ParseError',
25
26
  'ActiveJob::DeserializationError', # Can cause infinite loops
@@ -3,13 +3,13 @@ module Sentry
3
3
  module ControllerMethods
4
4
  def capture_message(message, options = {})
5
5
  with_request_scope do
6
- Sentry.capture_message(message, **options)
6
+ Sentry::Rails.capture_message(message, **options)
7
7
  end
8
8
  end
9
9
 
10
10
  def capture_exception(exception, options = {})
11
11
  with_request_scope do
12
- Sentry.capture_exception(exception, **options)
12
+ Sentry::Rails.capture_exception(exception, **options)
13
13
  end
14
14
  end
15
15
 
@@ -2,10 +2,8 @@ module Sentry
2
2
  module Rails
3
3
  module ControllerTransaction
4
4
  def self.included(base)
5
- base.prepend_around_action do |controller, block|
5
+ base.prepend_before_action do |controller|
6
6
  Sentry.get_current_scope.set_transaction_name("#{controller.class}##{controller.action_name}")
7
- block.call
8
- Sentry.get_current_scope.transaction_names.pop
9
7
  end
10
8
  end
11
9
  end
@@ -3,7 +3,7 @@ module Sentry
3
3
  module Overrides
4
4
  module StreamingReporter
5
5
  def log_error(exception)
6
- Sentry.capture_exception(exception)
6
+ Sentry::Rails.capture_exception(exception)
7
7
  super
8
8
  end
9
9
  end
@@ -14,7 +14,7 @@ module Sentry
14
14
  end
15
15
 
16
16
  def log_error_with_raven(exception)
17
- Sentry.capture_exception(exception)
17
+ Sentry::Rails.capture_exception(exception)
18
18
  log_error_without_raven(exception)
19
19
  end
20
20
  end
@@ -1,16 +1,19 @@
1
1
  require "rails"
2
2
  require "sentry/rails/capture_exceptions"
3
+ require "sentry/rails/rescued_exception_interceptor"
3
4
  require "sentry/rails/backtrace_cleaner"
4
5
  require "sentry/rails/controller_methods"
5
6
  require "sentry/rails/controller_transaction"
6
- require "sentry/rails/active_job"
7
7
  require "sentry/rails/overrides/streaming_reporter"
8
8
 
9
9
  module Sentry
10
10
  class Railtie < ::Rails::Railtie
11
11
  # middlewares can't be injected after initialize
12
12
  initializer "sentry.use_rack_middleware" do |app|
13
+ # need to be placed at first to capture as many errors as possible
13
14
  app.config.middleware.insert 0, Sentry::Rails::CaptureExceptions
15
+ # need to be placed at last to smuggle app exceptions via env
16
+ app.config.middleware.use(Sentry::Rails::RescuedExceptionInterceptor)
14
17
  end
15
18
 
16
19
  config.after_initialize do
@@ -18,8 +21,7 @@ module Sentry
18
21
 
19
22
  configure_sentry_logger
20
23
  extend_controller_methods
21
- extend_active_job
22
- override_exceptions_handling
24
+ extend_active_job if defined?(ActiveJob)
23
25
  override_streaming_reporter
24
26
  setup_backtrace_cleanup_callback
25
27
  inject_breadcrumbs_logger
@@ -31,6 +33,7 @@ module Sentry
31
33
  end
32
34
 
33
35
  def extend_active_job
36
+ require "sentry/rails/active_job"
34
37
  ActiveJob::Base.send(:prepend, Sentry::Rails::ActiveJobExtensions)
35
38
  end
36
39
 
@@ -57,19 +60,6 @@ module Sentry
57
60
  end
58
61
  end
59
62
 
60
- def override_exceptions_handling
61
- if Sentry.configuration.rails.report_rescued_exceptions
62
- require 'sentry/rails/overrides/debug_exceptions_catcher'
63
- if defined?(::ActionDispatch::DebugExceptions)
64
- exceptions_class = ::ActionDispatch::DebugExceptions
65
- elsif defined?(::ActionDispatch::ShowExceptions)
66
- exceptions_class = ::ActionDispatch::ShowExceptions
67
- end
68
-
69
- exceptions_class.send(:prepend, Sentry::Rails::Overrides::DebugExceptionsCatcher)
70
- end
71
- end
72
-
73
63
  def override_streaming_reporter
74
64
  ActiveSupport.on_load :action_view do
75
65
  ActionView::StreamingTemplateRenderer::Body.send(:prepend, Sentry::Rails::Overrides::StreamingReporter)
@@ -0,0 +1,29 @@
1
+ module Sentry
2
+ module Rails
3
+ class RescuedExceptionInterceptor
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ return @app.call(env) unless Sentry.initialized?
10
+
11
+ begin
12
+ @app.call(env)
13
+ rescue => e
14
+ request = ActionDispatch::Request.new(env)
15
+
16
+ # Rails' ShowExceptions#render_exception will mutate env for the exceptions app
17
+ # so we need to hold a copy of env to report the accurate data (like request's url)
18
+ if request.show_exceptions?
19
+ scope = Sentry.get_current_scope
20
+ scope.set_rack_env(scope.rack_env.dup)
21
+ end
22
+
23
+ env["sentry.rescued_exception"] = e if Sentry.configuration.rails.report_rescued_exceptions
24
+ raise e
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -15,6 +15,9 @@ module Sentry
15
15
  description: "#{controller}##{action}",
16
16
  duration: duration
17
17
  ) do |span|
18
+ payload = payload.dup
19
+ payload.delete(:headers)
20
+ payload.delete(:request)
18
21
  span.set_data(:payload, payload)
19
22
  span.set_http_status(payload[:status])
20
23
  end
@@ -2,19 +2,11 @@ module Sentry
2
2
  module Rails
3
3
  module Tracing
4
4
  class ActionViewSubscriber < AbstractSubscriber
5
- EVENT_NAMES = ["render_template.action_view", "render_partial.action_view", "render_collection.action_view"]
5
+ EVENT_NAME = "render_template.action_view".freeze
6
6
 
7
7
  def self.subscribe!
8
- EVENT_NAMES.each do |event_name|
9
- subscribe_to_event(event_name) do |event_name, duration, payload|
10
- record_on_current_span(op: event_name, start_timestamp: payload[:start_timestamp], description: payload[:identifier], duration: duration)
11
- end
12
- end
13
- end
14
-
15
- def self.unsubscribe!
16
- EVENT_NAMES.each do |event_name|
17
- ActiveSupport::Notifications.unsubscribe(event_name)
8
+ subscribe_to_event(EVENT_NAME) do |event_name, duration, payload|
9
+ record_on_current_span(op: event_name, start_timestamp: payload[:start_timestamp], description: payload[:identifier], duration: duration)
18
10
  end
19
11
  end
20
12
  end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Rails
3
- VERSION = "4.1.0"
3
+ VERSION = "4.1.5"
4
4
  end
5
5
  end
@@ -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", ">= 4.1.0"
26
+ spec.add_dependency "sentry-ruby", "~> 4.1.2"
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.0
4
+ version: 4.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-18 00:00:00.000000000 Z
11
+ date: 2021-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: sentry-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 4.1.0
33
+ version: 4.1.2
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.0
40
+ version: 4.1.2
41
41
  description: A gem that provides Rails integration for the Sentry error logger
42
42
  email: accounts@sentry.io
43
43
  executables: []
@@ -67,9 +67,9 @@ files:
67
67
  - lib/sentry/rails/configuration.rb
68
68
  - lib/sentry/rails/controller_methods.rb
69
69
  - lib/sentry/rails/controller_transaction.rb
70
- - lib/sentry/rails/overrides/debug_exceptions_catcher.rb
71
70
  - lib/sentry/rails/overrides/streaming_reporter.rb
72
71
  - lib/sentry/rails/railtie.rb
72
+ - lib/sentry/rails/rescued_exception_interceptor.rb
73
73
  - lib/sentry/rails/tracing.rb
74
74
  - lib/sentry/rails/tracing/abstract_subscriber.rb
75
75
  - lib/sentry/rails/tracing/action_controller_subscriber.rb
@@ -1,19 +0,0 @@
1
- module Sentry
2
- module Rails
3
- module Overrides
4
- module DebugExceptionsCatcher
5
- def render_exception(env_or_request, exception)
6
- begin
7
- env = env_or_request.respond_to?(:env) ? env_or_request.env : env_or_request
8
- Sentry.with_scope do |scope|
9
- scope.set_rack_env(env)
10
- Sentry.capture_exception(exception)
11
- end
12
- rescue
13
- end
14
- super
15
- end
16
- end
17
- end
18
- end
19
- end