sentry-rails 5.4.2 → 5.16.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: 92b1952096935f672e03a41883297d867b70e433c92434b24420062c37d2325f
4
- data.tar.gz: 3cdfb19c85436bdc509e00512734fe6eb11880bdbe22ef50e6d99908f38daf16
3
+ metadata.gz: 7ee07f40f442adc566067614916895a02d753d2a44c518a78d78528c6d967e1e
4
+ data.tar.gz: 71004c34b4c2798d8022a3d11dbda9daf19f9f9a39a9d4b9a8bdac0332a0b39f
5
5
  SHA512:
6
- metadata.gz: 2271053cd6e6d9f04ba55258d177347f8df8ce74d6c15bdb3083eef6cc3cd1b8f4847c448071c8e03b33d90498acc04f384c4cfe3730c792af046a1860a76a53
7
- data.tar.gz: 345700856d420c3e562201cedb88d18d396d4f60487bb945f262bffba028ca7f9b12aa481deeebad7607e8f9baa0c4db30308d97a856b45bd7fd0e3f75e06258
6
+ metadata.gz: 172c3ca6639f55e608db51ef7efb1837791b5bc8836273fed287b58f32a1b88377b50488e70e94134a4c3b9d230731fba03b7a2523cfde975dd6685c7a136d73
7
+ data.tar.gz: 3a8010027974f00f4c708e8b0356233c3ccddb7eb525df660b9d9aefbcc535870118dbf727b1658b1271bc5afddc9a93b13a4ce0c496fc22ba9c8db18c84d630
data/.gitignore CHANGED
@@ -5,7 +5,7 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
- /spec/dummy/test_rails_app/db
8
+ /spec/dummy/test_rails_app/db*
9
9
  /tmp/
10
10
 
11
11
  # rspec failure tracking
data/Gemfile CHANGED
@@ -5,23 +5,29 @@ git_source(:github) { |name| "https://github.com/#{name}.git" }
5
5
  gemspec
6
6
  gem "sentry-ruby", path: "../sentry-ruby"
7
7
 
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ gem "jdbc-sqlite3"
11
+ end
12
+
8
13
  rails_version = ENV["RAILS_VERSION"]
9
- rails_version = "7.0.0" if rails_version.nil?
14
+ rails_version = "7.1.0" if rails_version.nil?
10
15
  rails_version = Gem::Version.new(rails_version)
11
16
 
12
- gem 'activerecord-jdbcmysql-adapter', platform: :jruby
13
- gem "jdbc-sqlite3", platform: :jruby
14
-
15
17
  if rails_version < Gem::Version.new("6.0.0")
16
18
  gem "sqlite3", "~> 1.3.0", platform: :ruby
17
19
  else
18
- gem "sqlite3", platform: :ruby
20
+ # 1.7.0 dropped support for ruby < 3.0, remove later after upgrading craft setup
21
+ gem "sqlite3", "1.6.9", platform: :ruby
19
22
  end
20
23
 
21
- if rails_version > Gem::Version.new("7.0.0")
24
+ if rails_version >= Gem::Version.new("7.2.0.alpha")
22
25
  gem "rails", github: "rails/rails"
26
+ elsif rails_version >= Gem::Version.new("7.1.0")
27
+ gem "rails", "~> #{rails_version}"
23
28
  else
24
29
  gem "rails", "~> #{rails_version}"
30
+ gem "psych", "~> 3.0.0"
25
31
  end
26
32
 
27
33
  gem "mini_magick"
@@ -30,20 +36,19 @@ gem "sprockets-rails"
30
36
 
31
37
  gem "sidekiq"
32
38
 
33
- gem "rspec", "~> 3.0"
34
- gem "rspec-retry"
35
39
  gem "rspec-rails", "~> 4.0"
36
- gem 'simplecov'
37
- gem "simplecov-cobertura", "~> 1.4"
38
- gem "rexml"
39
40
 
40
- gem "rake", "~> 12.0"
41
+ ruby_version = Gem::Version.new(RUBY_VERSION)
41
42
 
42
- gem "object_tracer"
43
- gem "debug", github: "ruby/debug", platform: :ruby if RUBY_VERSION.to_f >= 2.6
44
- gem "pry"
43
+ if ruby_version < Gem::Version.new("2.5.0")
44
+ # https://github.com/flavorjones/loofah/pull/267
45
+ # loofah changed the required ruby version in a patch so we need to explicitly pin it
46
+ gem "loofah", "2.20.0"
47
+ end
45
48
 
46
49
  gem "benchmark-ips"
47
50
  gem "benchmark_driver"
48
51
  gem "benchmark-ipsa"
49
52
  gem "benchmark-memory"
53
+
54
+ eval_gemfile File.expand_path("../Gemfile", __dir__)
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
  [![Gem Version](https://img.shields.io/gem/v/sentry-rails.svg)](https://rubygems.org/gems/sentry-rails)
14
- ![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-rails%20Test/badge.svg)
14
+ ![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_rails_test.yml/badge.svg)
15
15
  [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master)
16
16
  [![Gem](https://img.shields.io/gem/dt/sentry-rails.svg)](https://rubygems.org/gems/sentry-rails/)
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)
@@ -2,6 +2,8 @@ module Sentry
2
2
  module Rails
3
3
  module ActionCableExtensions
4
4
  class ErrorHandler
5
+ OP_NAME = "websocket.server".freeze
6
+
5
7
  class << self
6
8
  def capture(connection, transaction_name:, extra_context: nil, &block)
7
9
  return block.call unless Sentry.initialized?
@@ -13,13 +15,14 @@ module Sentry
13
15
  Sentry.with_scope do |scope|
14
16
  scope.set_rack_env(env)
15
17
  scope.set_context("action_cable", extra_context) if extra_context
16
- scope.set_transaction_name(transaction_name)
17
- transaction = start_transaction(env, scope.transaction_name)
18
+ scope.set_transaction_name(transaction_name, source: :view)
19
+ transaction = start_transaction(env, scope)
18
20
  scope.set_span(transaction) if transaction
19
21
 
20
22
  begin
21
- block.call
23
+ result = block.call
22
24
  finish_transaction(transaction, 200)
25
+ result
23
26
  rescue Exception => e # rubocop:disable Lint/RescueException
24
27
  Sentry::Rails.capture_exception(e)
25
28
  finish_transaction(transaction, 500)
@@ -29,10 +32,9 @@ module Sentry
29
32
  end
30
33
  end
31
34
 
32
- def start_transaction(env, transaction_name)
33
- sentry_trace = env["HTTP_SENTRY_TRACE"]
34
- options = { name: transaction_name, op: "rails.action_cable".freeze }
35
- transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace
35
+ def start_transaction(env, scope)
36
+ options = { name: scope.transaction_name, source: scope.transaction_source, op: OP_NAME }
37
+ transaction = Sentry.continue_trace(env, **options)
36
38
  Sentry.start_transaction(transaction: transaction, **options)
37
39
  end
38
40
 
@@ -16,16 +16,18 @@ module Sentry
16
16
  end
17
17
 
18
18
  class SentryReporter
19
+ OP_NAME = "queue.active_job".freeze
20
+
19
21
  class << self
20
22
  def record(job, &block)
21
23
  Sentry.with_scope do |scope|
22
24
  begin
23
- scope.set_transaction_name(job.class.name)
25
+ scope.set_transaction_name(job.class.name, source: :task)
24
26
  transaction =
25
27
  if job.is_a?(::Sentry::SendEventJob)
26
28
  nil
27
29
  else
28
- Sentry.start_transaction(name: scope.transaction_name, op: "active_job")
30
+ Sentry.start_transaction(name: scope.transaction_name, source: scope.transaction_source, op: OP_NAME)
29
31
  end
30
32
 
31
33
  scope.set_span(transaction) if transaction
@@ -3,8 +3,11 @@ module Sentry
3
3
  def _perform(&block)
4
4
  block.call
5
5
  ensure
6
- # make sure the background worker returns AR connection if it accidentally acquire one during serialization
7
- ActiveRecord::Base.connection_pool.release_connection
6
+ # some applications have partial or even no AR connection
7
+ if ActiveRecord::Base.connected?
8
+ # make sure the background worker returns AR connection if it accidentally acquire one during serialization
9
+ ActiveRecord::Base.connection_pool.release_connection
10
+ end
8
11
  end
9
12
  end
10
13
  end
@@ -1,20 +1,14 @@
1
- require "sentry/rails/instrument_payload_cleanup_helper"
2
-
3
1
  module Sentry
4
2
  module Rails
5
3
  module Breadcrumb
6
4
  module ActiveSupportLogger
7
5
  class << self
8
- include InstrumentPayloadCleanupHelper
9
-
10
6
  def add(name, started, _finished, _unique_id, data)
11
7
  # skip Rails' internal events
12
8
  return if name.start_with?("!")
13
9
 
14
10
  if data.is_a?(Hash)
15
- # we should only mutate the copy of the data
16
- data = data.dup
17
- cleanup_data(data)
11
+ data = data.slice(*@allowed_keys[name])
18
12
  end
19
13
 
20
14
  crumb = Sentry::Breadcrumb.new(
@@ -25,7 +19,9 @@ module Sentry
25
19
  Sentry.add_breadcrumb(crumb)
26
20
  end
27
21
 
28
- def inject
22
+ def inject(allowed_keys)
23
+ @allowed_keys = allowed_keys
24
+
29
25
  @subscriber = ::ActiveSupport::Notifications.subscribe(/.*/) do |name, started, finished, unique_id, data|
30
26
  # we only record events that has a started timestamp
31
27
  if started.is_a?(Time)
@@ -1,11 +1,13 @@
1
1
  module Sentry
2
2
  module Rails
3
3
  class CaptureExceptions < Sentry::Rack::CaptureExceptions
4
- def initialize(app)
4
+ RAILS_7_1 = Gem::Version.new(::Rails.version) >= Gem::Version.new("7.1.0.alpha")
5
+
6
+ def initialize(_)
5
7
  super
6
8
 
7
- if defined?(::Sprockets::Rails)
8
- @assets_regex = %r(\A/{0,2}#{::Rails.application.config.assets.prefix})
9
+ if Sentry.initialized?
10
+ @assets_regexp = Sentry.configuration.rails.assets_regexp
9
11
  end
10
12
  end
11
13
 
@@ -17,20 +19,12 @@ module Sentry
17
19
  end
18
20
 
19
21
  def transaction_op
20
- "rails.request".freeze
22
+ "http.server".freeze
21
23
  end
22
24
 
23
25
  def capture_exception(exception, env)
24
- request = ActionDispatch::Request.new(env)
25
-
26
26
  # the exception will be swallowed by ShowExceptions middleware
27
- return if request.show_exceptions? && !Sentry.configuration.rails.report_rescued_exceptions
28
-
29
- current_scope = Sentry.get_current_scope
30
-
31
- if original_transaction = env["sentry.original_transaction"]
32
- current_scope.set_transaction_name(original_transaction)
33
- end
27
+ return if show_exceptions?(exception, env) && !Sentry.configuration.rails.report_rescued_exceptions
34
28
 
35
29
  Sentry::Rails.capture_exception(exception).tap do |event|
36
30
  env[ERROR_EVENT_ID_KEY] = event.event_id if event
@@ -38,16 +32,25 @@ module Sentry
38
32
  end
39
33
 
40
34
  def start_transaction(env, scope)
41
- sentry_trace = env["HTTP_SENTRY_TRACE"]
42
- options = { name: scope.transaction_name, op: transaction_op }
35
+ options = { name: scope.transaction_name, source: scope.transaction_source, op: transaction_op }
43
36
 
44
- if @assets_regex && scope.transaction_name.match?(@assets_regex)
37
+ if @assets_regexp && scope.transaction_name.match?(@assets_regexp)
45
38
  options.merge!(sampled: false)
46
39
  end
47
40
 
48
- transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace
41
+ transaction = Sentry.continue_trace(env, **options)
49
42
  Sentry.start_transaction(transaction: transaction, custom_sampling_context: { env: env }, **options)
50
43
  end
44
+
45
+ def show_exceptions?(exception, env)
46
+ request = ActionDispatch::Request.new(env)
47
+
48
+ if RAILS_7_1
49
+ ActionDispatch::ExceptionWrapper.new(nil, exception).show?(request)
50
+ else
51
+ request.show_exceptions?
52
+ end
53
+ end
51
54
  end
52
55
  end
53
56
  end
@@ -12,7 +12,12 @@ module Sentry
12
12
  @excluded_exceptions = @excluded_exceptions.concat(Sentry::Rails::IGNORE_DEFAULT)
13
13
 
14
14
  if ::Rails.logger
15
- @logger = ::Rails.logger
15
+ if defined?(::ActiveSupport::BroadcastLogger) && ::Rails.logger.is_a?(::ActiveSupport::BroadcastLogger)
16
+ dupped_broadcasts = ::Rails.logger.broadcasts.map(&:dup)
17
+ @logger = ::ActiveSupport::BroadcastLogger.new(*dupped_broadcasts)
18
+ else
19
+ @logger = ::Rails.logger.dup
20
+ end
16
21
  else
17
22
  @logger.warn(Sentry::LOGGER_PROGNAME) do
18
23
  <<~MSG
@@ -41,6 +46,67 @@ module Sentry
41
46
  'ActionDispatch::Http::Parameters::ParseError',
42
47
  'ActiveRecord::RecordNotFound'
43
48
  ].freeze
49
+
50
+ ACTIVE_SUPPORT_LOGGER_SUBSCRIPTION_ITEMS_DEFAULT = {
51
+ # action_controller
52
+ "write_fragment.action_controller" => %i[key],
53
+ "read_fragment.action_controller" => %i[key],
54
+ "exist_fragment?.action_controller" => %i[key],
55
+ "expire_fragment.action_controller" => %i[key],
56
+ "start_processing.action_controller" => %i[controller action params format method path],
57
+ "process_action.action_controller" => %i[controller action params format method path status view_runtime db_runtime],
58
+ "send_file.action_controller" => %i[path],
59
+ "redirect_to.action_controller" => %i[status location],
60
+ "halted_callback.action_controller" => %i[filter],
61
+ # action_dispatch
62
+ "process_middleware.action_dispatch" => %i[middleware],
63
+ # action_view
64
+ "render_template.action_view" => %i[identifier layout],
65
+ "render_partial.action_view" => %i[identifier],
66
+ "render_collection.action_view" => %i[identifier count cache_hits],
67
+ "render_layout.action_view" => %i[identifier],
68
+ # active_record
69
+ "sql.active_record" => %i[sql name statement_name cached],
70
+ "instantiation.active_record" => %i[record_count class_name],
71
+ # action_mailer
72
+ # not including to, from, or subject..etc. because of PII concern
73
+ "deliver.action_mailer" => %i[mailer date perform_deliveries],
74
+ "process.action_mailer" => %i[mailer action params],
75
+ # active_support
76
+ "cache_read.active_support" => %i[key store hit],
77
+ "cache_generate.active_support" => %i[key store],
78
+ "cache_fetch_hit.active_support" => %i[key store],
79
+ "cache_write.active_support" => %i[key store],
80
+ "cache_delete.active_support" => %i[key store],
81
+ "cache_exist?.active_support" => %i[key store],
82
+ # active_job
83
+ "enqueue_at.active_job" => %i[],
84
+ "enqueue.active_job" => %i[],
85
+ "enqueue_retry.active_job" => %i[],
86
+ "perform_start.active_job" => %i[],
87
+ "perform.active_job" => %i[],
88
+ "retry_stopped.active_job" => %i[],
89
+ "discard.active_job" => %i[],
90
+ # action_cable
91
+ "perform_action.action_cable" => %i[channel_class action],
92
+ "transmit.action_cable" => %i[channel_class],
93
+ "transmit_subscription_confirmation.action_cable" => %i[channel_class],
94
+ "transmit_subscription_rejection.action_cable" => %i[channel_class],
95
+ "broadcast.action_cable" => %i[broadcasting],
96
+ # active_storage
97
+ "service_upload.active_storage" => %i[service key checksum],
98
+ "service_streaming_download.active_storage" => %i[service key],
99
+ "service_download_chunk.active_storage" => %i[service key],
100
+ "service_download.active_storage" => %i[service key],
101
+ "service_delete.active_storage" => %i[service key],
102
+ "service_delete_prefixed.active_storage" => %i[service prefix],
103
+ "service_exist.active_storage" => %i[service key exist],
104
+ "service_url.active_storage" => %i[service key url],
105
+ "service_update_metadata.active_storage" => %i[service key],
106
+ "preview.active_storage" => %i[key],
107
+ "analyze.active_storage" => %i[analyzer],
108
+ }.freeze
109
+
44
110
  class Configuration
45
111
  # Rails 7.0 introduced a new error reporter feature, which the SDK once opted-in by default.
46
112
  # But after receiving multiple issue reports, the integration seemed to cause serious troubles to some users.
@@ -60,16 +126,38 @@ module Sentry
60
126
 
61
127
  attr_accessor :tracing_subscribers
62
128
 
129
+ # sentry-rails by default skips asset request' transactions by checking if the path matches
130
+ #
131
+ # ```rb
132
+ # %r(\A/{0,2}#{::Rails.application.config.assets.prefix})
133
+ # ```
134
+ #
135
+ # If you want to use a different pattern, you can configure the `assets_regexp` option like:
136
+ #
137
+ # ```rb
138
+ # Sentry.init do |config|
139
+ # config.rails.assets_regexp = /my_regexp/
140
+ # end
141
+ # ```
142
+ attr_accessor :assets_regexp
143
+
144
+ # Hash of subscription items that will be shown in breadcrumbs active support logger.
145
+ # @return [Hash<String, Array<Symbol>>]
146
+ attr_accessor :active_support_logger_subscription_items
147
+
63
148
  def initialize
64
149
  @register_error_subscriber = false
65
150
  @report_rescued_exceptions = true
66
151
  @skippable_job_adapters = []
152
+ @assets_regexp = if defined?(::Sprockets::Rails)
153
+ %r(\A/{0,2}#{::Rails.application.config.assets.prefix})
154
+ end
67
155
  @tracing_subscribers = Set.new([
68
- Sentry::Rails::Tracing::ActionControllerSubscriber,
69
156
  Sentry::Rails::Tracing::ActionViewSubscriber,
70
157
  Sentry::Rails::Tracing::ActiveRecordSubscriber,
71
158
  Sentry::Rails::Tracing::ActiveStorageSubscriber
72
159
  ])
160
+ @active_support_logger_subscription_items = Sentry::Rails::ACTIVE_SUPPORT_LOGGER_SUBSCRIPTION_ITEMS_DEFAULT.dup
73
161
  end
74
162
  end
75
163
  end
@@ -2,8 +2,34 @@ module Sentry
2
2
  module Rails
3
3
  module ControllerTransaction
4
4
  def self.included(base)
5
- base.prepend_before_action do |controller|
6
- Sentry.get_current_scope.set_transaction_name("#{controller.class}##{controller.action_name}")
5
+ base.prepend_around_action(:sentry_around_action)
6
+ end
7
+
8
+ private
9
+
10
+ def sentry_around_action
11
+ if Sentry.initialized?
12
+ transaction_name = "#{self.class}##{action_name}"
13
+ Sentry.get_current_scope.set_transaction_name(transaction_name, source: :view)
14
+ Sentry.with_child_span(op: "view.process_action.action_controller", description: transaction_name) do |child_span|
15
+ if child_span
16
+ begin
17
+ result = yield
18
+ ensure
19
+ child_span.set_http_status(response.status)
20
+ child_span.set_data(:format, request.format)
21
+ child_span.set_data(:method, request.method)
22
+ child_span.set_data(:path, request.path)
23
+ child_span.set_data(:params, request.params)
24
+ end
25
+
26
+ result
27
+ else
28
+ yield
29
+ end
30
+ end
31
+ else
32
+ yield
7
33
  end
8
34
  end
9
35
  end
@@ -1,7 +1,8 @@
1
1
  module Sentry
2
2
  module Rails
3
3
  # This is not a user-facing class. You should use it with Rails 7.0's error reporter feature and its interfaces.
4
- # See https://github.com/rails/rails/blob/main/activesupport/lib/active_support/error_reporter.rb for more information.
4
+ # See https://github.com/rails/rails/blob/main/activesupport/lib/active_support/error_reporter.rb to learn more about reporting APIs.
5
+ # If you want Sentry to subscribe to the error reporter, please set `config.rails.register_error_subscriber` to `true`.
5
6
  class ErrorSubscriber
6
7
  SKIP_SOURCES = Regexp.union([/.*_cache_store.active_support/])
7
8
 
@@ -13,6 +14,11 @@ module Sentry
13
14
  tags[:source] = source
14
15
  end
15
16
 
17
+ if context[:tags].is_a?(Hash)
18
+ context = context.dup
19
+ tags.merge!(context.delete(:tags))
20
+ end
21
+
16
22
  Sentry::Rails.capture_exception(error, level: severity, contexts: { "rails.error" => context }, tags: tags)
17
23
  end
18
24
  end
@@ -40,6 +40,7 @@ module Sentry
40
40
 
41
41
  configure_project_root
42
42
  configure_trusted_proxies
43
+ configure_cron_timezone
43
44
  extend_controller_methods if defined?(ActionController)
44
45
  patch_background_worker if defined?(ActiveRecord)
45
46
  override_streaming_reporter if defined?(ActionView)
@@ -56,7 +57,9 @@ module Sentry
56
57
 
57
58
  at_exit do
58
59
  # TODO: Add a condition for Rails 7.1 to avoid confliction with https://github.com/rails/rails/pull/44999
59
- Sentry::Rails.capture_exception($ERROR_INFO, tags: { source: "runner" }) if $ERROR_INFO
60
+ if $ERROR_INFO && !($ERROR_INFO.is_a?(SystemExit) && $ERROR_INFO.success?)
61
+ Sentry::Rails.capture_exception($ERROR_INFO, tags: { source: "runner" })
62
+ end
60
63
  end
61
64
  end
62
65
 
@@ -68,6 +71,11 @@ module Sentry
68
71
  Sentry.configuration.trusted_proxies += Array(::Rails.application.config.action_dispatch.trusted_proxies)
69
72
  end
70
73
 
74
+ def configure_cron_timezone
75
+ tz_info = ::ActiveSupport::TimeZone.find_tzinfo(::Rails.application.config.time_zone)
76
+ Sentry.configuration.cron.default_timezone = tz_info.name
77
+ end
78
+
71
79
  def extend_controller_methods
72
80
  require "sentry/rails/controller_methods"
73
81
  require "sentry/rails/controller_transaction"
@@ -87,7 +95,7 @@ module Sentry
87
95
  def inject_breadcrumbs_logger
88
96
  if Sentry.configuration.breadcrumbs_logger.include?(:active_support_logger)
89
97
  require 'sentry/rails/breadcrumb/active_support_logger'
90
- Sentry::Rails::Breadcrumb::ActiveSupportLogger.inject
98
+ Sentry::Rails::Breadcrumb::ActiveSupportLogger.inject(Sentry.configuration.rails.active_support_logger_subscription_items)
91
99
  end
92
100
 
93
101
  if Sentry.configuration.breadcrumbs_logger.include?(:monotonic_active_support_logger)
@@ -115,7 +123,7 @@ module Sentry
115
123
  end
116
124
 
117
125
  def activate_tracing
118
- if Sentry.configuration.tracing_enabled?
126
+ if Sentry.configuration.tracing_enabled? && Sentry.configuration.instrumenter == :sentry
119
127
  subscribers = Sentry.configuration.rails.tracing_subscribers
120
128
  Sentry::Rails::Tracing.register_subscribers(subscribers)
121
129
  Sentry::Rails::Tracing.subscribe_tracing_events
@@ -8,14 +8,20 @@ module Sentry
8
8
  extend InstrumentPayloadCleanupHelper
9
9
 
10
10
  EVENT_NAMES = ["process_action.action_controller"].freeze
11
+ OP_NAME = "view.process_action.action_controller".freeze
11
12
 
12
13
  def self.subscribe!
14
+ Sentry.logger.warn <<~MSG
15
+ DEPRECATION WARNING: sentry-rails has changed its approach on controller span recording and #{self.name} is now depreacted.
16
+ Please stop using or referencing #{self.name} as it will be removed in the next major release.
17
+ MSG
18
+
13
19
  subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
14
20
  controller = payload[:controller]
15
21
  action = payload[:action]
16
22
 
17
23
  record_on_current_span(
18
- op: event_name,
24
+ op: OP_NAME,
19
25
  start_timestamp: payload[START_TIMESTAMP_NAME],
20
26
  description: "#{controller}##{action}",
21
27
  duration: duration
@@ -13,7 +13,33 @@ module Sentry
13
13
  next if EXCLUDED_EVENTS.include? payload[:name]
14
14
 
15
15
  record_on_current_span(op: SPAN_PREFIX + event_name, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:sql], duration: duration) do |span|
16
- span.set_data(:connection_id, payload[:connection_id])
16
+ span.set_tag(:cached, true) if payload.fetch(:cached, false) # cached key is only set for hits in the QueryCache, from Rails 5.1
17
+
18
+ connection = payload[:connection]
19
+
20
+ if payload[:connection_id]
21
+ span.set_data(:connection_id, payload[:connection_id])
22
+
23
+ # we fallback to the base connection on rails < 6.0.0 since the payload doesn't have it
24
+ base_connection = ActiveRecord::Base.connection
25
+ connection ||= base_connection if payload[:connection_id] == base_connection.object_id
26
+ end
27
+
28
+ next unless connection
29
+
30
+ db_config = if connection.pool.respond_to?(:db_config)
31
+ connection.pool.db_config.configuration_hash
32
+ elsif connection.pool.respond_to?(:spec)
33
+ connection.pool.spec.config
34
+ end
35
+
36
+ next unless db_config
37
+
38
+ span.set_data(Span::DataConventions::DB_SYSTEM, db_config[:adapter]) if db_config[:adapter]
39
+ span.set_data(Span::DataConventions::DB_NAME, db_config[:database]) if db_config[:database]
40
+ span.set_data(Span::DataConventions::SERVER_ADDRESS, db_config[:host]) if db_config[:host]
41
+ span.set_data(Span::DataConventions::SERVER_PORT, db_config[:port]) if db_config[:port]
42
+ span.set_data(Span::DataConventions::SERVER_SOCKET_ADDRESS, db_config[:socket]) if db_config[:socket]
17
43
  end
18
44
  end
19
45
  end
@@ -21,7 +21,7 @@ module Sentry
21
21
 
22
22
  def self.subscribe!
23
23
  subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
24
- record_on_current_span(op: event_name, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:service], duration: duration) do |span|
24
+ record_on_current_span(op: "file.#{event_name}".freeze, start_timestamp: payload[START_TIMESTAMP_NAME], description: payload[:service], duration: duration) do |span|
25
25
  payload.each do |key, value|
26
26
  span.set_data(key, value) unless key == START_TIMESTAMP_NAME
27
27
  end
@@ -67,7 +67,7 @@ module Sentry
67
67
  end
68
68
 
69
69
  def self.get_current_transaction
70
- Sentry.get_current_scope.get_transaction
70
+ Sentry.get_current_scope.get_transaction if Sentry.initialized?
71
71
  end
72
72
 
73
73
  # it's just a container for the extended method
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Rails
3
- VERSION = "5.4.2"
3
+ VERSION = "5.16.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 "railties", ">= 5.0"
26
- spec.add_dependency "sentry-ruby", "~> 5.4.2"
26
+ spec.add_dependency "sentry-ruby", "~> 5.16.1"
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: 5.4.2
4
+ version: 5.16.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: 2022-08-17 00:00:00.000000000 Z
11
+ date: 2024-01-09 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: 5.4.2
33
+ version: 5.16.1
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: 5.4.2
40
+ version: 5.16.1
41
41
  description: A gem that provides Rails integration for the Sentry error logger
42
42
  email: accounts@sentry.io
43
43
  executables: []
@@ -49,7 +49,6 @@ files:
49
49
  - ".gitignore"
50
50
  - ".rspec"
51
51
  - CHANGELOG.md
52
- - CODE_OF_CONDUCT.md
53
52
  - Gemfile
54
53
  - LICENSE.txt
55
54
  - Makefile
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at stan001212@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [https://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: https://contributor-covenant.org
74
- [version]: https://contributor-covenant.org/version/1/4/