Skip to content

Commit

Permalink
fix(clickhouse): _sentry_span might be missing (#3096)
Browse files Browse the repository at this point in the history
We started auto-enabling the ClickHouse integration in 2.0+. This led to it getting auto-enabled also for folks using ClickHouse with Django via `django-clickhouse-backend`, but it turns out that the integration doesn't work properly with `django-clickhouse-backend` and leads to `AttributeError: 'Connection' object has no attribute '_sentry_span'`.
  • Loading branch information
sentrivana committed May 22, 2024
1 parent 7af75ce commit 38c14e9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions sentry_sdk/integrations/clickhouse_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _wrap_end(f: Callable[P, T]) -> Callable[P, T]:
def _inner_end(*args: P.args, **kwargs: P.kwargs) -> T:
res = f(*args, **kwargs)
instance = args[0]
span = instance.connection._sentry_span # type: ignore[attr-defined]
span = getattr(instance.connection, "_sentry_span", None) # type: ignore[attr-defined]

if span is not None:
if res is not None and should_send_default_pii():
Expand All @@ -129,14 +129,15 @@ def _wrap_send_data(f: Callable[P, T]) -> Callable[P, T]:
def _inner_send_data(*args: P.args, **kwargs: P.kwargs) -> T:
instance = args[0] # type: clickhouse_driver.client.Client
data = args[2]
span = instance.connection._sentry_span
span = getattr(instance.connection, "_sentry_span", None)

_set_db_data(span, instance.connection)
if span is not None:
_set_db_data(span, instance.connection)

if should_send_default_pii():
db_params = span._data.get("db.params", [])
db_params.extend(data)
span.set_data("db.params", db_params)
if should_send_default_pii():
db_params = span._data.get("db.params", [])
db_params.extend(data)
span.set_data("db.params", db_params)

return f(*args, **kwargs)

Expand Down

0 comments on commit 38c14e9

Please sign in to comment.