From b5c827a45e41a47d06eea856f3dde6d4d9e0815b Mon Sep 17 00:00:00 2001 From: Ariel Valentin Date: Tue, 10 Oct 2023 19:24:56 -0500 Subject: [PATCH] fix: Rails 7.1 incompatabilities --- instrumentation/active_job/Appraisals | 18 ++++-------------- .../active_job/patches/active_job_callbacks.rb | 2 +- .../patches/active_job_callbacks_test.rb | 17 ++++++++++++----- 3 files changed, 17 insertions(+), 20 deletions(-) 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