From 93dcf359a8a66d17fed545f7a642f1d3a83d4ef4 Mon Sep 17 00:00:00 2001 From: Ariel Valentin Date: Wed, 11 Oct 2023 14:38:12 -0500 Subject: [PATCH] fix: Add Rails 7.1 compatability (#684) * chore: Add tests for Rails 7.1 * fix: Rails 7.1 incompatabilities --- instrumentation/action_pack/Appraisals | 4 ++++ instrumentation/action_view/Appraisals | 4 ++++ instrumentation/active_job/Appraisals | 14 ++++---------- .../active_job/patches/active_job_callbacks.rb | 2 +- .../patches/active_job_callbacks_test.rb | 17 ++++++++++++----- instrumentation/active_record/Appraisals | 4 ++++ instrumentation/active_support/Appraisals | 4 ++++ instrumentation/rails/Appraisals | 4 ++++ 8 files changed, 37 insertions(+), 16 deletions(-) diff --git a/instrumentation/action_pack/Appraisals b/instrumentation/action_pack/Appraisals index 03f29edc9..895a185d4 100644 --- a/instrumentation/action_pack/Appraisals +++ b/instrumentation/action_pack/Appraisals @@ -15,3 +15,7 @@ end appraise 'rails-7.0' do gem 'rails', '~> 7.0.0' end + +appraise 'rails-7.1' do + gem 'rails', '~> 7.1.0' +end diff --git a/instrumentation/action_view/Appraisals b/instrumentation/action_view/Appraisals index 03f29edc9..895a185d4 100644 --- a/instrumentation/action_view/Appraisals +++ b/instrumentation/action_view/Appraisals @@ -15,3 +15,7 @@ end appraise 'rails-7.0' do gem 'rails', '~> 7.0.0' end + +appraise 'rails-7.1' do + gem 'rails', '~> 7.1.0' +end diff --git a/instrumentation/active_job/Appraisals b/instrumentation/active_job/Appraisals index 5ebb30636..a318df014 100644 --- a/instrumentation/active_job/Appraisals +++ b/instrumentation/active_job/Appraisals @@ -4,14 +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' +%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 diff --git a/instrumentation/active_record/Appraisals b/instrumentation/active_record/Appraisals index 7a6f38c98..75952e9f4 100644 --- a/instrumentation/active_record/Appraisals +++ b/instrumentation/active_record/Appraisals @@ -15,3 +15,7 @@ end appraise 'activerecord-7.0' do gem 'activerecord', '~> 7.0.0' end + +appraise 'activerecord-7.1' do + gem 'activerecord', '~> 7.1.0' +end diff --git a/instrumentation/active_support/Appraisals b/instrumentation/active_support/Appraisals index 9b71bf262..aaad18a9c 100644 --- a/instrumentation/active_support/Appraisals +++ b/instrumentation/active_support/Appraisals @@ -15,3 +15,7 @@ end appraise 'activesupport-7.0' do gem 'activesupport', '~> 7.0.0' end + +appraise 'activesupport-7.1' do + gem 'activesupport', '~> 7.1.0' +end diff --git a/instrumentation/rails/Appraisals b/instrumentation/rails/Appraisals index 03f29edc9..895a185d4 100644 --- a/instrumentation/rails/Appraisals +++ b/instrumentation/rails/Appraisals @@ -15,3 +15,7 @@ end appraise 'rails-7.0' do gem 'rails', '~> 7.0.0' end + +appraise 'rails-7.1' do + gem 'rails', '~> 7.1.0' +end