|
97 | 97 | tracer.start_span('connect', with_parent: root_parent_context, attributes: attributes, kind: :internal) |
98 | 98 | end |
99 | 99 |
|
| 100 | + let(:child_queue_span_producer) do |
| 101 | + attributes = { |
| 102 | + 'messaging.system' => 'sidekiq', |
| 103 | + 'messaging.destination' => 'default', |
| 104 | + 'messaging.destination_kind' => 'queue', |
| 105 | + 'messaging.operation' => 'publish', |
| 106 | + 'messaging.sidekiq_job_class' => 'Sidekiq::Worker' |
| 107 | + } |
| 108 | + |
| 109 | + tracer.start_span('Sidekiq::Worker publish', with_parent: root_parent_context, attributes: attributes, kind: :producer) |
| 110 | + end |
| 111 | + |
| 112 | + let(:child_queue_span_consumer) do |
| 113 | + attributes = { |
| 114 | + 'messaging.system' => 'sidekiq', |
| 115 | + 'messaging.destination' => 'default', |
| 116 | + 'messaging.destination_kind' => 'queue', |
| 117 | + 'messaging.operation' => 'process', |
| 118 | + 'messaging.sidekiq_job_class' => 'Sidekiq::Worker' |
| 119 | + } |
| 120 | + |
| 121 | + tracer.start_span('Sidekiq::Worker process', with_parent: root_parent_context, attributes: attributes, kind: :consumer) |
| 122 | + end |
| 123 | + |
100 | 124 | before do |
101 | 125 | perform_basic_setup |
102 | 126 | perform_otel_setup |
|
247 | 271 | subject.on_start(child_http_span, root_parent_context) |
248 | 272 | subject.on_start(error_span, empty_context) |
249 | 273 | subject.on_start(http_error_span, empty_context) |
| 274 | + subject.on_start(child_queue_span_producer, root_parent_context) |
| 275 | + subject.on_start(child_queue_span_consumer, root_parent_context) |
250 | 276 | end |
251 | 277 |
|
252 | 278 | let(:finished_db_span) { child_db_span.finish } |
|
255 | 281 | let(:finished_invalid_span) { invalid_span.finish } |
256 | 282 | let(:finished_error_span) { error_span.finish } |
257 | 283 | let(:finished_http_error_span) { http_error_span.finish } |
| 284 | + let(:finished_queue_span) { child_queue_span_producer.finish } |
| 285 | + let(:finished_queue_span_consumer) { child_queue_span_consumer.finish } |
258 | 286 |
|
259 | 287 | it 'noops when not initialized' do |
260 | 288 | allow(Sentry).to receive(:initialized?).and_return(false) |
|
317 | 345 | expect(sentry_span.data).to include({ 'otel.kind' => finished_db_span.kind }) |
318 | 346 | expect(sentry_span.timestamp).to eq(finished_db_span.end_timestamp / 1e9) |
319 | 347 |
|
320 | | - expect(subject.span_map.size).to eq(4) |
| 348 | + expect(subject.span_map.size).to eq(6) |
321 | 349 | expect(subject.span_map.keys).not_to include(span_id) |
322 | 350 | end |
323 | 351 |
|
|
339 | 367 | expect(sentry_span.timestamp).to eq(finished_http_span.end_timestamp / 1e9) |
340 | 368 | expect(sentry_span.status).to eq('ok') |
341 | 369 |
|
342 | | - expect(subject.span_map.size).to eq(4) |
| 370 | + expect(subject.span_map.size).to eq(6) |
| 371 | + expect(subject.span_map.keys).not_to include(span_id) |
| 372 | + end |
| 373 | + |
| 374 | + it 'finishes sentry child span on otel child queue producer span finish' do |
| 375 | + expect(subject.span_map).to receive(:delete).and_call_original |
| 376 | + |
| 377 | + span_id = finished_queue_span.context.hex_span_id |
| 378 | + sentry_span = subject.span_map[span_id] |
| 379 | + expect(sentry_span).to be_a(Sentry::Span) |
| 380 | + |
| 381 | + expect(sentry_span).to receive(:finish).and_call_original |
| 382 | + subject.on_finish(finished_queue_span) |
| 383 | + |
| 384 | + expect(sentry_span.op).to eq('queue.publish') |
| 385 | + expect(sentry_span.origin).to eq('auto.otel') |
| 386 | + expect(sentry_span.description).to eq('Sidekiq::Worker') |
| 387 | + expect(sentry_span.data).to include(finished_queue_span.attributes) |
| 388 | + expect(sentry_span.data).to include({ 'otel.kind' => finished_queue_span.kind }) |
| 389 | + expect(sentry_span.timestamp).to eq(finished_queue_span.end_timestamp / 1e9) |
| 390 | + expect(sentry_span.status).to eq('ok') |
| 391 | + |
| 392 | + expect(subject.span_map.size).to eq(6) |
| 393 | + expect(subject.span_map.keys).not_to include(span_id) |
| 394 | + end |
| 395 | + |
| 396 | + it 'finishes sentry child span on otel child queue consumer span finish' do |
| 397 | + expect(subject.span_map).to receive(:delete).and_call_original |
| 398 | + |
| 399 | + span_id = finished_queue_span_consumer.context.hex_span_id |
| 400 | + sentry_span = subject.span_map[span_id] |
| 401 | + expect(sentry_span).to be_a(Sentry::Span) |
| 402 | + |
| 403 | + expect(sentry_span).to receive(:finish).and_call_original |
| 404 | + subject.on_finish(finished_queue_span_consumer) |
| 405 | + |
| 406 | + expect(sentry_span.op).to eq('queue.process') |
| 407 | + expect(sentry_span.origin).to eq('auto.otel') |
| 408 | + expect(sentry_span.description).to eq('Sidekiq::Worker') |
| 409 | + expect(sentry_span.data).to include(finished_queue_span_consumer.attributes) |
| 410 | + expect(sentry_span.data).to include({ 'otel.kind' => finished_queue_span_consumer.kind }) |
| 411 | + expect(sentry_span.timestamp).to eq(finished_queue_span_consumer.end_timestamp / 1e9) |
| 412 | + expect(sentry_span.status).to eq('ok') |
| 413 | + |
| 414 | + expect(subject.span_map.size).to eq(6) |
343 | 415 | expect(subject.span_map.keys).not_to include(span_id) |
344 | 416 | end |
345 | 417 |
|
|
348 | 420 | subject.on_finish(finished_http_span) |
349 | 421 | subject.on_finish(finished_error_span) |
350 | 422 | subject.on_finish(finished_http_error_span) |
| 423 | + subject.on_finish(finished_queue_span) |
| 424 | + subject.on_finish(finished_queue_span_consumer) |
351 | 425 |
|
352 | 426 | expect(subject.span_map).to receive(:delete).and_call_original |
353 | 427 |
|
|
0 commit comments