Skip to content

Commit 35d2b7a

Browse files
committed
Serialize w/ json.dumps instead of str
1 parent b46faea commit 35d2b7a

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

sentry_sdk/integrations/asyncpg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22
import contextlib
3+
import json
34
from typing import Any, TypeVar, Callable, Awaitable, Iterator
45

56
import sentry_sdk
@@ -147,7 +148,7 @@ def _inner(*args: Any, **kwargs: Any) -> T: # noqa: N807
147148
) as span:
148149
_set_db_data(span, args[0])
149150
res = f(*args, **kwargs)
150-
span.set_attribute("db.cursor", str(res))
151+
span.set_attribute("db.cursor", json.dumps(res))
151152

152153
return res
153154

sentry_sdk/integrations/clickhouse_driver.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
13
import sentry_sdk
24
from sentry_sdk.consts import OP, SPANDATA
35
from sentry_sdk.integrations import Integration, DidNotEnable
@@ -99,7 +101,7 @@ def _inner(*args: P.args, **kwargs: P.kwargs) -> T:
99101

100102
if params and should_send_default_pii():
101103
connection._sentry_db_params = params
102-
span.set_attribute("db.params", str(params))
104+
span.set_attribute("db.params", json.dumps(params))
103105

104106
# run the original code
105107
ret = f(*args, **kwargs)
@@ -117,7 +119,7 @@ def _inner_end(*args: P.args, **kwargs: P.kwargs) -> T:
117119

118120
if span is not None:
119121
if res is not None and should_send_default_pii():
120-
span.set_attribute("db.result", str(res))
122+
span.set_attribute("db.result", json.dumps(res))
121123

122124
with capture_internal_exceptions():
123125
query = span.get_attribute("db.query.text")
@@ -159,7 +161,7 @@ def _inner_send_data(*args: P.args, **kwargs: P.kwargs) -> T:
159161
getattr(instance.connection, "_sentry_db_params", None) or []
160162
)
161163
db_params.extend(data)
162-
span.set_attribute("db.params", str(db_params))
164+
span.set_attribute("db.params", json.dumps(db_params))
163165
try:
164166
del instance.connection._sentry_db_params
165167
except AttributeError:

sentry_sdk/tracing_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import contextlib
22
import inspect
3+
import json
34
import os
45
import re
56
import sys
7+
import uuid
68
from collections.abc import Mapping
79
from datetime import datetime, timedelta, timezone
810
from functools import wraps
911
from urllib.parse import quote, unquote
10-
import uuid
1112

1213
import sentry_sdk
1314
from sentry_sdk.consts import OP, SPANDATA
@@ -133,13 +134,13 @@ def record_sql_queries(
133134

134135
data = {}
135136
if params_list is not None:
136-
data["db.params"] = str(params_list)
137+
data["db.params"] = json.dumps(params_list)
137138
if paramstyle is not None:
138-
data["db.paramstyle"] = str(paramstyle)
139+
data["db.paramstyle"] = json.dumps(paramstyle)
139140
if executemany:
140141
data["db.executemany"] = True
141142
if record_cursor_repr and cursor is not None:
142-
data["db.cursor"] = str(cursor)
143+
data["db.cursor"] = json.dumps(cursor)
143144

144145
with capture_internal_exceptions():
145146
sentry_sdk.add_breadcrumb(message=query, category="query", data=data)

tests/integrations/clickhouse_driver/test_clickhouse_driver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
```
66
"""
77

8+
import json
9+
810
import clickhouse_driver
911
from clickhouse_driver import Client, connect
1012

@@ -16,7 +18,7 @@
1618
if clickhouse_driver.VERSION < (0, 2, 6):
1719
EXPECT_PARAMS_IN_SELECT = False
1820

19-
PARAMS_SERIALIZER = str
21+
PARAMS_SERIALIZER = json.dumps
2022

2123

2224
def test_clickhouse_client_breadcrumbs(sentry_init, capture_events) -> None:

0 commit comments

Comments
 (0)