Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/4827.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`opentelemetry-instrumentation-celery`: populate `celery.origin` and `celery.hostname` as distinct span attributes
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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`.
"""
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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)
Expand Down