Skip to content

Commit 90a2220

Browse files
committed
Fix asyncpg get_query to make it compatible with asyncpg>=0.29
1 parent 05332cd commit 90a2220

File tree

1 file changed

+6
-3
lines changed
  • elasticapm/instrumentation/packages/asyncio

1 file changed

+6
-3
lines changed

elasticapm/instrumentation/packages/asyncio/asyncpg.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@ class AsyncPGInstrumentation(AsyncAbstractInstrumentedModule):
5555
("asyncpg.protocol.protocol", "Protocol.copy_out"),
5656
]
5757

58-
def get_query(self, method, args):
58+
def get_query(self, method, args, kwargs=None):
5959
if method in ["Protocol.query", "Protocol.copy_in", "Protocol.copy_out"]:
6060
return args[0]
61-
else:
61+
elif args:
6262
return args[0].query
63+
else:
64+
# asyncpg>=0.29 pass data as kwargs
65+
return kwargs["state"].query
6366

6467
async def call(self, module, method, wrapped, instance, args, kwargs):
65-
query = self.get_query(method, args)
68+
query = self.get_query(method, args, kwargs)
6669
name = extract_signature(query)
6770
sql_string = shorten(query, string_length=10000)
6871
context = {"db": {"type": "sql", "statement": sql_string}}

0 commit comments

Comments
 (0)