Skip to content

Commit

Permalink
test(celery): Test that Celery queue only set for default exchange
Browse files Browse the repository at this point in the history
This test checks that `messaging.destination.name` is only set for the default exchange. Other exchanges should not set this value, since the routing key may be different from the queue name.
  • Loading branch information
szokeasaurusrex committed Apr 30, 2024
1 parent e70aa66 commit 67e2531
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/integrations/celery/test_celery.py
Expand Up @@ -620,7 +620,7 @@ def example_task():

@pytest.mark.parametrize("routing_key", ("celery", "custom"))
@mock.patch("celery.app.task.Task.request")
def test_messaging_destination_name(
def test_messaging_destination_name_default_exchange(
mock_request, routing_key, init_celery, capture_events
):
celery_app = init_celery(enable_tracing=True)
Expand All @@ -635,3 +635,27 @@ def task(): ...
(event,) = events
(span,) = event["spans"]
assert span["data"]["messaging.destination.name"] == routing_key


@mock.patch("celery.app.task.Task.request")
def test_messaging_destination_name_nondefault_exchange(
mock_request, init_celery, capture_events
):
"""
Currently, we only capture the routing key as the messaging.destination.name when
we are using the default exchange (""). This is because the default exchange ensures
that the routing key is the queue name. Other exchanges may not guarantee this
behavior.
"""
celery_app = init_celery(enable_tracing=True)
events = capture_events()
mock_request.delivery_info = {"routing_key": "celery", "exchange": "custom"}

@celery_app.task()
def task(): ...

task.apply_async()

(event,) = events
(span,) = event["spans"]
assert "messaging.destination.name" not in span["data"]

0 comments on commit 67e2531

Please sign in to comment.