Skip to content

Commit

Permalink
fix: Rails 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
arielvalentin committed Oct 8, 2023
1 parent 3c17731 commit df11d4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def call(payload)
'rails.active_job.execution.counter' => job.executions.to_i,
'rails.active_job.provider_job_id' => job.provider_job_id.to_s,
'rails.active_job.priority' => job.priority,
'rails.active_job.scheduled_at' => job.scheduled_at
'rails.active_job.scheduled_at' => job.scheduled_at&.to_f
}

otel_attributes['net.transport'] = 'inproc' if TEST_ADAPTERS.include?(job.class.queue_adapter_name)
Expand Down Expand Up @@ -136,7 +136,7 @@ def start(name, id, payload)
OpenTelemetry.handle_error(exception: e)
end

super
super if ::ActiveJob.version < Gem::Version.new('7.1')
end

def finish(_name, _id, payload)
Expand All @@ -160,7 +160,7 @@ def finish(_name, _id, payload)
OpenTelemetry.handle_error(exception: e)
end

super
super if ::ActiveJob.version < Gem::Version.new('7.1')
ensure
begin
span&.finish
Expand All @@ -176,6 +176,9 @@ def finish(_name, _id, payload)

def self.install
attach_to :active_job

# ActiveSupport::Notifications.subscribe("render_template.action_view", ActionView::LogSubscriber::Start.new)
# ActiveSupport::Notifications.subscribe("render_layout.action_view", ActionView::LogSubscriber::Start.new)
end

def self.uninstall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,21 @@
end
end

it 'is set correctly for jobs that do wait' do
it 'is set correctly for jobs that do wait in Rails 7.0 or older' do
skip 'scheduled jobs behave differently in Rails 7.1 and newer' 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['rails.active_job.scheduled_at']).must_equal(job.scheduled_at)
_(publish_span.attributes['rails.active_job.scheduled_at']).must_equal(job.scheduled_at.to_f)
_(process_span.attributes['rails.active_job.scheduled_at']).must_equal(job.scheduled_at.to_f)
end

it 'is set correctly for jobs that do wait in Rails 7.1 and newer' do
skip 'scheduled jobs behave differently in Rails 7.0 and older' 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['rails.active_job.scheduled_at']).must_equal(job.scheduled_at.to_f)
_(process_span.attributes['rails.active_job.scheduled_at']).must_be_nil
end
end
Expand Down

0 comments on commit df11d4c

Please sign in to comment.