Skip to content

Psyopg2 Instrumentation doesn't work with RealDictCursor #381

@bllchmbrs

Description

@bllchmbrs

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

Metadata

Metadata

Assignees

Labels

bugBug related to the Logfire Python SDK

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions