sentry-rails 0.2.0 → 4.1.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: 9e7eaef0b61e66058c293dd473a41a8a45af0c1547325099540d81f7802be480
4
- data.tar.gz: c67ee2d0741a7822c43b3d29ad3d44a8590a032abe0727487dd88e09934f9449
3
+ metadata.gz: 8d6a1afa9da4c0ec517f7cf0b494f7965f9d6b30450ed005face3d28d541430e
4
+ data.tar.gz: 21a9be637731b712e430eee4652a3b98d7eef0475c7027833172b2dfb8a414fd
5
5
  SHA512:
6
- metadata.gz: 82bbf7256864d79f10863c730508e7d0f24c0923ec0fbf77446584db1ecae1b04dcfb9e1de45367e3c0528848bd8e41d3db6d45e7d6be6eada7e2abd4e47c808
7
- data.tar.gz: 661da577ee137848c260fcd019413b0efd7b0cc7756f90b33ba4f049446f3b1439439929e50b8ffddbfa08c1d6e907aa7f7e04761630b5cfaf81f29fe2ec1589
6
+ metadata.gz: 8d9c22704d42808bb82104540524468e696da6e24340b6e79216c1dfd0510a8e30099915fb9502c676ecc4f399d7bf29c48468708e2b29a2b9b656a771c8264d
7
+ data.tar.gz: 4eaff646e0096e0221c4389ff65ce50cd80a8ed4c03673718c1a5990b7a02f5d4639dffcb02a8622bc5f1f5b563c8c0dcaad8af77a72577d577c1744c81529a5
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.1.2
4
+
5
+ - Use middleware instead of method override to handle rescued exceptions [#1168](https://github.com/getsentry/sentry-ruby/pull/1168)
6
+ - Fixes [#738](https://github.com/getsentry/sentry-ruby/issues/738)
7
+ - Adopt Integrable module [#1177](https://github.com/getsentry/sentry-ruby/pull/1177)
8
+
9
+ ## 4.1.1
10
+
11
+ - Use stricter dependency declaration [#1159](https://github.com/getsentry/sentry-ruby/pull/1159)
12
+
13
+ ## 4.1.0
14
+
15
+ - Merge & rename 2 Rack middlewares [#1147](https://github.com/getsentry/sentry-ruby/pull/1147)
16
+ - Fixes [#1153](https://github.com/getsentry/sentry-ruby/pull/1153)
17
+ - Removed `Sentry::Rack::Tracing` middleware and renamed `Sentry::Rack::CaptureException` to `Sentry::Rack::CaptureExceptions`
18
+ - Tidy up rails integration [#1150](https://github.com/getsentry/sentry-ruby/pull/1150)
19
+ - Check SDK initialization before running integrations [#1151](https://github.com/getsentry/sentry-ruby/pull/1151)
20
+ - Fixes [#1145](https://github.com/getsentry/sentry-ruby/pull/1145)
21
+
22
+ ## 4.0.0
23
+
24
+ - Only documents update for the official release and no API/feature changes.
25
+
26
+ ## 0.3.0
27
+
28
+ - Major API changes: [1123](https://github.com/getsentry/sentry-ruby/pull/1123)
29
+
3
30
  ## 0.2.0
4
31
 
5
32
  - Multiple fixes and refactorings
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  rails_version = ENV["RAILS_VERSION"]
7
- rails_version = "6.0" if rails_version.nil?
7
+ 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
@@ -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
@@ -17,7 +17,7 @@
17
17
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-rails&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-rails&package-manager=bundler&version-scheme=semver)
18
18
 
19
19
 
20
- [Documentation](https://docs.sentry.io/clients/ruby/) | [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues) | [Forum](https://forum.sentry.io/) | IRC: irc.freenode.net, #sentry
20
+ [Documentation](https://docs.sentry.io/platforms/ruby/guides/rails/) | [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues) | [Forum](https://forum.sentry.io/) | IRC: irc.freenode.net, #sentry
21
21
 
22
22
  The official Ruby-language client and integration layer for the [Sentry](https://github.com/getsentry/sentry) error reporting API.
23
23
 
@@ -50,3 +50,36 @@ Sentry.init do |config|
50
50
  end
51
51
  ```
52
52
 
53
+ ### Performance Monitoring
54
+
55
+ You can activate performance monitoring by enabling traces sampling:
56
+
57
+ ```ruby
58
+ Sentry.init do |config|
59
+ # set a uniform sample rate between 0.0 and 1.0
60
+ config.traces_sample_rate = 0.2
61
+
62
+ # or control sampling dynamically
63
+ config.traces_sampler = lambda do |sampling_context|
64
+ # sampling_context[:transaction_context] contains the information about the transaction
65
+ # sampling_context[:parent_sampled] contains the transaction's parent's sample decision
66
+ true # return value can be a boolean or a float between 0.0 and 1.0
67
+ end
68
+ end
69
+ ```
70
+
71
+ Currently, it tracks the following Rails instrumentation events:
72
+
73
+ - ActiveRecord
74
+ - `sql.active_record`
75
+ - ActionController
76
+ - `process_action.action_controller`
77
+ - ActionView
78
+ - `render_template.action_view`
79
+ - `render_partial.action_view`
80
+ - `render_collection.action_view`
81
+
82
+ To lean more about performance monitoring, please visit the [official documentation](https://docs.sentry.io/platforms/ruby/guides/rails/performance/).
83
+
84
+
85
+
@@ -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
@@ -26,7 +26,7 @@ module Sentry
26
26
  rescue_handler_result = rescue_with_handler(e)
27
27
  return rescue_handler_result if rescue_handler_result
28
28
 
29
- Sentry.capture_exception(e, :extra => sentry_context(job))
29
+ Sentry::Rails.capture_exception(e, extra: sentry_context(job))
30
30
  raise e
31
31
  end
32
32
 
@@ -4,16 +4,20 @@ module Sentry
4
4
  module ActiveSupportLogger
5
5
  class << self
6
6
  def add(name, started, _finished, _unique_id, data)
7
- Sentry.get_current_scope.breadcrumbs.record do |crumb|
8
- crumb.data = data
9
- crumb.category = name
10
- crumb.timestamp = started.to_i
11
- end
7
+ crumb = Sentry::Breadcrumb.new(
8
+ data: data,
9
+ category: name,
10
+ timestamp: started.to_i
11
+ )
12
+ Sentry.add_breadcrumb(crumb)
12
13
  end
13
14
 
14
15
  def inject
15
16
  @subscriber = ::ActiveSupport::Notifications.subscribe(/.*/) do |name, started, finished, unique_id, data|
16
- add(name, started, finished, unique_id, data)
17
+ # we only record events that has a started timestamp
18
+ if started.is_a?(Time)
19
+ add(name, started, finished, unique_id, data)
20
+ end
17
21
  end
18
22
  end
19
23
 
@@ -0,0 +1,19 @@
1
+ module Sentry
2
+ module Rails
3
+ class CaptureExceptions < Sentry::Rack::CaptureExceptions
4
+ private
5
+
6
+ def collect_exception(env)
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)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -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,5 +1,6 @@
1
1
  require "rails"
2
- require "sentry/rails/capture_exception"
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"
@@ -8,12 +9,35 @@ require "sentry/rails/overrides/streaming_reporter"
8
9
 
9
10
  module Sentry
10
11
  class Railtie < ::Rails::Railtie
12
+ # middlewares can't be injected after initialize
11
13
  initializer "sentry.use_rack_middleware" do |app|
12
- app.config.middleware.insert 0, Sentry::Rails::CaptureException
13
- app.config.middleware.insert 0, Sentry::Rack::Tracing
14
+ # need to be placed at first to capture as many errors as possible
15
+ app.config.middleware.insert 0, Sentry::Rails::CaptureExceptions
16
+ # need to be placed at last to smuggle app exceptions via env
17
+ app.config.middleware.use(Sentry::Rails::RescuedExceptionInterceptor)
14
18
  end
15
19
 
16
- initializer 'sentry.action_controller' do
20
+ config.after_initialize do
21
+ next unless Sentry.initialized?
22
+
23
+ configure_sentry_logger
24
+ extend_controller_methods
25
+ extend_active_job
26
+ override_streaming_reporter
27
+ setup_backtrace_cleanup_callback
28
+ inject_breadcrumbs_logger
29
+ activate_tracing
30
+ end
31
+
32
+ def configure_sentry_logger
33
+ Sentry.configuration.logger = ::Rails.logger
34
+ end
35
+
36
+ def extend_active_job
37
+ ActiveJob::Base.send(:prepend, Sentry::Rails::ActiveJobExtensions)
38
+ end
39
+
40
+ def extend_controller_methods
17
41
  ActiveSupport.on_load :action_controller do
18
42
  include Sentry::Rails::ControllerMethods
19
43
  include Sentry::Rails::ControllerTransaction
@@ -21,51 +45,32 @@ module Sentry
21
45
  end
22
46
  end
23
47
 
24
- initializer 'sentry.action_view' do
25
- ActiveSupport.on_load :action_view do
26
- ActionView::StreamingTemplateRenderer::Body.send(:prepend, Sentry::Rails::Overrides::StreamingReporter)
48
+ def inject_breadcrumbs_logger
49
+ if Sentry.configuration.breadcrumbs_logger.include?(:active_support_logger)
50
+ require 'sentry/rails/breadcrumb/active_support_logger'
51
+ Sentry::Rails::Breadcrumb::ActiveSupportLogger.inject
27
52
  end
28
53
  end
29
54
 
30
- config.after_initialize do
31
- Sentry.configuration.logger = ::Rails.logger
32
-
55
+ def setup_backtrace_cleanup_callback
33
56
  backtrace_cleaner = Sentry::Rails::BacktraceCleaner.new
34
57
 
35
58
  Sentry.configuration.backtrace_cleanup_callback = lambda do |backtrace|
36
59
  backtrace_cleaner.clean(backtrace)
37
60
  end
61
+ end
38
62
 
39
- if Sentry.configuration.breadcrumbs_logger.include?(:active_support_logger)
40
- require 'sentry/rails/breadcrumb/active_support_logger'
41
- Sentry::Rails::Breadcrumb::ActiveSupportLogger.inject
42
- end
43
-
44
- if Sentry.configuration.rails.report_rescued_exceptions
45
- require 'sentry/rails/overrides/debug_exceptions_catcher'
46
- if defined?(::ActionDispatch::DebugExceptions)
47
- exceptions_class = ::ActionDispatch::DebugExceptions
48
- elsif defined?(::ActionDispatch::ShowExceptions)
49
- exceptions_class = ::ActionDispatch::ShowExceptions
50
- end
51
-
52
- exceptions_class.send(:prepend, Sentry::Rails::Overrides::DebugExceptionsCatcher)
63
+ def override_streaming_reporter
64
+ ActiveSupport.on_load :action_view do
65
+ ActionView::StreamingTemplateRenderer::Body.send(:prepend, Sentry::Rails::Overrides::StreamingReporter)
53
66
  end
67
+ end
54
68
 
69
+ def activate_tracing
55
70
  if Sentry.configuration.tracing_enabled?
56
71
  Sentry::Rails::Tracing.subscribe_tracing_events
57
72
  Sentry::Rails::Tracing.patch_active_support_notifications
58
73
  end
59
74
  end
60
-
61
- initializer 'sentry.active_job' do
62
- ActiveSupport.on_load :active_job do
63
- require 'sentry/rails/active_job'
64
- end
65
- end
66
-
67
- # rake_tasks do
68
- # require 'sentry/integrations/tasks'
69
- # end
70
75
  end
71
76
  end
@@ -0,0 +1,18 @@
1
+ module Sentry
2
+ module Rails
3
+ class RescuedExceptionInterceptor
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ begin
10
+ @app.call(env)
11
+ rescue => e
12
+ env["sentry.rescued_exception"] = e if Sentry.configuration.rails.report_rescued_exceptions
13
+ raise e
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Rails
3
- VERSION = "0.2.0"
3
+ VERSION = "4.1.2"
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", ">= 0.2.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: 0.2.0
4
+ version: 4.1.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: 2020-11-30 00:00:00.000000000 Z
11
+ date: 2020-12-30 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: 0.2.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: 0.2.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: []
@@ -63,13 +63,13 @@ files:
63
63
  - lib/sentry/rails/active_job.rb
64
64
  - lib/sentry/rails/backtrace_cleaner.rb
65
65
  - lib/sentry/rails/breadcrumb/active_support_logger.rb
66
- - lib/sentry/rails/capture_exception.rb
66
+ - lib/sentry/rails/capture_exceptions.rb
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,9 +0,0 @@
1
- module Sentry
2
- module Rails
3
- class CaptureException < Sentry::Rack::CaptureException
4
- def collect_exception(env)
5
- super || env["action_dispatch.exception"]
6
- end
7
- end
8
- end
9
- end
@@ -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