Module: Sentry::Rails::ActiveJobExtensions
- Defined in:
- lib/sentry/rails/active_job.rb
Defined Under Namespace
Classes: SentryReporter
Constant Summary collapse
- SENTRY_PAYLOAD_KEY =
"_sentry"- USER_FIELDS_ALLOWLIST =
%w[id email username].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #already_supported_by_sentry_integration? ⇒ Boolean
- #deserialize(job_data) ⇒ Object
- #perform_now ⇒ Object
- #serialize ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
14 15 16 |
# File 'lib/sentry/rails/active_job.rb', line 14 def self.prepended(base) base.attr_accessor :_sentry end |
Instance Method Details
#already_supported_by_sentry_integration? ⇒ Boolean
67 68 69 |
# File 'lib/sentry/rails/active_job.rb', line 67 def already_supported_by_sentry_integration? Sentry.configuration.rails.skippable_job_adapters.include?(self.class.queue_adapter.class.to_s) end |
#deserialize(job_data) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sentry/rails/active_job.rb', line 56 def deserialize(job_data) super return if !Sentry.initialized? || already_supported_by_sentry_integration? begin self._sentry = job_data[SENTRY_PAYLOAD_KEY] rescue StandardError => e Sentry.sdk_logger&.error("sentry-rails: failed to extract _sentry payload: #{e.class}: #{e.}\n #{Array(e.backtrace).first(5).join("\n ")}") end end |
#perform_now ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sentry/rails/active_job.rb', line 18 def perform_now if !Sentry.initialized? || already_supported_by_sentry_integration? super else data = _sentry || {} SentryReporter.record( self, trace_headers: data["trace_propagation_headers"], user: data["user"] ) { super } end end |
#serialize ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sentry/rails/active_job.rb', line 31 def serialize payload = super return payload if !Sentry.initialized? || already_supported_by_sentry_integration? begin sentry_data = {} if Sentry.configuration.rails.active_job_propagate_traces headers = Sentry.get_trace_propagation_headers sentry_data["trace_propagation_headers"] = headers if headers && !headers.empty? end if Sentry.configuration.send_default_pii user = Sentry.get_current_scope.user allowed = user.transform_keys(&:to_s).slice(*USER_FIELDS_ALLOWLIST) sentry_data["user"] = allowed unless allowed.empty? end payload[SENTRY_PAYLOAD_KEY] = sentry_data unless sentry_data.empty? rescue StandardError => e Sentry.sdk_logger&.error("sentry-rails: failed to inject _sentry payload: #{e.class}: #{e.}\n #{Array(e.backtrace).first(5).join("\n ")}") end payload end |