Skip to content

Commit bfd6524

Browse files
committed
fix(celery): Get driver_type from broker's URL
Under the hood within Kombu (the messaging library used by Celery), the `driver_type` is ultimately derived from the broker's URL that's provided in the Celery configuration by the user via either the `broker` or `broker_url` arguments. We can accomplish the same thing in our context, removing the need to open a connection to the broker to determine the `driver_type` to set in the span. Fixes PY-2071 Fixes #5428
1 parent 1eeb5df commit bfd6524

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

sentry_sdk/integrations/celery/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
from collections.abc import Mapping
33
from functools import wraps
4+
from urllib.parse import urlparse
45

56
import sentry_sdk
67
from sentry_sdk import isolation_scope
@@ -392,11 +393,9 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":
392393
)
393394

394395
with capture_internal_exceptions():
395-
with task.app.connection() as conn:
396-
span.set_data(
397-
SPANDATA.MESSAGING_SYSTEM,
398-
conn.transport.driver_type,
399-
)
396+
task_broker_url = task.app.conf.broker_url
397+
driver_type = urlparse(task_broker_url).scheme
398+
span.set_data(SPANDATA.MESSAGING_SYSTEM, driver_type)
400399

401400
return f(*args, **kwargs)
402401
except Exception:

0 commit comments

Comments
 (0)