From ef2ee8f95e79f3d82ea3224efc400e81fe10825c Mon Sep 17 00:00:00 2001 From: shivanshu Date: Thu, 12 Dec 2024 18:51:54 +0530 Subject: [PATCH 1/2] fix: remove the origin check --- .../src/opentelemetry/instrumentation/celery/utils.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py index 6af310df5a..4761780928 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py @@ -76,12 +76,7 @@ def set_attributes_from_context(span, context): attribute_name = None - # Celery 4.0 uses `origin` instead of `hostname`; this change preserves - # the same name for the tag despite Celery version - if key == "origin": - key = "hostname" - - elif key == "delivery_info": + if key == "delivery_info": # Get also destination from this routing_key = value.get("routing_key") From ef93cb12bbe780b9f38df0dc733511675cb257f5 Mon Sep 17 00:00:00 2001 From: shivanshu Date: Fri, 20 Dec 2024 17:52:54 +0530 Subject: [PATCH 2/2] test: added a unit test for set_attributes_from_context Signed-off-by: shivanshu --- .../tests/test_utils.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py b/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py index a2f6e4338c..b627332e79 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py +++ b/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py @@ -282,3 +282,27 @@ def test_task_id_from_protocol_v2(self): task_id = utils.retrieve_task_id_from_message(context) self.assertEqual(task_id, "7e917b83-4018-431d-9832-73a28e1fb6c0") + + def test_origin_and_hostname_attributes(self): + """Test that 'origin' and 'hostname' are distinct attributes""" + # Create a mock span + span = mock.Mock() + span.is_recording.return_value = True + + # Create a context with both 'origin' and 'hostname' keys + context = { + "origin": "gen8@b98c7aca4628", + "hostname": "celery@7c2c2cd6a5b5", + } + + # Call the function + utils.set_attributes_from_context(span, context) + + # Verify that both attributes were set with their original keys + span.set_attribute.assert_has_calls( + [ + mock.call("celery.origin", "gen8@b98c7aca4628"), + mock.call("celery.hostname", "celery@7c2c2cd6a5b5"), + ], + any_order=True, + )