Skip to content

Commit

Permalink
fix: execution counter oddities
Browse files Browse the repository at this point in the history
  • Loading branch information
arielvalentin committed Oct 8, 2023
1 parent f5b140d commit fff8749
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def call(payload)
'messaging.system' => job.class.queue_adapter_name,
'messaging.destination' => job.queue_name,
'messaging.message_id' => job.job_id,
'rails.active_job.execution.counter' => (job.executions.to_i + 1),
'rails.active_job.execution.counter' => job.executions.to_i,
'rails.active_job.provider_job_id' => job.provider_job_id,
'rails.active_job.priority' => job.priority,
'rails.active_job.scheduled_at' => job.scheduled_at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,20 @@
end

describe 'messaging.active_job.executions' do
it 'is 1 for a normal job that does not retry' do
it 'is 1 for a normal job that does not retry in Rails 6 or earlier' do
skip "ActiveJob #{ActiveJob.version} starts at 0 in newer versions" if ActiveJob.version >= Gem::Version.new('7')
TestJob.perform_now
_(process_span.attributes['rails.active_job.execution.counter']).must_equal(1)
end

it 'tracks correctly for jobs that do retry' do
it 'is 0 for a normal job that does not retry in Rails 7 or later' do
skip "ActiveJob #{ActiveJob.version} starts at 1 for older versions" if ActiveJob.version < Gem::Version.new('7')
TestJob.perform_now
_(process_span.attributes['rails.active_job.execution.counter']).must_equal(0)
end

it 'tracks correctly for jobs that do retry in Rails 6 or earlier' do
skip "ActiveJob #{ActiveJob.version} starts at 0 in newer versions" if ActiveJob.version >= Gem::Version.new('7')
begin
RetryJob.perform_later
rescue StandardError
Expand All @@ -210,6 +218,18 @@
executions = spans.filter { |s| s.kind == :consumer }.map { |s| s.attributes['rails.active_job.execution.counter'] }.compact.max
_(executions).must_equal(2) # total of 3 runs. The initial and 2 retries.
end

it 'tracks correctly for jobs that do retry in Rails 7 or later' do
skip "ActiveJob #{ActiveJob.version} starts at 1 in older versions" if ActiveJob.version < Gem::Version.new('7')
begin
RetryJob.perform_later
rescue StandardError
nil
end

executions = spans.filter { |s| s.kind == :consumer }.map { |s| s.attributes['rails.active_job.execution.counter'] }.compact.max
_(executions).must_equal(1)
end
end

describe 'messaging.active_job.provider_job_id' do
Expand Down Expand Up @@ -349,13 +369,15 @@

describe 'active_job callbacks' do
it 'makes the tracing context available in before_perform callbacks' do
skip "ActiveJob #{ActiveJob.version} subscribers do not include timing information for callbacks" if ActiveJob.version < Gem::Version.new('7')
CallbacksJob.perform_now

_(CallbacksJob.context_before).wont_be_nil
_(CallbacksJob.context_before).must_be :valid?
end

it 'makes the tracing context available in after_perform callbacks' do
skip "ActiveJob #{ActiveJob.version} subscribers do not include timing information for callbacks" if ActiveJob.version < Gem::Version.new('7')
CallbacksJob.perform_now

_(CallbacksJob.context_after).wont_be_nil
Expand Down

0 comments on commit fff8749

Please sign in to comment.