Skip to content

Commit e2e54d3

Browse files
[#1444] Added tests for passing job trace
1 parent dd7c691 commit e2e54d3

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

spec/elastic_apm/spies/sidekiq_spec.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,60 @@ def perform
105105
expect(transaction['outcome']).to eq 'success'
106106
end
107107

108+
it 'creates child transaction when trace_id is present in job' do
109+
with_agent do
110+
parent_trace_id = 'abc123def456'
111+
112+
# Simulate a job with trace_id from parent
113+
job_with_trace = {
114+
'class' => 'ElasticAPM::HardWorker',
115+
'trace_id' => parent_trace_id,
116+
'args' => []
117+
}
118+
119+
middleware = Spies::SidekiqSpy::Middleware.new
120+
worker = HardWorker.new
121+
122+
middleware.call(worker, job_with_trace, 'default') do
123+
worker.perform
124+
end
125+
end
126+
127+
wait_for transactions: 1
128+
129+
transaction, = @mock_intake.transactions
130+
expect(transaction).to_not be_nil
131+
expect(transaction['name']).to eq 'ElasticAPM::HardWorker'
132+
expect(transaction['type']).to eq 'Sidekiq'
133+
expect(transaction['trace_id']).to eq('abc123def456')
134+
end
135+
136+
it 'creates independent transaction when no trace_id is present' do
137+
with_agent do
138+
# Simulate a job without trace_id
139+
job_without_trace = {
140+
'class' => 'ElasticAPM::HardWorker',
141+
'args' => []
142+
}
143+
144+
middleware = Spies::SidekiqSpy::Middleware.new
145+
worker = HardWorker.new
146+
147+
middleware.call(worker, job_without_trace, 'default') do
148+
worker.perform
149+
end
150+
end
151+
152+
wait_for transactions: 1
153+
154+
transaction, = @mock_intake.transactions
155+
expect(transaction).to_not be_nil
156+
expect(transaction['name']).to eq 'ElasticAPM::HardWorker'
157+
expect(transaction['type']).to eq 'Sidekiq'
158+
# Should have its own trace_id since no parent was provided
159+
expect(transaction['trace_id']).to_not be_nil
160+
end
161+
108162
it 'reports errors' do
109163
with_agent do
110164
Sidekiq::Testing.inline! do

0 commit comments

Comments
 (0)