Skip to content
Merged
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
24 changes: 13 additions & 11 deletions sentry_sdk/integrations/clickhouse_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def setup_once() -> None:
)

# If the query contains parameters then the send_data function is used to send those parameters to clickhouse
clickhouse_driver.client.Client.send_data = _wrap_send_data(
clickhouse_driver.client.Client.send_data
)
_wrap_send_data()

# Every query ends either with the Client's `receive_end_of_query` (no result expected)
# or its `receive_result` (result expected)
Expand Down Expand Up @@ -128,23 +126,27 @@ def _inner_end(*args: P.args, **kwargs: P.kwargs) -> T:
return _inner_end


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 = getattr(instance.connection, "_sentry_span", None)
def _wrap_send_data() -> None:
original_send_data = clickhouse_driver.client.Client.send_data

def _inner_send_data( # type: ignore[no-untyped-def] # clickhouse-driver does not type send_data
self, sample_block, data, types_check=False, columnar=False, *args, **kwargs
):
span = getattr(self.connection, "_sentry_span", None)

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

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)
return original_send_data(
self, sample_block, data, types_check, columnar, *args, **kwargs
)

return _inner_send_data
clickhouse_driver.client.Client.send_data = _inner_send_data


def _set_db_data(
Expand Down