Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate both origin and hostname correctly to span attributes #3097

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -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")

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