|
16 | 16 | ) |
17 | 17 | from sentry_sdk.utils import ( |
18 | 18 | capture_internal_exceptions, |
19 | | - ensure_integration_enabled, |
20 | 19 | parse_version, |
21 | 20 | ) |
22 | 21 |
|
@@ -52,8 +51,12 @@ def setup_once() -> None: |
52 | 51 | asyncpg.Connection._executemany = _wrap_connection_method( |
53 | 52 | asyncpg.Connection._executemany, executemany=True |
54 | 53 | ) |
55 | | - asyncpg.Connection.cursor = _wrap_cursor_creation(asyncpg.Connection.cursor) |
56 | 54 | asyncpg.Connection.prepare = _wrap_connection_method(asyncpg.Connection.prepare) |
| 55 | + |
| 56 | + BaseCursor._bind_exec = _wrap_cursor_method(BaseCursor._bind_exec) |
| 57 | + BaseCursor._bind = _wrap_cursor_method(BaseCursor._bind) |
| 58 | + BaseCursor._exec = _wrap_cursor_method(BaseCursor._exec) |
| 59 | + |
57 | 60 | asyncpg.connect_utils._connect_addr = _wrap_connect_addr( |
58 | 61 | asyncpg.connect_utils._connect_addr |
59 | 62 | ) |
@@ -159,21 +162,26 @@ async def _inner(*args: "Any", **kwargs: "Any") -> "T": |
159 | 162 | return _inner |
160 | 163 |
|
161 | 164 |
|
162 | | -def _wrap_cursor_creation(f: "Callable[..., T]") -> "Callable[..., T]": |
163 | | - @ensure_integration_enabled(AsyncPGIntegration, f) |
164 | | - def _inner(*args: "Any", **kwargs: "Any") -> "T": # noqa: N807 |
165 | | - query = args[1] |
166 | | - params_list = args[2] if len(args) > 2 else None |
| 165 | +def _wrap_cursor_method( |
| 166 | + f: "Callable[..., Awaitable[T]]", |
| 167 | +) -> "Callable[..., Awaitable[T]]": |
| 168 | + async def _inner(*args: "Any", **kwargs: "Any") -> "T": |
| 169 | + if sentry_sdk.get_client().get_integration(AsyncPGIntegration) is None: |
| 170 | + return await f(*args, **kwargs) |
167 | 171 |
|
168 | | - with _record( |
169 | | - None, |
170 | | - query, |
171 | | - params_list, |
| 172 | + cursor = args[0] |
| 173 | + query = _normalize_query(cursor._query) |
| 174 | + with record_sql_queries_supporting_streaming( |
| 175 | + cursor=cursor, |
| 176 | + query=query, |
| 177 | + params_list=None, |
| 178 | + paramstyle=None, |
172 | 179 | executemany=False, |
| 180 | + record_cursor_repr=True, |
| 181 | + span_origin=AsyncPGIntegration.origin, |
173 | 182 | ) as span: |
174 | | - _set_db_data(span, args[0]) |
175 | | - |
176 | | - res = f(*args, **kwargs) |
| 183 | + _set_db_data(span, cursor._connection) |
| 184 | + res = await f(*args, **kwargs) |
177 | 185 |
|
178 | 186 | if isinstance(span, StreamedSpan): |
179 | 187 | with capture_internal_exceptions(): |
|
0 commit comments