sentry-rails 4.1.1 → 4.1.6

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: f1ded72e004f25631844145fc5a86d4e4a20e90417a42ac608a91b92fd5a0702
4
- data.tar.gz: 5b36ca31d954d72c0ee3f0407b3ad201285809b45439d580ccad910cf5f68d6f
3
+ metadata.gz: 577efe95018b382a927d9078662707a033c579fa37757467e9cbdbead6ddadb1
4
+ data.tar.gz: d99a6385af1d142f446649bd4df596299c8ace976ca333313897335e3dabe44f
5
5
  SHA512:
6
- metadata.gz: b91264b7393b702a5f4e08e8ac37836dd97e5055eb214b37faa704930bb56ef681edbc7baabc8fcced668d2a78c4d10ab039715036a8196f6734a7ef5f429467
7
- data.tar.gz: bb6d1c2a6c051922126ba745350f1c003cf928309a6507867084f1a1833dd160a2ac6637cd909caadf69ac848d66a8789a1286409267c7aefbb74453836833c2
6
+ metadata.gz: 899fd5096e17f61dc6d0186cdcb87c93c555dce397bd5c4e4ade88fd704e320290e7fb2a7cbfebb9eaf21a188e6e3823d0f7e298db645eb438110d93831d7d1e
7
+ data.tar.gz: 1f16fc8dd1e35c38d7a6b78449ae586bae30d9f611c98d43cb6f497f7a21accb84d6552f7eaddb41a0cb32adb01b597b67e41173266f27c562b8242a7291ae7d
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.1.6
4
+
5
+ - Prevent exceptions app from overriding event's transaction name [#1230](https://github.com/getsentry/sentry-ruby/pull/1230)
6
+ - Fix project root detection [#1242](https://github.com/getsentry/sentry-ruby/pull/1242)
7
+ - Use sentry-ruby-core as the main SDK dependency [#1244](https://github.com/getsentry/sentry-ruby/pull/1244)
8
+
9
+ ## 4.1.5
10
+
11
+ - Add `ActionDispatch::Http::MimeNegotiation::InvalidType` to the list of default ignored Rails exceptions [#1215](https://github.com/getsentry/sentry-ruby/pull/1215) (by @agrobbin)
12
+ - Continue ActiveJob execution if Sentry is not initialized [#1217](https://github.com/getsentry/sentry-ruby/pull/1217)
13
+ - Fixes [#1211](https://github.com/getsentry/sentry-ruby/issues/1211) and [#1216](https://github.com/getsentry/sentry-ruby/issues/1216)
14
+ - Only extend ActiveJob when it's defined [#1218](https://github.com/getsentry/sentry-ruby/pull/1218)
15
+ - Fixes [#1210](https://github.com/getsentry/sentry-ruby/issues/1210)
16
+ - Filter out redundant event/payload from breadcrumbs logger [#1222](https://github.com/getsentry/sentry-ruby/pull/1222)
17
+ - Copy request env before Rails' ShowExceptions middleware [#1223](https://github.com/getsentry/sentry-ruby/pull/1223)
18
+ - Don't subscribe render_partial and render_collection events [#1224](https://github.com/getsentry/sentry-ruby/pull/1224)
19
+
20
+ ## 4.1.4
21
+
22
+ - Don't include headers & request info in tracing span or breadcrumb [#1199](https://github.com/getsentry/sentry-ruby/pull/1199)
23
+ - Don't run RescuedExceptionInterceptor unless Sentry is initialized [#1204](https://github.com/getsentry/sentry-ruby/pull/1204)
24
+
25
+ ## 4.1.3
26
+
27
+ - Remove DelayedJobAdapter from ignored list [#1179](https://github.com/getsentry/sentry-ruby/pull/1179)
28
+
29
+ ## 4.1.2
30
+
31
+ - Use middleware instead of method override to handle rescued exceptions [#1168](https://github.com/getsentry/sentry-ruby/pull/1168)
32
+ - Fixes [#738](https://github.com/getsentry/sentry-ruby/issues/738)
33
+ - Adopt Integrable module [#1177](https://github.com/getsentry/sentry-ruby/pull/1177)
34
+
3
35
  ## 4.1.1
4
36
 
5
37
  - Use stricter dependency declaration [#1159](https://github.com/getsentry/sentry-ruby/pull/1159)
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"
@@ -0,0 +1,3 @@
1
+ build:
2
+ bundle install
3
+ gem build sentry-rails.gemspec
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,36 +1,44 @@
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
17
20
  next unless Sentry.initialized?
18
21
 
22
+ configure_project_root
19
23
  configure_sentry_logger
20
24
  extend_controller_methods
21
- extend_active_job
22
- override_exceptions_handling
25
+ extend_active_job if defined?(ActiveJob)
23
26
  override_streaming_reporter
24
27
  setup_backtrace_cleanup_callback
25
28
  inject_breadcrumbs_logger
26
29
  activate_tracing
27
30
  end
28
31
 
32
+ def configure_project_root
33
+ Sentry.configuration.project_root = ::Rails.root.to_s
34
+ end
35
+
29
36
  def configure_sentry_logger
30
37
  Sentry.configuration.logger = ::Rails.logger
31
38
  end
32
39
 
33
40
  def extend_active_job
41
+ require "sentry/rails/active_job"
34
42
  ActiveJob::Base.send(:prepend, Sentry::Rails::ActiveJobExtensions)
35
43
  end
36
44
 
@@ -57,19 +65,6 @@ module Sentry
57
65
  end
58
66
  end
59
67
 
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
68
  def override_streaming_reporter
74
69
  ActiveSupport.on_load :action_view do
75
70
  ActionView::StreamingTemplateRenderer::Body.send(:prepend, Sentry::Rails::Overrides::StreamingReporter)
@@ -0,0 +1,36 @@
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
+ transaction = scope.transaction_name
22
+
23
+ # we also need to make sure the transaction name won't be overridden by the exceptions app
24
+ scope.add_event_processor do |event, hint|
25
+ event.transaction = transaction
26
+ event
27
+ end
28
+ end
29
+
30
+ env["sentry.rescued_exception"] = e if Sentry.configuration.rails.report_rescued_exceptions
31
+ raise e
32
+ end
33
+ end
34
+ end
35
+ end
36
+ 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.1"
3
+ VERSION = "4.1.6"
4
4
  end
5
5
  end
@@ -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/CHANGELOG.md"
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/sentry-rails/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 "rails", ">= 5.0"
26
- spec.add_dependency "sentry-ruby", "~> 4.1.0"
26
+ spec.add_dependency "sentry-ruby-core", "~> 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.1
4
+ version: 4.1.6
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-21 00:00:00.000000000 Z
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: sentry-ruby
28
+ name: sentry-ruby-core
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: []
@@ -49,11 +49,11 @@ files:
49
49
  - ".craft.yml"
50
50
  - ".gitignore"
51
51
  - ".rspec"
52
- - ".travis.yml"
53
52
  - CHANGELOG.md
54
53
  - CODE_OF_CONDUCT.md
55
54
  - Gemfile
56
55
  - LICENSE.txt
56
+ - Makefile
57
57
  - README.md
58
58
  - Rakefile
59
59
  - bin/console
@@ -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
@@ -83,7 +83,7 @@ licenses:
83
83
  metadata:
84
84
  homepage_uri: https://github.com/getsentry/sentry-ruby
85
85
  source_code_uri: https://github.com/getsentry/sentry-ruby
86
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/master/CHANGELOG.md
86
+ changelog_uri: https://github.com/getsentry/sentry-ruby/blob/master/sentry-rails/CHANGELOG.md
87
87
  post_install_message:
88
88
  rdoc_options: []
89
89
  require_paths:
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.6.5
6
- before_install: gem install bundler -v 2.1.1
@@ -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