Skip to content

Commit 075978e

Browse files
authored
ref(db)!: Drop record_sql_params experiment and legacy send_default_pii fallback (#7821)
`record_sql_queries` now reads only `data_collection.database_query_data` to decide whether to record query params, and the `_experiments["record_sql_params"]` option is removed. Tests that relied on the experiment now opt in with `data_collection={"database_query_data": True}`. Also removes `record_params` options in the aiomysql and asyncpg integrations. Refs PY-2798 Refs #7566
1 parent 9018e7b commit 075978e

12 files changed

Lines changed: 90 additions & 323 deletions

File tree

‎MIGRATION_GUIDE.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
163163
- The `trace_ignore_status_codes` option was removed.
164164
- `add_attachment` no longer accepts an `add_to_transactions` argument.
165165
- The `stream_gen_ai_spans` option was removed. All spans are streamed now.
166+
- The experimental `record_sql_params` option was removed. Use the `database_query_data` setting of `data_collection` instead.
167+
- The `record_params` option of `AsyncPGIntegration` and `AioMySQLIntegration` was removed. Use the `database_query_data` setting of `data_collection` instead.
166168

167169

168170
## Deprecated

‎sentry_sdk/consts.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ class CompressionAlgo(Enum):
6565
"Experiments",
6666
{
6767
"max_flags": Optional[int],
68-
"record_sql_params": Optional[bool],
6968
"continuous_profiling_auto_start": Optional[bool],
7069
"transport_zlib_compression_level": Optional[int],
7170
"transport_compression_level": Optional[int],

‎sentry_sdk/integrations/aiomysql.py‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
)
1414
from sentry_sdk.utils import (
1515
capture_internal_exceptions,
16-
has_data_collection_enabled,
1716
parse_version,
1817
)
1918

@@ -28,10 +27,6 @@
2827
class AioMySQLIntegration(Integration):
2928
identifier = "aiomysql"
3029
origin = f"auto.db.{identifier}"
31-
_record_params = False
32-
33-
def __init__(self, *, record_params: bool = False):
34-
AioMySQLIntegration._record_params = record_params
3530

3631
@staticmethod
3732
def setup_once() -> None:
@@ -84,12 +79,7 @@ async def _inner(*args: Any, **kwargs: Any) -> T:
8479
integration = sentry_sdk.get_client().get_integration(AioMySQLIntegration)
8580

8681
client = sentry_sdk.get_client()
87-
should_record_params = False
88-
if has_data_collection_enabled(client.options):
89-
if client.options["data_collection"]["database_query_data"]:
90-
should_record_params = True
91-
else:
92-
should_record_params = integration._record_params if integration else False
82+
should_record_params = client.options["data_collection"]["database_query_data"]
9383

9484
params_list = params if integration and should_record_params else None
9585
param_style = "pyformat" if params_list else None
@@ -134,12 +124,7 @@ async def _inner(*args: Any, **kwargs: Any) -> T:
134124

135125
integration = sentry_sdk.get_client().get_integration(AioMySQLIntegration)
136126
client = sentry_sdk.get_client()
137-
should_record_params = False
138-
if has_data_collection_enabled(client.options):
139-
if client.options["data_collection"]["database_query_data"]:
140-
should_record_params = True
141-
else:
142-
should_record_params = integration._record_params if integration else False
127+
should_record_params = client.options["data_collection"]["database_query_data"]
143128

144129
params_list = seq_of_params if integration and should_record_params else None
145130
param_style = "pyformat" if params_list else None

‎sentry_sdk/integrations/asyncpg.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
class AsyncPGIntegration(Integration):
3333
identifier = "asyncpg"
3434
origin = f"auto.db.{identifier}"
35-
_record_params = False
36-
37-
def __init__(self, *, record_params: bool = False):
38-
AsyncPGIntegration._record_params = record_params
3935

4036
@staticmethod
4137
def setup_once() -> None:
@@ -114,7 +110,10 @@ def _record(
114110
) -> "Iterator[Span]":
115111
client = sentry_sdk.get_client()
116112
integration = client.get_integration(AsyncPGIntegration)
117-
if integration is not None and not integration._record_params:
113+
if (
114+
integration is not None
115+
and not client.options["data_collection"]["database_query_data"]
116+
):
118117
params_list = None
119118

120119
param_style = "pyformat" if params_list else None

‎sentry_sdk/tracing_utils.py‎

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,27 +124,15 @@ def record_sql_queries(
124124
) -> "Generator[sentry_sdk.traces.Span, None, None]":
125125
# TODO: Bring back capturing of params by default
126126
client = sentry_sdk.get_client()
127-
if has_data_collection_enabled(client.options):
128-
if client.options["data_collection"]["database_query_data"]:
129-
if not params_list or params_list == [None]:
130-
params_list = None
131-
132-
if paramstyle == "pyformat":
133-
paramstyle = "format"
134-
else:
127+
if client.options["data_collection"]["database_query_data"]:
128+
if not params_list or params_list == [None]:
135129
params_list = None
136-
paramstyle = None
137-
else:
138-
# TODO: remove this else block once data collection is released
139-
if client.options["_experiments"].get("record_sql_params", False):
140-
if not params_list or params_list == [None]:
141-
params_list = None
142130

143-
if paramstyle == "pyformat":
144-
paramstyle = "format"
145-
else:
146-
params_list = None
147-
paramstyle = None
131+
if paramstyle == "pyformat":
132+
paramstyle = "format"
133+
else:
134+
params_list = None
135+
paramstyle = None
148136

149137
query = _format_sql(cursor, query)
150138

‎tests/integrations/aiomysql/test_aiomysql.py‎

Lines changed: 15 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _connect_args():
102102
async def test_connect(sentry_init, capture_events) -> None:
103103
sentry_init(
104104
integrations=[AioMySQLIntegration()],
105-
_experiments={"record_sql_params": True},
105+
data_collection={"database_query_data": True},
106106
)
107107
events = capture_events()
108108

@@ -123,7 +123,7 @@ async def test_connect(sentry_init, capture_events) -> None:
123123
async def test_execute(sentry_init, capture_events) -> None:
124124
sentry_init(
125125
integrations=[AioMySQLIntegration()],
126-
_experiments={"record_sql_params": True},
126+
data_collection={"database_query_data": True},
127127
)
128128
events = capture_events()
129129

@@ -160,13 +160,19 @@ async def test_execute(sentry_init, capture_events) -> None:
160160
},
161161
{
162162
"category": "query",
163-
"data": {},
163+
"data": {
164+
"db.params": ["Bob", "secret_pw", "datetime.date(1984, 3, 1)"],
165+
"db.paramstyle": "format",
166+
},
164167
"message": "INSERT INTO users(name, password, dob) VALUES (%s, %s, %s)",
165168
"type": "default",
166169
},
167170
{
168171
"category": "query",
169-
"data": {},
172+
"data": {
173+
"db.params": ["Bob"],
174+
"db.paramstyle": "format",
175+
},
170176
"message": "SELECT * FROM users WHERE name = %s",
171177
"type": "default",
172178
},
@@ -177,7 +183,6 @@ async def test_execute(sentry_init, capture_events) -> None:
177183
async def test_execute_many(sentry_init, capture_events) -> None:
178184
sentry_init(
179185
integrations=[AioMySQLIntegration()],
180-
_experiments={"record_sql_params": True},
181186
)
182187
events = capture_events()
183188

@@ -260,47 +265,6 @@ async def test_execute_many_record_params_with_data_collection_enabled(
260265
]
261266

262267

263-
@pytest.mark.asyncio
264-
async def test_execute_many_record_params_with_data_collection_disabled(
265-
sentry_init, capture_events
266-
) -> None:
267-
sentry_init(
268-
integrations=[AioMySQLIntegration(record_params=True)],
269-
data_collection={"database_query_data": False},
270-
)
271-
events = capture_events()
272-
273-
conn = await aiomysql.connect(**_connect_args())
274-
275-
async with conn.cursor() as cur:
276-
await cur.executemany(
277-
"INSERT INTO users(name, password, dob) VALUES (%s, %s, %s)",
278-
[
279-
("Bob", "secret_pw", datetime.date(1984, 3, 1)),
280-
("Alice", "pw", datetime.date(1990, 12, 25)),
281-
],
282-
)
283-
284-
conn.close()
285-
286-
capture_message("hi")
287-
288-
(event,) = events
289-
290-
for crumb in event["breadcrumbs"]["values"]:
291-
del crumb["timestamp"]
292-
293-
assert event["breadcrumbs"]["values"] == [
294-
CRUMBS_CONNECT,
295-
{
296-
"category": "query",
297-
"data": {"db.executemany": True},
298-
"message": "INSERT INTO users(name, password, dob) VALUES (%s, %s, %s)",
299-
"type": "default",
300-
},
301-
]
302-
303-
304268
@pytest.mark.asyncio
305269
async def test_execute_many_record_params_with_data_collection_default(
306270
sentry_init, capture_events
@@ -354,7 +318,7 @@ async def test_execute_many_non_insert(sentry_init, capture_events) -> None:
354318
"""Test executemany with non-INSERT queries (falls back to row-by-row)."""
355319
sentry_init(
356320
integrations=[AioMySQLIntegration()],
357-
_experiments={"record_sql_params": True},
321+
data_collection={"database_query_data": True},
358322
)
359323
events = capture_events()
360324

@@ -400,48 +364,7 @@ async def test_execute_many_non_insert(sentry_init, capture_events) -> None:
400364

401365

402366
@pytest.mark.asyncio
403-
async def test_record_params(sentry_init, capture_events) -> None:
404-
sentry_init(
405-
integrations=[AioMySQLIntegration(record_params=True)],
406-
_experiments={"record_sql_params": True},
407-
)
408-
events = capture_events()
409-
410-
conn = await aiomysql.connect(**_connect_args())
411-
412-
async with conn.cursor() as cur:
413-
await cur.execute(
414-
"INSERT INTO users(name, password, dob) VALUES (%s, %s, %s)",
415-
("Bob", "secret_pw", datetime.date(1984, 3, 1)),
416-
)
417-
418-
conn.close()
419-
420-
capture_message("hi")
421-
422-
(event,) = events
423-
424-
for crumb in event["breadcrumbs"]["values"]:
425-
del crumb["timestamp"]
426-
427-
assert event["breadcrumbs"]["values"] == [
428-
CRUMBS_CONNECT,
429-
{
430-
"category": "query",
431-
"data": {
432-
"db.params": ["Bob", "secret_pw", "datetime.date(1984, 3, 1)"],
433-
"db.paramstyle": "format",
434-
},
435-
"message": "INSERT INTO users(name, password, dob) VALUES (%s, %s, %s)",
436-
"type": "default",
437-
},
438-
]
439-
440-
441-
@pytest.mark.asyncio
442-
async def test_execute_record_params_with_data_collection_enabled(
443-
sentry_init, capture_events
444-
) -> None:
367+
async def test_execute_record_params(sentry_init, capture_events) -> None:
445368
sentry_init(
446369
integrations=[AioMySQLIntegration()],
447370
data_collection={"database_query_data": True},
@@ -479,44 +402,6 @@ async def test_execute_record_params_with_data_collection_enabled(
479402
]
480403

481404

482-
@pytest.mark.asyncio
483-
async def test_execute_record_params_with_data_collection_disabled(
484-
sentry_init, capture_events
485-
) -> None:
486-
sentry_init(
487-
integrations=[AioMySQLIntegration(record_params=True)],
488-
data_collection={"database_query_data": False},
489-
)
490-
events = capture_events()
491-
492-
conn = await aiomysql.connect(**_connect_args())
493-
494-
async with conn.cursor() as cur:
495-
await cur.execute(
496-
"INSERT INTO users(name, password, dob) VALUES (%s, %s, %s)",
497-
("Bob", "secret_pw", datetime.date(1984, 3, 1)),
498-
)
499-
500-
conn.close()
501-
502-
capture_message("hi")
503-
504-
(event,) = events
505-
506-
for crumb in event["breadcrumbs"]["values"]:
507-
del crumb["timestamp"]
508-
509-
assert event["breadcrumbs"]["values"] == [
510-
CRUMBS_CONNECT,
511-
{
512-
"category": "query",
513-
"data": {},
514-
"message": "INSERT INTO users(name, password, dob) VALUES (%s, %s, %s)",
515-
"type": "default",
516-
},
517-
]
518-
519-
520405
@pytest.mark.asyncio
521406
async def test_execute_record_params_with_data_collection_default(
522407
sentry_init, capture_events
@@ -562,7 +447,7 @@ async def test_execute_record_params_with_data_collection_default(
562447
async def test_cursor_context_manager(sentry_init, capture_events) -> None:
563448
sentry_init(
564449
integrations=[AioMySQLIntegration()],
565-
_experiments={"record_sql_params": True},
450+
data_collection={"database_query_data": True},
566451
)
567452
events = capture_events()
568453

@@ -604,7 +489,7 @@ async def test_cursor_context_manager(sentry_init, capture_events) -> None:
604489
async def test_cursor_async_iteration(sentry_init, capture_events) -> None:
605490
sentry_init(
606491
integrations=[AioMySQLIntegration()],
607-
_experiments={"record_sql_params": True},
492+
data_collection={"database_query_data": True},
608493
)
609494
events = capture_events()
610495

@@ -637,7 +522,7 @@ async def test_cursor_async_iteration(sentry_init, capture_events) -> None:
637522
async def test_connection_pool(sentry_init, capture_events) -> None:
638523
sentry_init(
639524
integrations=[AioMySQLIntegration()],
640-
_experiments={"record_sql_params": True},
525+
data_collection={"database_query_data": True},
641526
)
642527
events = capture_events()
643528

0 commit comments

Comments
 (0)