@@ -395,6 +395,59 @@ def reported_executions(job_class, error, adapter_skipped:)
395395 end
396396 end
397397
398+ context "when the queued ActiveJob class cannot be loaded" do
399+ let ( :traces_sample_rate ) { nil }
400+
401+ [ nil , 1.0 ] . each do |sample_rate |
402+ it "preserves native error enrichment and the incoming trace at sample rate #{ sample_rate . inspect } " do
403+ Sentry . configuration . traces_sample_rate = sample_rate
404+ worker_transaction = Sentry . start_transaction ( name : "worker" , op : "test" )
405+ Sentry . get_main_hub . current_scope . set_span ( worker_transaction ) if worker_transaction
406+
407+ message = sidekiq_message (
408+ parity_job ,
409+ retry : false ,
410+ tags : [ "marvel" ] ,
411+ sentry_user : { "id" => "42" } ,
412+ trace_propagation_headers : { "sentry-trace" => "#{ "a" * 32 } -#{ "b" * 16 } -0" }
413+ )
414+ message [ "wrapped" ] = "RemovedJob"
415+ message [ "args" ] . first [ "job_class" ] = "RemovedJob"
416+
417+ native_errors = process ( message , adapter_skipped : true ) . grep ( Sentry ::ErrorEvent )
418+ active_job_errors = process ( message , adapter_skipped : false ) . grep ( Sentry ::ErrorEvent )
419+
420+ expect ( native_errors . size ) . to eq ( 1 )
421+ expect ( active_job_errors . size ) . to eq ( 1 )
422+ expect ( active_job_errors . first . tags ) . to include ( native_errors . first . tags )
423+ expect ( active_job_errors . first . user ) . to eq ( native_errors . first . user )
424+ expect ( active_job_errors . first . contexts . dig ( :trace , :trace_id ) ) . to eq ( "a" * 32 )
425+ end
426+ end
427+
428+ it "restores the worker hub and payload after a failure before perform_now" do
429+ skip_sidekiq_adapter ( false )
430+ message = sidekiq_message ( parity_job , retry : false )
431+ message [ "args" ] . first [ "job_class" ] = "RemovedJob"
432+ original_args = message [ "args" ]
433+ original_payload = Marshal . load ( Marshal . dump ( original_args ) )
434+ hub = Sentry . get_current_hub
435+ Sentry . set_tags ( worker : "outside" )
436+
437+ expect do
438+ Sentry ::Sidekiq ::SentryContextServerMiddleware . new . call ( nil , message , "events" ) do
439+ ActiveJob ::Base . execute ( message [ "args" ] . first )
440+ end
441+ end . to raise_error ( NameError )
442+
443+ expect ( message [ "args" ] ) . to equal ( original_args )
444+ expect ( message [ "args" ] ) . to eq ( original_payload )
445+ expect ( Sentry . get_current_hub ) . to equal ( hub )
446+ expect ( Sentry . get_current_scope . tags ) . to eq ( worker : "outside" )
447+ expect ( transport . events . grep ( Sentry ::ErrorEvent ) . size ) . to eq ( 1 )
448+ end
449+ end
450+
398451 context "with a separate running Sidekiq configuration" , skip : !WITH_SIDEKIQ_7 do
399452 let ( :running_config ) do
400453 Sidekiq ::Config . new ( max_retries : 5 ) . tap do |config |
0 commit comments