Skip to content

Commit

Permalink
fix(active_job): rename 'send' operation to 'publish'
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-kazmierczak committed Sep 5, 2023
1 parent e37d5af commit dc2a582
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.prepended(base)
base.class_eval do
around_enqueue do |job, block|
span_kind = job.class.queue_adapter_name == 'inline' ? :client : :producer
span_name = "#{otel_config[:span_naming] == :job_class ? job.class : job.queue_name} send"
span_name = "#{otel_config[:span_naming] == :job_class ? job.class : job.queue_name} publish"
span_attributes = job_attributes(job)
otel_tracer.in_span(span_name, attributes: span_attributes, kind: span_kind) do
OpenTelemetry.propagation.inject(job.metadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
let(:config) { { propagation_style: :link, force_flush: false, span_naming: :queue } }
let(:exporter) { EXPORTER }
let(:spans) { exporter.finished_spans }
let(:send_span) { spans.find { |s| s.name == 'default send' } }
let(:publish_span) { spans.find { |s| s.name == 'default publish' } }
let(:process_span) { spans.find { |s| s.name == 'default process' } }

before do
Expand All @@ -41,7 +41,7 @@
it 'traces enqueuing and processing the job' do
TestJob.perform_later

_(send_span).wont_be_nil
_(publish_span).wont_be_nil
_(process_span).wont_be_nil
end
end
Expand All @@ -50,7 +50,7 @@
it 'only traces processing the job' do
TestJob.perform_now

_(send_span).must_be_nil
_(publish_span).must_be_nil
_(process_span).wont_be_nil
_(process_span.attributes['code.namespace']).must_equal('TestJob')
_(process_span.attributes['code.function']).must_equal('perform_now')
Expand Down Expand Up @@ -97,14 +97,14 @@

TestJob.perform_later

_(send_span.kind).must_equal(:client)
_(publish_span.kind).must_equal(:client)
_(process_span.kind).must_equal(:server)
end

it 'sets correct span kinds for all other jobs' do
TestJob.perform_later

_(send_span.kind).must_equal(:producer)
_(publish_span.kind).must_equal(:producer)
_(process_span.kind).must_equal(:consumer)
end
end
Expand All @@ -113,23 +113,23 @@
it 'sets the messaging.operation attribute only when processing the job' do
TestJob.perform_later

_(send_span.attributes['messaging.operation']).must_be_nil
_(publish_span.attributes['messaging.operation']).must_be_nil
_(process_span.attributes['messaging.operation']).must_equal('process')
end

describe 'net.transport' do
it 'is sets correctly for inline jobs' do
TestJob.perform_later

[send_span, process_span].each do |span|
[publish_span, process_span].each do |span|
_(span.attributes['net.transport']).must_equal('inproc')
end
end

it 'is set correctly for async jobs' do
TestJob.perform_later

[send_span, process_span].each do |span|
[publish_span, process_span].each do |span|
_(span.attributes['net.transport']).must_equal('inproc')
end
end
Expand All @@ -139,15 +139,15 @@
it 'is unset for unprioritized jobs' do
TestJob.perform_later

[send_span, process_span].each do |span|
[publish_span, process_span].each do |span|
_(span.attributes['messaging.active_job.priority']).must_be_nil
end
end

it 'is set for jobs with a priority' do
TestJob.set(priority: 1).perform_later

[send_span, process_span].each do |span|
[publish_span, process_span].each do |span|
_(span.attributes['messaging.active_job.priority']).must_equal(1)
end
end
Expand All @@ -157,7 +157,7 @@
it 'is unset for jobs that do not specify a wait time' do
TestJob.perform_later

[send_span, process_span].each do |span|
[publish_span, process_span].each do |span|
_(span.attributes['messaging.active_job.scheduled_at']).must_be_nil
end
end
Expand All @@ -166,8 +166,8 @@
job = TestJob.set(wait: 0.second).perform_later

# Only the sending span is a 'scheduled' thing
_(send_span.attributes['messaging.active_job.scheduled_at']).must_equal(job.scheduled_at)
assert(send_span.attributes['messaging.active_job.scheduled_at'])
_(publish_span.attributes['messaging.active_job.scheduled_at']).must_equal(job.scheduled_at)
assert(publish_span.attributes['messaging.active_job.scheduled_at'])

# The processing span isn't a 'scheduled' thing
_(process_span.attributes['messaging.active_job.scheduled_at']).must_be_nil
Expand All @@ -185,15 +185,15 @@
ActiveJob::Base.queue_adapter = :inline
TestJob.perform_later

[send_span, process_span].each do |span|
[publish_span, process_span].each do |span|
_(span.attributes['messaging.system']).must_equal('inline')
end
end

it 'is set correctly for the async adapter' do
TestJob.perform_later

[send_span, process_span].each do |span|
[publish_span, process_span].each do |span|
_(span.attributes['messaging.system']).must_equal('async')
end
end
Expand Down Expand Up @@ -232,7 +232,7 @@
it 'generally sets other attributes as expected' do
job = TestJob.perform_later

[send_span, process_span].each do |span|
[publish_span, process_span].each do |span|
_(span.attributes['code.namespace']).must_equal('TestJob')
_(span.attributes['messaging.destination_kind']).must_equal('queue')
_(span.attributes['messaging.system']).must_equal('async')
Expand All @@ -245,8 +245,8 @@
describe 'when queue - default' do
it 'names spans according to the job queue' do
TestJob.set(queue: :foo).perform_later
send_span = exporter.finished_spans.find { |s| s.name == 'foo send' }
_(send_span).wont_be_nil
publish_span = exporter.finished_spans.find { |s| s.name == 'foo publish' }
_(publish_span).wont_be_nil

process_span = exporter.finished_spans.find { |s| s.name == 'foo process' }
_(process_span).wont_be_nil
Expand All @@ -258,8 +258,8 @@

it 'names span according to the job class' do
TestJob.set(queue: :foo).perform_later
send_span = exporter.finished_spans.find { |s| s.name == 'TestJob send' }
_(send_span).wont_be_nil
publish_span = exporter.finished_spans.find { |s| s.name == 'TestJob publish' }
_(publish_span).wont_be_nil

process_span = exporter.finished_spans.find { |s| s.name == 'TestJob process' }
_(process_span).wont_be_nil
Expand Down Expand Up @@ -309,11 +309,11 @@
it 'creates span links in separate traces' do
TestJob.perform_later

_(send_span.trace_id).wont_equal(process_span.trace_id)
_(publish_span.trace_id).wont_equal(process_span.trace_id)

_(process_span.total_recorded_links).must_equal(1)
_(process_span.links[0].span_context.trace_id).must_equal(send_span.trace_id)
_(process_span.links[0].span_context.span_id).must_equal(send_span.span_id)
_(process_span.links[0].span_context.trace_id).must_equal(publish_span.trace_id)
_(process_span.links[0].span_context.span_id).must_equal(publish_span.span_id)
end

it 'propagates baggage' do
Expand All @@ -322,11 +322,11 @@
BaggageJob.perform_later
end

_(send_span.trace_id).wont_equal(process_span.trace_id)
_(publish_span.trace_id).wont_equal(process_span.trace_id)

_(process_span.total_recorded_links).must_equal(1)
_(process_span.links[0].span_context.trace_id).must_equal(send_span.trace_id)
_(process_span.links[0].span_context.span_id).must_equal(send_span.span_id)
_(process_span.links[0].span_context.trace_id).must_equal(publish_span.trace_id)
_(process_span.links[0].span_context.span_id).must_equal(publish_span.span_id)
_(process_span.attributes['success']).must_equal(true)
end
end
Expand All @@ -339,8 +339,8 @@

_(process_span.total_recorded_links).must_equal(0)

_(send_span.trace_id).must_equal(process_span.trace_id)
_(process_span.parent_span_id).must_equal(send_span.span_id)
_(publish_span.trace_id).must_equal(process_span.trace_id)
_(process_span.parent_span_id).must_equal(publish_span.span_id)
end

it 'propagates baggage' do
Expand All @@ -350,8 +350,8 @@
end
_(process_span.total_recorded_links).must_equal(0)

_(send_span.trace_id).must_equal(process_span.trace_id)
_(process_span.parent_span_id).must_equal(send_span.span_id)
_(publish_span.trace_id).must_equal(process_span.trace_id)
_(process_span.parent_span_id).must_equal(publish_span.span_id)
_(process_span.attributes['success']).must_equal(true)
end
end
Expand All @@ -364,8 +364,8 @@

_(process_span.total_recorded_links).must_equal(0)

_(send_span.trace_id).wont_equal(process_span.trace_id)
_(process_span.parent_span_id).wont_equal(send_span.span_id)
_(publish_span.trace_id).wont_equal(process_span.trace_id)
_(process_span.parent_span_id).wont_equal(publish_span.span_id)
end

it 'still propagates baggage' do
Expand All @@ -376,8 +376,8 @@

_(process_span.total_recorded_links).must_equal(0)

_(send_span.trace_id).wont_equal(process_span.trace_id)
_(process_span.parent_span_id).wont_equal(send_span.span_id)
_(publish_span.trace_id).wont_equal(process_span.trace_id)
_(process_span.parent_span_id).wont_equal(publish_span.span_id)
_(process_span.attributes['success']).must_equal(true)
end
end
Expand Down

0 comments on commit dc2a582

Please sign in to comment.