diff --git a/instrumentation/active_job/Appraisals b/instrumentation/active_job/Appraisals index 1db020eeb..a318df014 100644 --- a/instrumentation/active_job/Appraisals +++ b/instrumentation/active_job/Appraisals @@ -4,18 +4,8 @@ # # SPDX-License-Identifier: Apache-2.0 -appraise 'activejob-6.0' do - gem 'activejob', '~> 6.0.0' -end - -appraise 'activejob-6.1' do - gem 'activejob', '~> 6.1.0' -end - -appraise 'activejob-7.0' do - gem 'activejob', '~> 7.0.0' -end - -appraise 'activejob-7.1' do - gem 'activejob', '~> 7.1.0' +%w[6.0.0 6.1.0 7.0.0 7.1.0].each do |version| + appraise "activejob-#{version}" do + gem 'activejob', "~> #{version}" + end end diff --git a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/patches/active_job_callbacks.rb b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/patches/active_job_callbacks.rb index c3f612599..973025352 100644 --- a/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/patches/active_job_callbacks.rb +++ b/instrumentation/active_job/lib/opentelemetry/instrumentation/active_job/patches/active_job_callbacks.rb @@ -73,7 +73,7 @@ def job_attributes(job) 'messaging.destination' => job.queue_name, 'messaging.message_id' => job.job_id, 'messaging.active_job.provider_job_id' => job.provider_job_id, - 'messaging.active_job.scheduled_at' => job.scheduled_at, + 'messaging.active_job.scheduled_at' => job.scheduled_at&.to_f, 'messaging.active_job.priority' => job.priority } diff --git a/instrumentation/active_job/test/instrumentation/active_job/patches/active_job_callbacks_test.rb b/instrumentation/active_job/test/instrumentation/active_job/patches/active_job_callbacks_test.rb index f2c6f996c..c5c59d95e 100644 --- a/instrumentation/active_job/test/instrumentation/active_job/patches/active_job_callbacks_test.rb +++ b/instrumentation/active_job/test/instrumentation/active_job/patches/active_job_callbacks_test.rb @@ -162,14 +162,21 @@ end end - it 'is set correctly for jobs that do wait' do + it 'records the scheduled at time for apps running Rails 7.1 and newer' do + skip 'scheduled jobs behave differently in Rails 7.1+' if ActiveJob.version < Gem::Version.new('7.1') + job = TestJob.set(wait: 0.second).perform_later - # Only the sending span is a 'scheduled' thing - _(publish_span.attributes['messaging.active_job.scheduled_at']).must_equal(job.scheduled_at) - assert(publish_span.attributes['messaging.active_job.scheduled_at']) + _(publish_span.attributes['messaging.active_job.scheduled_at']).must_equal(job.scheduled_at.to_f) + _(process_span.attributes['messaging.active_job.scheduled_at']).must_equal(job.scheduled_at.to_f) + end + + it 'records the scheduled at time for apps running Rails 7.0 or older' do + skip 'scheduled jobs behave differently in Rails 7.1+' if ActiveJob.version >= Gem::Version.new('7.1') + + job = TestJob.set(wait: 0.second).perform_later - # The processing span isn't a 'scheduled' thing + _(publish_span.attributes['messaging.active_job.scheduled_at']).must_equal(job.scheduled_at.to_f) _(process_span.attributes['messaging.active_job.scheduled_at']).must_be_nil end end