From 167cef755854302cc93d372f8fcf561db1ef4f40 Mon Sep 17 00:00:00 2001 From: Colton Allen Date: Tue, 21 May 2024 05:58:33 -0500 Subject: [PATCH] Add conditional check for delivery_info's existence (#3083) Co-authored-by: Anton Pirker --- sentry_sdk/integrations/celery/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sentry_sdk/integrations/celery/__init__.py b/sentry_sdk/integrations/celery/__init__.py index b2c90d7d37..46e8002218 100644 --- a/sentry_sdk/integrations/celery/__init__.py +++ b/sentry_sdk/integrations/celery/__init__.py @@ -333,11 +333,12 @@ def _set_messaging_destination_name(task, span): """Set "messaging.destination.name" tag for span""" with capture_internal_exceptions(): delivery_info = task.request.delivery_info - routing_key = delivery_info.get("routing_key") - if delivery_info.get("exchange") == "" and routing_key is not None: - # Empty exchange indicates the default exchange, meaning the tasks - # are sent to the queue with the same name as the routing key. - span.set_data(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key) + if delivery_info: + routing_key = delivery_info.get("routing_key") + if delivery_info.get("exchange") == "" and routing_key is not None: + # Empty exchange indicates the default exchange, meaning the tasks + # are sent to the queue with the same name as the routing key. + span.set_data(SPANDATA.MESSAGING_DESTINATION_NAME, routing_key) def _wrap_task_call(task, f):