@@ -292,7 +292,6 @@ def test_decorate_basic_publish(
292
292
use_span .assert_called_once_with (
293
293
get_span .return_value , end_on_exit = True
294
294
)
295
- get_span .return_value .is_recording .assert_called_once ()
296
295
inject .assert_called_once_with (properties .headers )
297
296
callback .assert_called_once_with (
298
297
exchange_name , routing_key , mock_body , properties , False
@@ -323,7 +322,6 @@ def test_decorate_basic_publish_no_properties(
323
322
use_span .assert_called_once_with (
324
323
get_span .return_value , end_on_exit = True
325
324
)
326
- get_span .return_value .is_recording .assert_called_once ()
327
325
inject .assert_called_once_with (basic_properties .return_value .headers )
328
326
self .assertEqual (retval , callback .return_value )
329
327
@@ -393,7 +391,6 @@ def test_decorate_basic_publish_with_hook(
393
391
use_span .assert_called_once_with (
394
392
get_span .return_value , end_on_exit = True
395
393
)
396
- get_span .return_value .is_recording .assert_called_once ()
397
394
inject .assert_called_once_with (properties .headers )
398
395
publish_hook .assert_called_once_with (
399
396
get_span .return_value , mock_body , properties
@@ -402,3 +399,52 @@ def test_decorate_basic_publish_with_hook(
402
399
exchange_name , routing_key , mock_body , properties , False
403
400
)
404
401
self .assertEqual (retval , callback .return_value )
402
+
403
+ @mock .patch ("opentelemetry.instrumentation.pika.utils._get_span" )
404
+ @mock .patch ("opentelemetry.propagate.inject" )
405
+ @mock .patch ("opentelemetry.trace.use_span" )
406
+ def test_decorate_basic_publish_when_span_is_not_recording (
407
+ self ,
408
+ use_span : mock .MagicMock ,
409
+ inject : mock .MagicMock ,
410
+ get_span : mock .MagicMock ,
411
+ ) -> None :
412
+ callback = mock .MagicMock ()
413
+ tracer = mock .MagicMock ()
414
+ channel = mock .MagicMock (spec = Channel )
415
+ exchange_name = "test-exchange"
416
+ routing_key = "test-routing-key"
417
+ properties = mock .MagicMock ()
418
+ mock_body = b"mock_body"
419
+ publish_hook = mock .MagicMock ()
420
+
421
+ mocked_span = mock .MagicMock ()
422
+ mocked_span .is_recording .return_value = False
423
+ get_span .return_value = mocked_span
424
+
425
+ decorated_basic_publish = utils ._decorate_basic_publish (
426
+ callback , channel , tracer , publish_hook
427
+ )
428
+ retval = decorated_basic_publish (
429
+ exchange_name , routing_key , mock_body , properties
430
+ )
431
+ get_span .assert_called_once_with (
432
+ tracer ,
433
+ channel ,
434
+ properties ,
435
+ destination = exchange_name ,
436
+ span_kind = SpanKind .PRODUCER ,
437
+ task_name = "(temporary)" ,
438
+ operation = None ,
439
+ )
440
+ use_span .assert_called_once_with (
441
+ get_span .return_value , end_on_exit = True
442
+ )
443
+ inject .assert_called_once_with (properties .headers )
444
+ publish_hook .assert_called_once_with (
445
+ get_span .return_value , mock_body , properties
446
+ )
447
+ callback .assert_called_once_with (
448
+ exchange_name , routing_key , mock_body , properties , False
449
+ )
450
+ self .assertEqual (retval , callback .return_value )
0 commit comments