sentry-rails 7.2.0 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -0
  3. data/README.md +5 -1
  4. data/gemfiles/ruby-2.7_rails-5.2.0.gemfile.lock +12 -12
  5. data/gemfiles/ruby-2.7_rails-6.0.0.gemfile.lock +12 -12
  6. data/gemfiles/ruby-2.7_rails-6.1.0.gemfile.lock +12 -12
  7. data/gemfiles/ruby-2.7_rails-7.0.0.gemfile.lock +12 -12
  8. data/gemfiles/ruby-2.7_rails-7.1.0.gemfile.lock +12 -12
  9. data/gemfiles/ruby-3.0_rails-6.1.0.gemfile.lock +27 -13
  10. data/gemfiles/ruby-3.0_rails-7.0.0.gemfile.lock +27 -13
  11. data/gemfiles/ruby-3.0_rails-7.1.0.gemfile.lock +27 -13
  12. data/gemfiles/ruby-3.1_rails-6.1.0.gemfile.lock +48 -24
  13. data/gemfiles/ruby-3.1_rails-7.0.0.gemfile.lock +48 -24
  14. data/gemfiles/ruby-3.1_rails-7.1.0.gemfile.lock +48 -24
  15. data/gemfiles/ruby-3.1_rails-7.2.0.gemfile.lock +48 -24
  16. data/gemfiles/ruby-3.2_rails-6.1.0.gemfile.lock +78 -54
  17. data/gemfiles/ruby-3.2_rails-7.0.0.gemfile.lock +78 -54
  18. data/gemfiles/ruby-3.2_rails-7.1.0.gemfile.lock +80 -56
  19. data/gemfiles/ruby-3.2_rails-7.2.0.gemfile.lock +77 -53
  20. data/gemfiles/ruby-3.2_rails-8.0.0.gemfile.lock +149 -125
  21. data/gemfiles/ruby-3.3_rails-6.1.0.gemfile.lock +78 -54
  22. data/gemfiles/ruby-3.3_rails-7.0.0.gemfile.lock +78 -54
  23. data/gemfiles/ruby-3.3_rails-7.1.0.gemfile.lock +80 -56
  24. data/gemfiles/ruby-3.3_rails-7.2.0.gemfile.lock +77 -53
  25. data/gemfiles/ruby-3.3_rails-8.0.0.gemfile.lock +149 -125
  26. data/gemfiles/ruby-3.4_rails-7.1.0.gemfile.lock +62 -46
  27. data/gemfiles/ruby-3.4_rails-7.2.0.gemfile.lock +59 -43
  28. data/gemfiles/ruby-3.4_rails-8.0.0.gemfile.lock +131 -115
  29. data/gemfiles/ruby-3.4_rails-8.1.3.gemfile.lock +131 -115
  30. data/gemfiles/ruby-4.0_rails-6.1.0.gemfile.lock +60 -44
  31. data/gemfiles/ruby-4.0_rails-7.0.0.gemfile.lock +60 -44
  32. data/gemfiles/ruby-4.0_rails-7.1.0.gemfile.lock +62 -46
  33. data/gemfiles/ruby-4.0_rails-8.0.0.gemfile.lock +131 -115
  34. data/gemfiles/ruby-4.0_rails-8.1.3.gemfile.lock +131 -115
  35. data/gemfiles/ruby-jruby-9.4.14.0_rails-6.1.0.gemfile.lock +25 -25
  36. data/gemfiles/ruby-jruby-9.4.14.0_rails-7.0.0.gemfile.lock +25 -25
  37. data/gemfiles/ruby-jruby-9.4.14.0_rails-7.1.0.gemfile.lock +25 -25
  38. data/lib/sentry/rails/active_job.rb +45 -186
  39. data/lib/sentry/rails/active_job_extension.rb +196 -0
  40. data/lib/sentry/rails/configuration.rb +6 -0
  41. data/lib/sentry/rails/good_job_cron.rb +152 -0
  42. data/lib/sentry/rails/solid_queue_recurring.rb +13 -12
  43. data/lib/sentry/rails/version.rb +1 -1
  44. data/lib/sentry/rails.rb +46 -0
  45. data/sentry-rails.gemspec +1 -1
  46. metadata +10 -9
  47. data/bin/test_old +0 -389
@@ -0,0 +1,196 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sentry/rails/serializer"
4
+ require "sentry/rails/error_reporter_context"
5
+
6
+ module Sentry
7
+ module Rails
8
+ # The job extension sentry-rails uses for ActiveJob jobs. Backend gems
9
+ # subclass it to enrich ActiveJob jobs run through their queue adapter, and
10
+ # register it with {Sentry::Rails.register_active_job_extension}.
11
+ class ActiveJobExtension < Sentry::JobExtensions::Extension
12
+ include ErrorReporterContext
13
+
14
+ SPAN_ORIGIN = "auto.queue.active_job"
15
+
16
+ # @param serializer [#serialize] serializes job arguments for error events
17
+ # @see Sentry::JobExtensions::Extension#initialize
18
+ def initialize(name: :active_job, integration: Sentry::Rails, origin: SPAN_ORIGIN, serializer: Sentry::Rails::Serializer)
19
+ super(name: name, integration: integration, origin: origin)
20
+ @serializer = serializer
21
+ end
22
+
23
+ # Returns the name of the job class' queue adapter.
24
+ #
25
+ # @param job_class [Class]
26
+ # @return [Symbol]
27
+ def self.adapter_name(job_class)
28
+ name = job_class.queue_adapter_name if job_class.respond_to?(:queue_adapter_name)
29
+ (name || job_class.queue_adapter.class.name.demodulize.delete_suffix("Adapter").underscore).to_sym
30
+ end
31
+
32
+ # Returns the job's serialized payload carrying Sentry's trace propagation
33
+ # headers and user data.
34
+ #
35
+ # @param job [ActiveJob::Base]
36
+ # @param payload [Hash]
37
+ # @return [Hash]
38
+ def prepare_payload(job:, payload:)
39
+ prepared = payload
40
+ sentry_data = {}
41
+ if Sentry.configuration.rails.active_job_propagate_traces
42
+ headers = Sentry.get_trace_propagation_headers
43
+ if headers && !headers.empty?
44
+ sentry_data["trace_propagation_headers"] = headers
45
+ injected = safely("inject trace headers", fallback: payload) { inject_trace_headers(job: job, payload: payload, headers: headers) }
46
+ prepared = injected if injected.is_a?(Hash)
47
+ end
48
+ end
49
+
50
+ if Sentry.configuration.data_collection.user_info
51
+ user = Sentry.get_current_scope.user.transform_keys(&:to_s).slice(*ActiveJobExtensions::USER_FIELDS_ALLOWLIST)
52
+ sentry_data["user"] = user unless user.empty?
53
+ end
54
+
55
+ sentry_data.empty? ? prepared : prepared.merge(ActiveJobExtensions::SENTRY_PAYLOAD_KEY => sentry_data)
56
+ rescue StandardError => e
57
+ Sentry.sdk_logger&.error("sentry-rails: failed to inject _sentry payload: #{e.class}: #{e.message}\n #{Array(e.backtrace).first(5).join("\n ")}")
58
+ payload
59
+ end
60
+
61
+ # Enqueues the job even when recording its `queue.publish` span fails.
62
+ #
63
+ # @see Sentry::JobExtensions::Extension#instrument_enqueue
64
+ def instrument_enqueue(job:, **context, &enqueue)
65
+ enqueued = false
66
+ super(job: job, **context) do
67
+ enqueued = true
68
+ enqueue.call
69
+ end
70
+ rescue StandardError => e
71
+ raise if enqueued
72
+
73
+ log_failure("record producer span", e)
74
+ enqueue.call
75
+ end
76
+
77
+ # Also applies the user and ActiveJob context the job carries.
78
+ #
79
+ # @see Sentry::JobExtensions::Extension#start_job
80
+ def start_job(scope:, job:, **context)
81
+ user = job._sentry&.[]("user")
82
+ scope.set_user(user.transform_keys(&:to_sym)) if user && !user.empty?
83
+ scope.set_transaction_name(job.class.name, source: :task)
84
+
85
+ super.tap { apply_active_job_context(scope, job) }
86
+ end
87
+
88
+ # Also adds the job's ActiveJob data to the event.
89
+ #
90
+ # @see Sentry::JobExtensions::Extension#capture_exception
91
+ def capture_exception(job:, exception:, contexts: {}, tags: {}, extra: {}, **context)
92
+ data = active_job_error_data(job)
93
+
94
+ super(
95
+ job: job,
96
+ exception: exception,
97
+ contexts: data[:contexts].merge(contexts),
98
+ tags: data[:tags].merge(tags),
99
+ extra: data[:extra].merge(extra),
100
+ **context
101
+ )
102
+ end
103
+
104
+ # Reads the trace propagation headers stored in the job's Sentry payload.
105
+ #
106
+ # @see Sentry::JobExtensions::Extension#extract_trace_headers
107
+ def extract_trace_headers(job:, **)
108
+ job._sentry&.[]("trace_propagation_headers") || {}
109
+ end
110
+
111
+ # Describes the job with its ActiveJob messaging attributes, its receive
112
+ # latency and body size.
113
+ #
114
+ # @see Sentry::JobExtensions::Extension#messaging_data
115
+ def messaging_data(job:, **)
116
+ data = active_job_messaging_data(job)
117
+ data[:receive_latency] = Sentry::Utils::Latency.milliseconds_since(job.enqueued_at) if job.respond_to?(:enqueued_at)
118
+ data[:body_size] = body_size(job._sentry_job_data) if Sentry.get_current_scope.get_span&.sampled
119
+ data.compact
120
+ end
121
+
122
+ # Describes the job with its ActiveJob messaging attributes.
123
+ #
124
+ # @see Sentry::JobExtensions::Extension#publish_messaging_data
125
+ def publish_messaging_data(job:, **)
126
+ active_job_messaging_data(job)
127
+ end
128
+
129
+ # Follows `config.rails.active_job_report_on_retry_error`.
130
+ #
131
+ # @see Sentry::JobExtensions::Extension#report_retried_exception?
132
+ def report_retried_exception?(job:, exception:, **)
133
+ Sentry.configuration.rails.active_job_report_on_retry_error
134
+ end
135
+
136
+ private
137
+
138
+ def log_failure(context, error)
139
+ Sentry.sdk_logger&.error("sentry-rails: job extension #{name.inspect} failed to #{context}: #{error.class}: #{error.message}\n #{Array(error.backtrace).first(5).join("\n ")}")
140
+ end
141
+
142
+ def active_job_messaging_data(job)
143
+ name = job.class.queue_adapter_name if job.class.respond_to?(:queue_adapter_name)
144
+ {
145
+ system: name.to_s.empty? ? "activejob" : name.to_s,
146
+ message_id: job.job_id,
147
+ destination: job.queue_name,
148
+ retry_count: (job.executions.to_i if job.respond_to?(:executions))
149
+ }.compact
150
+ end
151
+
152
+ def body_size(payload)
153
+ JSON.generate(payload).bytesize if payload
154
+ rescue StandardError
155
+ nil
156
+ end
157
+
158
+ def apply_active_job_context(scope, job)
159
+ required = {
160
+ job_class: job.class.name,
161
+ job_id: job.job_id,
162
+ queue: job.queue_name,
163
+ provider_job_id: job.provider_job_id
164
+ }
165
+ scope.set_contexts(active_job: scope.contexts.fetch(:active_job, {}).merge(required))
166
+ scope.set_tags(queue: job.queue_name)
167
+ end
168
+
169
+ def active_job_error_data(job)
170
+ queues = Sentry.configuration.data_collection.queues
171
+ extra = {
172
+ active_job: job.class.name,
173
+ scheduled_at: job.scheduled_at,
174
+ job_id: job.job_id,
175
+ provider_job_id: job.provider_job_id,
176
+ locale: job.locale
177
+ }
178
+ arguments = serialize_arguments(job.arguments) if queues
179
+ extra[:arguments] = arguments unless arguments.nil?
180
+
181
+ {
182
+ contexts: queues ? execution_context : {},
183
+ tags: { job_id: job.job_id, provider_job_id: job.provider_job_id },
184
+ extra: extra
185
+ }
186
+ end
187
+
188
+ def serialize_arguments(arguments)
189
+ @serializer.serialize(arguments)
190
+ rescue StandardError => e
191
+ Sentry.sdk_logger&.error("sentry-rails: failed to serialize job arguments: #{e.class}: #{e.message}")
192
+ nil
193
+ end
194
+ end
195
+ end
196
+ end
@@ -183,6 +183,11 @@ module Sentry
183
183
  # Defaults to true. Set to false to opt out.
184
184
  attr_accessor :active_job_propagate_traces
185
185
 
186
+ # GoodJob cron keys to skip when the :good_job_cron patch is enabled.
187
+ # Strings and Symbols match the key exactly; Regexps are matched against it.
188
+ # @return [Array<String, Symbol, Regexp>]
189
+ attr_accessor :good_job_exclude_cron_jobs
190
+
186
191
  # Solid Queue recurring task keys to skip when the :solid_queue_recurring patch is enabled.
187
192
  # Strings match the key exactly; Regexps are matched against it.
188
193
  # @return [Array<String, Regexp>]
@@ -210,6 +215,7 @@ module Sentry
210
215
  @active_support_logger_subscription_items = Sentry::Rails::ACTIVE_SUPPORT_LOGGER_SUBSCRIPTION_ITEMS_DEFAULT.dup
211
216
  @active_job_report_on_retry_error = false
212
217
  @active_job_propagate_traces = true
218
+ @good_job_exclude_cron_jobs = []
213
219
  @solid_queue_exclude_recurring_tasks = []
214
220
  @structured_logging = StructuredLoggingConfiguration.new
215
221
  end
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sentry
4
+ module Rails
5
+ # Sends Crons check-ins for GoodJob cron entries.
6
+ # Enable with `config.enabled_patches << :good_job_cron`.
7
+ module GoodJobCron
8
+ EVENT_STATE = :sentry_good_job_cron
9
+ MINIMUM_GOOD_JOB_VERSION = Gem::Version.new("4.0")
10
+
11
+ class << self
12
+ def excluded?(key)
13
+ return false unless Sentry.initialized?
14
+
15
+ key = key.to_s
16
+ Array(Sentry.configuration.rails.good_job_exclude_cron_jobs).any? do |pattern|
17
+ (pattern.is_a?(Symbol) ? pattern.to_s : pattern) === key
18
+ end
19
+ rescue StandardError => e
20
+ Sentry.sdk_logger.error(Sentry::LOGGER_PROGNAME) { "Could not check good_job_exclude_cron_jobs for #{key}: #{e.class}: #{e.message}" }
21
+ false
22
+ end
23
+
24
+ # The persisted record identifies the cron run, including retries and callable classes.
25
+ def monitor_for(job)
26
+ key = job.cron_key
27
+ return unless key && Sentry.initialized?
28
+ return if excluded?(key)
29
+
30
+ entry = ::GoodJob::CronEntry.find(key)
31
+ job_class = job.job_class.safe_constantize
32
+ return if job_class && job_class < Sentry::Cron::MonitorCheckIns::Patch
33
+
34
+ slug = Sentry::Cron::Slug.from(entry.key)
35
+ return unless slug
36
+
37
+ config = schedule_for(entry)
38
+ unless config
39
+ Sentry.sdk_logger.debug(Sentry::LOGGER_PROGNAME) { "Not monitoring GoodJob cron entry #{entry.key}: its schedule can't be expressed as a Crons schedule." }
40
+ return
41
+ end
42
+ return if slug_shared?(entry.key, slug)
43
+
44
+ [slug, config]
45
+ rescue StandardError => e
46
+ Sentry.sdk_logger.error(Sentry::LOGGER_PROGNAME) { "Not monitoring GoodJob cron entry #{key}: #{e.class}: #{e.message}" }
47
+ nil
48
+ end
49
+
50
+ # Evented subscribers receive start before execution and finish afterwards.
51
+ # State belongs to the notification payload, so nested and concurrent runs are independent.
52
+ def start(_name, _id, payload)
53
+ return unless Sentry.initialized? && Sentry.configuration.enabled_patches.include?(:good_job_cron)
54
+
55
+ monitor = monitor_for(payload[:job])
56
+ return unless monitor
57
+
58
+ slug, schedule = monitor
59
+ cron_config = Sentry.configuration.cron
60
+ config = Sentry::Cron::MonitorConfig.from_crontab(
61
+ schedule.schedule.value,
62
+ timezone: schedule.timezone,
63
+ checkin_margin: cron_config.default_checkin_margin,
64
+ max_runtime: cron_config.default_max_runtime
65
+ )
66
+ check_in_id = Sentry.capture_check_in(slug, :in_progress, monitor_config: config)
67
+ payload[EVENT_STATE] = { slug: slug, check_in_id: check_in_id, started_at: monotonic_now }
68
+ rescue StandardError => e
69
+ log_error(e)
70
+ end
71
+
72
+ def finish(_name, _id, payload)
73
+ state = payload.delete(EVENT_STATE)
74
+ return unless state && Sentry.initialized?
75
+
76
+ error = payload[:handled_error] || payload[:unhandled_error] || payload[:error] || payload[:exception]
77
+ Sentry.capture_check_in(
78
+ state[:slug], error ? :error : :ok,
79
+ check_in_id: state[:check_in_id], duration: monotonic_now - state[:started_at]
80
+ )
81
+ rescue StandardError => e
82
+ log_error(e)
83
+ end
84
+
85
+ def patch
86
+ return if @subscriber
87
+
88
+ @subscriber = ActiveSupport::Notifications.subscribe("perform_job.good_job", self)
89
+ end
90
+
91
+ private
92
+
93
+ def log_error(error)
94
+ Sentry.sdk_logger.error(Sentry::LOGGER_PROGNAME) { "Could not send GoodJob cron check-in: #{error.class}: #{error.message}" }
95
+ end
96
+
97
+ def monotonic_now
98
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
99
+ end
100
+
101
+ # Proc schedules can change between runs. Match the scheduler's local-zone
102
+ # resolution: EtOrbi prefers ENV['TZ'], then the Rails app's default zone.
103
+ # A request's temporary Time.use_zone must not change the monitor's zone.
104
+ def schedule_for(entry)
105
+ cron = entry.params[:cron]
106
+ return if cron.respond_to?(:call)
107
+
108
+ Time.use_zone(Time.zone_default) { Sentry::Cron::FugitSchedule.from_cron(::Fugit.parse(cron)) }
109
+ end
110
+
111
+ # Different keys can share a slug, like long keys cut at the same length.
112
+ # One monitor can't follow two schedules, so none of them are monitored.
113
+ def slug_shared?(key, slug)
114
+ colliding = ::GoodJob::CronEntry.all.select do |other|
115
+ other.key.to_s != key.to_s && Sentry::Cron::Slug.from(other.key) == slug && monitored?(other)
116
+ end.map(&:key)
117
+ return false if colliding.empty?
118
+
119
+ @slug_warnings ||= Concurrent::Map.new
120
+ if @slug_warnings.put_if_absent(key.to_s, true).nil?
121
+ Sentry.sdk_logger.warn(Sentry::LOGGER_PROGNAME) do
122
+ "Not monitoring GoodJob cron entry #{key}: its monitor slug #{slug} is also used by #{colliding.join(", ")}. Rename or exclude one of them."
123
+ end
124
+ end
125
+ true
126
+ end
127
+
128
+ def monitored?(entry)
129
+ return false if excluded?(entry.key) || !schedule_for(entry)
130
+
131
+ job_class = entry.job_class
132
+ job_class = job_class.safe_constantize if job_class.is_a?(String)
133
+ !(job_class.is_a?(Class) && job_class < Sentry::Cron::MonitorCheckIns::Patch)
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ Sentry.register_patch(:good_job_cron) do |config|
141
+ if defined?(::GoodJob) && defined?(::Rails.application) && ::Rails.application
142
+ if Gem::Version.new(::GoodJob::VERSION) < Sentry::Rails::GoodJobCron::MINIMUM_GOOD_JOB_VERSION
143
+ config.sdk_logger.warn(Sentry::LOGGER_PROGNAME) do
144
+ "The GoodJob cron integration requires good_job #{Sentry::Rails::GoodJobCron::MINIMUM_GOOD_JOB_VERSION} or later, but #{::GoodJob::VERSION} is installed."
145
+ end
146
+ else
147
+ Sentry::Rails::GoodJobCron.patch
148
+ end
149
+ else
150
+ config.sdk_logger.warn(Sentry::LOGGER_PROGNAME) { "You tried to enable the GoodJob cron integration but the `good_job` gem was not detected." }
151
+ end
152
+ end
@@ -52,7 +52,9 @@ module Sentry
52
52
  return unless slug
53
53
 
54
54
  config = Sentry::Cron::FugitSchedule.from_cron(cron_for(task))
55
- { "slug" => slug, "crontab" => config&.schedule&.value, "timezone" => config&.timezone }.compact
55
+ return unless config
56
+
57
+ { "slug" => slug, "crontab" => config.schedule.value, "timezone" => config.timezone }.compact
56
58
  rescue StandardError => e
57
59
  Sentry.sdk_logger.error(Sentry::LOGGER_PROGNAME) { "Not monitoring Solid Queue recurring task #{task.key}: #{e.class}: #{e.message}" }
58
60
  nil
@@ -62,18 +64,17 @@ module Sentry
62
64
  data = job.instance_variable_get(:@_sentry_recurring_task)
63
65
  return yield unless data && Sentry.initialized?
64
66
 
65
- slug = data["slug"]
66
- if data["crontab"]
67
- cron_config = Sentry.configuration.cron
68
- monitor_config = Sentry::Cron::MonitorConfig.from_crontab(
69
- data["crontab"],
70
- timezone: data["timezone"],
71
- checkin_margin: cron_config.default_checkin_margin,
72
- max_runtime: cron_config.default_max_runtime
73
- )
74
- end
67
+ return yield unless data["crontab"]
68
+
69
+ cron_config = Sentry.configuration.cron
70
+ monitor_config = Sentry::Cron::MonitorConfig.from_crontab(
71
+ data["crontab"],
72
+ timezone: data["timezone"],
73
+ checkin_margin: cron_config.default_checkin_margin,
74
+ max_runtime: cron_config.default_max_runtime
75
+ )
75
76
 
76
- Sentry::Cron::MonitorCheckIns.with_check_in(slug, monitor_config: monitor_config) { yield }
77
+ Sentry::Cron::MonitorCheckIns.with_check_in(data["slug"], monitor_config: monitor_config) { yield }
77
78
  end
78
79
 
79
80
  def patch
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sentry
4
4
  module Rails
5
- VERSION = "7.2.0"
5
+ VERSION = "7.3.0"
6
6
  end
7
7
  end
data/lib/sentry/rails.rb CHANGED
@@ -5,14 +5,60 @@ require "sentry-ruby"
5
5
  require "sentry/integrable"
6
6
  require "sentry/rails/tracing"
7
7
  require "sentry/rails/configuration"
8
+ require "sentry/rails/active_job_extension"
8
9
  require "sentry/rails/structured_logging"
9
10
  require "sentry/rails/engine"
10
11
  require "sentry/rails/railtie"
12
+ require "sentry/rails/good_job_cron"
11
13
  require "sentry/rails/solid_queue_recurring"
12
14
 
13
15
  module Sentry
14
16
  module Rails
15
17
  extend Integrable
16
18
  register_integration name: "rails", version: Sentry::Rails::VERSION
19
+
20
+ DEFAULT_ACTIVE_JOB_EXTENSION = ActiveJobExtension.new
21
+ private_constant :DEFAULT_ACTIVE_JOB_EXTENSION
22
+
23
+ # Returns whether sentry-rails reports ActiveJob jobs run through the given
24
+ # queue adapter, in which case the backend gem should not report them itself.
25
+ # The result depends on the current configuration, so check it when a job is
26
+ # handled rather than caching it.
27
+ #
28
+ # @param adapter_class_name [String, Class]
29
+ # @return [Boolean]
30
+ def self.active_job_owns_adapter?(adapter_class_name)
31
+ Sentry.initialized? && !Sentry.configuration.rails.skippable_job_adapters.include?(adapter_class_name.to_s)
32
+ end
33
+
34
+ # Registers the extension for ActiveJob jobs run through the given queue
35
+ # adapter. Raises ArgumentError if it is not an {ActiveJobExtension}.
36
+ #
37
+ # @param adapter [Symbol] the adapter name, such as `:sidekiq`
38
+ # @param extension [ActiveJobExtension]
39
+ # @return [ActiveJobExtension]
40
+ def self.register_active_job_extension(adapter, extension)
41
+ unless extension.is_a?(ActiveJobExtension)
42
+ raise ArgumentError, "ActiveJob extension must be an instance of #{ActiveJobExtension}, got #{extension.inspect}"
43
+ end
44
+
45
+ active_job_extensions[adapter.to_sym] = extension
46
+ end
47
+
48
+ # Returns the extension for the job class' queue adapter, or the default
49
+ # {ActiveJobExtension} when none is registered.
50
+ #
51
+ # @param job_class [Class]
52
+ # @return [ActiveJobExtension]
53
+ def self.active_job_extension_for(job_class)
54
+ active_job_extensions.fetch(ActiveJobExtension.adapter_name(job_class), DEFAULT_ACTIVE_JOB_EXTENSION)
55
+ end
56
+
57
+ # Returns the registered extensions by adapter name.
58
+ #
59
+ # @return [Hash{Symbol => ActiveJobExtension}]
60
+ def self.active_job_extensions
61
+ @active_job_extensions ||= {}
62
+ end
17
63
  end
18
64
  end
data/sentry-rails.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_dependency "railties", ">= 5.2.0"
34
- spec.add_dependency "sentry-ruby", "~> 7.2.0"
34
+ spec.add_dependency "sentry-ruby", "~> 7.3.0"
35
35
 
36
36
  spec.post_install_message = <<~MSG
37
37
  Starting with sentry-rails 7.1.0, Rails structured logging is disabled by default.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.0
4
+ version: 7.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: 7.2.0
32
+ version: 7.3.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 7.2.0
39
+ version: 7.3.0
40
40
  description: A gem that provides Rails integration for the Sentry error logger
41
41
  email: accounts@sentry.io
42
42
  executables: []
@@ -57,7 +57,6 @@ files:
57
57
  - bin/console
58
58
  - bin/setup
59
59
  - bin/test
60
- - bin/test_old
61
60
  - gemfiles/ruby-2.7_rails-5.2.0.gemfile.lock
62
61
  - gemfiles/ruby-2.7_rails-6.0.0.gemfile.lock
63
62
  - gemfiles/ruby-2.7_rails-6.1.0.gemfile.lock
@@ -97,6 +96,7 @@ files:
97
96
  - lib/sentry/rails.rb
98
97
  - lib/sentry/rails/action_cable.rb
99
98
  - lib/sentry/rails/active_job.rb
99
+ - lib/sentry/rails/active_job_extension.rb
100
100
  - lib/sentry/rails/background_worker.rb
101
101
  - lib/sentry/rails/backtrace_cleaner.rb
102
102
  - lib/sentry/rails/breadcrumb/active_support_logger.rb
@@ -107,6 +107,7 @@ files:
107
107
  - lib/sentry/rails/engine.rb
108
108
  - lib/sentry/rails/error_reporter_context.rb
109
109
  - lib/sentry/rails/error_subscriber.rb
110
+ - lib/sentry/rails/good_job_cron.rb
110
111
  - lib/sentry/rails/log_subscriber.rb
111
112
  - lib/sentry/rails/log_subscribers/action_controller_subscriber.rb
112
113
  - lib/sentry/rails/log_subscribers/action_mailer_subscriber.rb
@@ -126,15 +127,15 @@ files:
126
127
  - lib/sentry/rails/tracing/active_support_subscriber.rb
127
128
  - lib/sentry/rails/version.rb
128
129
  - sentry-rails.gemspec
129
- homepage: https://github.com/getsentry/sentry-ruby/tree/7.2.0/sentry-rails
130
+ homepage: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-rails
130
131
  licenses:
131
132
  - MIT
132
133
  metadata:
133
- homepage_uri: https://github.com/getsentry/sentry-ruby/tree/7.2.0/sentry-rails
134
- source_code_uri: https://github.com/getsentry/sentry-ruby/tree/7.2.0/sentry-rails
135
- changelog_uri: https://github.com/getsentry/sentry-ruby/blob/7.2.0/CHANGELOG.md
134
+ homepage_uri: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-rails
135
+ source_code_uri: https://github.com/getsentry/sentry-ruby/tree/7.3.0/sentry-rails
136
+ changelog_uri: https://github.com/getsentry/sentry-ruby/blob/7.3.0/CHANGELOG.md
136
137
  bug_tracker_uri: https://github.com/getsentry/sentry-ruby/issues
137
- documentation_uri: http://www.rubydoc.info/gems/sentry-rails/7.2.0
138
+ documentation_uri: http://www.rubydoc.info/gems/sentry-rails/7.3.0
138
139
  post_install_message: |
139
140
  Starting with sentry-rails 7.1.0, Rails structured logging is disabled by default.
140
141
  Set `config.rails.structured_logging.enabled = true` to enable it.