Skip to content

Commit d340033

Browse files
authored
Merge branch 'main' into psycopg-cursor-execute-update
2 parents a9debda + 4534249 commit d340033

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
updatecli v0.102.0
1+
updatecli v0.103.0

elasticapm/instrumentation/packages/psycopg2.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ def _bake_sql(self, sql):
5959
def extract_signature(self, sql):
6060
return extract_signature(sql)
6161

62+
def execute(self, query, vars=None):
63+
return self._trace_sql(self.__wrapped__.execute, query, vars)
64+
65+
def executemany(self, query, vars_list):
66+
return self._trace_sql(self.__wrapped__.executemany, query, vars_list)
67+
6268
def __enter__(self):
6369
return PGCursorProxy(self.__wrapped__.__enter__(), destination_info=self._self_destination_info)
6470

tests/instrumentation/psycopg2_tests.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,27 @@ def test_fully_qualified_table_name():
266266
assert "SELECT FROM db.schema.mytable" == actual
267267

268268

269+
@pytest.mark.integrationtest
270+
@pytest.mark.skipif(not has_postgres_configured, reason="PostgresSQL not configured")
271+
def test_cursor_execute_signature(instrument, postgres_connection, elasticapm_client):
272+
cursor = postgres_connection.cursor()
273+
cursor.execute(query="SELECT 1", vars=None)
274+
row = cursor.fetchone()
275+
276+
assert row
277+
278+
279+
@pytest.mark.integrationtest
280+
@pytest.mark.skipif(not has_postgres_configured, reason="PostgresSQL not configured")
281+
def test_cursor_executemany_signature(instrument, postgres_connection, elasticapm_client):
282+
cursor = postgres_connection.cursor()
283+
res = cursor.executemany(
284+
query="INSERT INTO test VALUES (%s, %s)",
285+
vars_list=((4, "four"),),
286+
)
287+
assert res is None
288+
289+
269290
@pytest.mark.integrationtest
270291
@pytest.mark.skipif(not has_postgres_configured, reason="PostgresSQL not configured")
271292
def test_destination(instrument, postgres_connection, elasticapm_client):

0 commit comments

Comments
 (0)