logfire icon indicating copy to clipboard operation
logfire copied to clipboard

Psyopg2 Instrumentation doesn't work with `RealDictCursor`

Open bllchmbrs opened this issue 1 year ago • 0 comments

Description

I'm still trying to get the exact repro, but I cannot instrument psycopg2 and get results when I use from psycopg2.extras import RealDictCursor

I am using the instrumentation, BUT when I go to run it, no values show up for cursors that go through that path.

import logfire
import psycopg2 as pg
from psycopg2.extras import RealDictCursor

logfire.instrument_psycopg()

conn = pg.connect()

def get_plain_cursor(conn):
    return conn.cursor()

def get_cursor(conn):
    return conn.cursor(cursor_factory=RealDictCursor)


def run_query(cur, query: str, args=None):
    try:
        if isinstance(args, tuple):
            cur.execute(query, args)
        elif isinstance(args, list):
            cur.executemany(query, args)
        else:
            cur.execute(query)
    except Exception as e:
        logger.error("Failed to run query", error=e)
        raise e

with get_plain_cursor(conn) as pc:
    run_query(pc, "SELECT 1")
# this shows the select query in logfire

with get_cursor(conn) as pc:
    run_query(pc, "SELECT 1")
# this does NOT show the select query

Python, Logfire & OS Versions, related packages (not required)

No response

bllchmbrs avatar Aug 16 '24 22:08 bllchmbrs