Skip to content

Commit 7ad3bf9

Browse files
committed
Remove the _bind patch again
1 parent 7e5e398 commit 7ad3bf9

2 files changed

Lines changed: 8 additions & 30 deletions

File tree

sentry_sdk/integrations/asyncpg.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ def setup_once() -> None:
5353
)
5454
asyncpg.Connection.prepare = _wrap_connection_method(asyncpg.Connection.prepare)
5555

56-
BaseCursor._bind = _wrap_cursor_method(
57-
BaseCursor._bind, record_query_source=False
58-
)
5956
BaseCursor._bind_exec = _wrap_cursor_method(BaseCursor._bind_exec)
6057
BaseCursor._exec = _wrap_cursor_method(BaseCursor._exec)
6158

@@ -166,8 +163,6 @@ async def _inner(*args: "Any", **kwargs: "Any") -> "T":
166163

167164
def _wrap_cursor_method(
168165
f: "Callable[..., Awaitable[T]]",
169-
*,
170-
record_query_source: bool = True,
171166
) -> "Callable[..., Awaitable[T]]":
172167
async def _inner(*args: "Any", **kwargs: "Any") -> "T":
173168
if sentry_sdk.get_client().get_integration(AsyncPGIntegration) is None:
@@ -187,11 +182,11 @@ async def _inner(*args: "Any", **kwargs: "Any") -> "T":
187182
_set_db_data(span, cursor._connection)
188183
res = await f(*args, **kwargs)
189184

190-
if record_query_source and isinstance(span, StreamedSpan):
185+
if isinstance(span, StreamedSpan):
191186
with capture_internal_exceptions():
192187
add_query_source(span)
193188

194-
if record_query_source and not isinstance(span, StreamedSpan):
189+
if not isinstance(span, StreamedSpan):
195190
with capture_internal_exceptions():
196191
add_query_source(span)
197192

tests/integrations/asyncpg/test_asyncpg.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,6 @@ async def test_cursor_manual(sentry_init, capture_events) -> None:
410410
"message": "SELECT * FROM users WHERE dob > $1",
411411
"type": "default",
412412
},
413-
{
414-
"category": "query",
415-
"data": {"db.cursor": mock.ANY},
416-
"message": "SELECT * FROM users WHERE dob > $1",
417-
"type": "default",
418-
},
419413
{"category": "query", "data": {}, "message": "COMMIT;", "type": "default"},
420414
]
421415

@@ -1468,9 +1462,7 @@ async def test_cursor__bind_exec_creates_spans(
14681462

14691463

14701464
@pytest.mark.asyncio
1471-
async def test_cursor_bind_and_exec_methods_create_spans(
1472-
sentry_init, capture_events
1473-
) -> None:
1465+
async def test_cursor__exec_methods_create_spans(sentry_init, capture_events) -> None:
14741466
sentry_init(
14751467
integrations=[AsyncPGIntegration()],
14761468
traces_sample_rate=1.0,
@@ -1502,34 +1494,25 @@ async def test_cursor_bind_and_exec_methods_create_spans(
15021494

15031495
(event,) = events
15041496

1505-
assert len(event["spans"]) == 7
1497+
assert len(event["spans"]) == 6
15061498

15071499
connect_span = event["spans"][0]
15081500
executemany_span = event["spans"][1]
15091501
begin_span = event["spans"][2]
1510-
bind_span = event["spans"][3]
1511-
fetchrow_span_1 = event["spans"][4]
1512-
fetchrow_span_2 = event["spans"][5]
1513-
commit_span = event["spans"][6]
1502+
fetchrow_span_1 = event["spans"][3]
1503+
fetchrow_span_2 = event["spans"][4]
1504+
commit_span = event["spans"][5]
15141505

15151506
assert connect_span["description"] == "connect"
15161507
assert (
15171508
executemany_span["description"]
15181509
== "INSERT INTO users(name, password, dob) VALUES($1, $2, $3)"
15191510
)
15201511
assert begin_span["description"] == "BEGIN;"
1521-
assert bind_span["description"] == "SELECT * FROM users WHERE dob > $1"
15221512
assert fetchrow_span_1["description"] == "SELECT * FROM users WHERE dob > $1"
15231513
assert fetchrow_span_2["description"] == "SELECT * FROM users WHERE dob > $1"
15241514
assert commit_span["description"] == "COMMIT;"
15251515

1526-
assert bind_span["data"]["db.cursor"] is not None
1527-
assert bind_span["data"]["db.system"] == "postgresql"
1528-
assert bind_span["data"]["db.driver.name"] == "asyncpg"
1529-
assert bind_span["origin"] == "auto.db.asyncpg"
1530-
assert SPANDATA.CODE_LINENO not in bind_span.get("data", {})
1531-
assert SPANDATA.CODE_FILEPATH not in bind_span.get("data", {})
1532-
15331516
for span in (fetchrow_span_1, fetchrow_span_2):
15341517
assert span["data"]["db.cursor"] is not None
15351518
assert span["data"]["db.system"] == "postgresql"
@@ -1538,5 +1521,5 @@ async def test_cursor_bind_and_exec_methods_create_spans(
15381521
_assert_query_source(
15391522
span,
15401523
False,
1541-
"test_cursor_bind_and_exec_methods_create_spans",
1524+
"test_cursor__exec_methods_create_spans",
15421525
)

0 commit comments

Comments
 (0)