'OpenTelemetry is not tracing SQL Statements while using cursor_factory as NamedTupleCursor

Kindly look at the code below. I'm using opentelemetry for tracing. Psycopg2Instrumentor for PostgreSQL tracing. Here only the "show server_version" SQL statement is getting traced. But the SQL statement in execute method is not traced. I think it's because of using NamedTupleCursor cursor_factory. If I remove NamedTupleCursor, it's tracing the main SQL statements. Could you please help me to trace the main SQL statement without removing NamedTupleCursor?

def self.get_connection():
   #conn = create_connection()
   with conn.cursor() as curs:
       curs.execute("show server_version") ---> this sql statement is getting tracked
   return conn

def execute()
   with self.get_connection() as conn:
       with conn.cursor(cursor_factory=NamedTupleCursor) as curs:
           curs.execute("Sql statements"). ---> this sql statement is **not** getting tracked```


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source