Skip to content

Commit b33f83c

Browse files
committed
fix
1 parent 9334dff commit b33f83c

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

sentry_sdk/integrations/clickhouse_driver.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,32 +136,33 @@ def _inner_end(*args: P.args, **kwargs: P.kwargs) -> T:
136136

137137
span.finish()
138138

139+
try:
140+
del connection._sentry_db_data
141+
del connection._sentry_span
142+
except AttributeError:
143+
pass
144+
139145
return res
140146

141147
return _inner_end
142148

143149

144150
def _wrap_send_data(f: Callable[P, T]) -> Callable[P, T]:
145151
def _inner_send_data(*args: P.args, **kwargs: P.kwargs) -> T:
146-
instance = args[0] # type: clickhouse_driver.client.Client
152+
connection = args[0].connection
147153
db_params_data = args[2]
148-
span = getattr(instance.connection, "_sentry_span", None)
154+
span = getattr(connection, "_sentry_span", None)
149155

150156
if span is not None:
151-
data = _get_db_data(instance.connection)
157+
data = _get_db_data(connection)
152158
_set_on_span(span, data)
153159

154160
if should_send_default_pii():
155-
db_params = (
156-
getattr(instance.connection, "_sentry_db_data", {}).get("db.params")
157-
or []
158-
)
161+
saved_db_data = getattr(connection, "_sentry_db_data", {})
162+
db_params = saved_db_data.get("db.params") or []
159163
db_params.extend(db_params_data)
164+
saved_db_data["db.params"] = db_params
160165
span.set_attribute("db.params", _serialize_span_attribute(db_params))
161-
try:
162-
del instance.connection._sentry_db_data
163-
except AttributeError:
164-
pass
165166

166167
return f(*args, **kwargs)
167168

tests/integrations/clickhouse_driver/test_clickhouse_driver.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def test_clickhouse_client_breadcrumbs_with_pii(sentry_init, capture_events) ->
168168
"db.user": "default",
169169
"server.address": "localhost",
170170
"server.port": 9000,
171-
"db.params": '[{"x": 100}]',
171+
"db.params": [{"x": 100}],
172172
},
173173
"message": "INSERT INTO test (x) VALUES",
174174
"type": "default",
@@ -181,7 +181,7 @@ def test_clickhouse_client_breadcrumbs_with_pii(sentry_init, capture_events) ->
181181
"db.user": "default",
182182
"server.address": "localhost",
183183
"server.port": 9000,
184-
"db.params": "[[170], [200]]",
184+
"db.params": [[170], [200]],
185185
},
186186
"message": "INSERT INTO test (x) VALUES",
187187
"type": "default",
@@ -195,7 +195,7 @@ def test_clickhouse_client_breadcrumbs_with_pii(sentry_init, capture_events) ->
195195
"server.address": "localhost",
196196
"server.port": 9000,
197197
"db.result": "[[370]]",
198-
"db.params": '{"minv": 150}',
198+
"db.params": {"minv": 150},
199199
},
200200
"message": "SELECT sum(x) FROM test WHERE x > 150",
201201
"type": "default",
@@ -348,9 +348,7 @@ def test_clickhouse_client_spans(
348348
assert event["spans"] == expected_spans
349349

350350

351-
def test_clickhouse_client_spans_with_pii(
352-
sentry_init, capture_events, capture_envelopes
353-
) -> None:
351+
def test_clickhouse_client_spans_with_pii(sentry_init, capture_events) -> None:
354352
sentry_init(
355353
integrations=[ClickhouseDriverIntegration()],
356354
_experiments={"record_sql_params": True},
@@ -646,7 +644,7 @@ def test_clickhouse_dbapi_breadcrumbs_with_pii(sentry_init, capture_events) -> N
646644
"db.user": "default",
647645
"server.address": "localhost",
648646
"server.port": 9000,
649-
"db.params": '[{"x": 100}]',
647+
"db.params": [{"x": 100}],
650648
},
651649
"message": "INSERT INTO test (x) VALUES",
652650
"type": "default",
@@ -659,7 +657,7 @@ def test_clickhouse_dbapi_breadcrumbs_with_pii(sentry_init, capture_events) -> N
659657
"db.user": "default",
660658
"server.address": "localhost",
661659
"server.port": 9000,
662-
"db.params": "[[170], [200]]",
660+
"db.params": [[170], [200]],
663661
},
664662
"message": "INSERT INTO test (x) VALUES",
665663
"type": "default",
@@ -672,8 +670,8 @@ def test_clickhouse_dbapi_breadcrumbs_with_pii(sentry_init, capture_events) -> N
672670
"db.user": "default",
673671
"server.address": "localhost",
674672
"server.port": 9000,
675-
"db.params": '{"minv": 150}',
676-
"db.result": '[[["370"]], [["\'sum(x)\'", "\'Int64\'"]]]',
673+
"db.params": {"minv": 150},
674+
"db.result": '[[[370]], [["sum(x)", "Int64"]]]',
677675
},
678676
"message": "SELECT sum(x) FROM test WHERE x > 150",
679677
"type": "default",

0 commit comments

Comments
 (0)