Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions elasticapm/instrumentation/packages/psycopg2.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def _bake_sql(self, sql):
def extract_signature(self, sql):
return extract_signature(sql)

def execute(self, query, vars=None):
return self._trace_sql(self.__wrapped__.execute, query, vars)

def executemany(self, query, vars_list):
return self._trace_sql(self.__wrapped__.executemany, query, vars_list)

def __enter__(self):
return PGCursorProxy(self.__wrapped__.__enter__(), destination_info=self._self_destination_info)

Expand Down
21 changes: 21 additions & 0 deletions tests/instrumentation/psycopg2_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,27 @@ def test_fully_qualified_table_name():
assert "SELECT FROM db.schema.mytable" == actual


@pytest.mark.integrationtest
@pytest.mark.skipif(not has_postgres_configured, reason="PostgresSQL not configured")
def test_cursor_execute_signature(instrument, postgres_connection, elasticapm_client):
cursor = postgres_connection.cursor()
cursor.execute(query="SELECT 1", vars=None)
row = cursor.fetchone()

assert row


@pytest.mark.integrationtest
@pytest.mark.skipif(not has_postgres_configured, reason="PostgresSQL not configured")
def test_cursor_executemany_signature(instrument, postgres_connection, elasticapm_client):
cursor = postgres_connection.cursor()
res = cursor.executemany(
query="INSERT INTO test VALUES (%s, %s)",
vars_list=((4, "four"),),
)
assert res is None


@pytest.mark.integrationtest
@pytest.mark.skipif(not has_postgres_configured, reason="PostgresSQL not configured")
def test_destination(instrument, postgres_connection, elasticapm_client):
Expand Down
Loading