From fd511b8139da3282373e81fbb71779d79e5c4b22 Mon Sep 17 00:00:00 2001 From: Ahmed Mohamed <68402624+ahmed5145@users.noreply.github.com> Date: Thu, 16 Jul 2026 13:20:07 -0500 Subject: [PATCH 1/2] fix(celery): populate origin and hostname as distinct span attributes --- .changelog/3096.fixed | 1 + .../opentelemetry/instrumentation/celery/utils.py | 13 ++++--------- .../tests/test_utils.py | 2 ++ 3 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 .changelog/3096.fixed diff --git a/.changelog/3096.fixed b/.changelog/3096.fixed new file mode 100644 index 0000000000..9c6a50b6e2 --- /dev/null +++ b/.changelog/3096.fixed @@ -0,0 +1 @@ +`opentelemetry-instrumentation-celery`: populate `celery.origin` and `celery.hostname` as distinct span attributes 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 be9d073f6a..90fccbb66b 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py @@ -86,12 +86,7 @@ def set_attributes_from_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") @@ -169,7 +164,7 @@ def attach_context( def detach_context( task: Optional[Task], task_id: str, is_publish: bool = False ) -> None: - """Helper to remove `Span`, `ContextManager` and context token in a + """Helper to remove `Span`, `ContextManager` and context token in a Celery task when it's propagated. This function handles tasks where no values are attached to the `Task`. """ @@ -217,8 +212,8 @@ def retrieve_task_from_sender(kwargs: Mapping[str, Any]) -> Optional[Task]: # for retry and failure signals sender is the task object if isinstance(sender, str): sender = registry.tasks.get(sender) - if sender is None: - logger.debug("Unable to retrieve the task from sender=%s", sender) + if sender is None: + logger.debug("Unable to retrieve the task from sender=%s", sender) return cast(Optional[Task], sender) diff --git a/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py b/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py index 49fe16ddbd..b619952073 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py +++ b/instrumentation/opentelemetry-instrumentation-celery/tests/test_utils.py @@ -28,6 +28,7 @@ def test_set_attributes_from_context(self): "expires": "later", "hostname": "localhost", "id": "44b7f305", + "origin": "gen8@localhost", "reply_to": "44b7f305", "retries": 4, "timelimit": ("now", "later"), @@ -56,6 +57,7 @@ def test_set_attributes_from_context(self): self.assertEqual(span.attributes.get("celery.eta"), "soon") self.assertEqual(span.attributes.get("celery.expires"), "later") self.assertEqual(span.attributes.get("celery.hostname"), "localhost") + self.assertEqual(span.attributes.get("celery.origin"), "gen8@localhost") self.assertEqual(span.attributes.get("celery.reply_to"), "44b7f305") self.assertEqual(span.attributes.get("celery.retries"), 4) From b4277b76a03706013e006738c1594d626ce706c5 Mon Sep 17 00:00:00 2001 From: Ahmed Mohamed <68402624+ahmed5145@users.noreply.github.com> Date: Thu, 16 Jul 2026 16:09:10 -0500 Subject: [PATCH 2/2] chore: rename changelog fragment for PR 4827 --- .changelog/{3096.fixed => 4827.fixed} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{3096.fixed => 4827.fixed} (100%) diff --git a/.changelog/3096.fixed b/.changelog/4827.fixed similarity index 100% rename from .changelog/3096.fixed rename to .changelog/4827.fixed