Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook for psycopg2 (_dbapi2) cursor not called when using with resources constructs #117

Open
Vaidic opened this issue Jul 19, 2021 · 0 comments

Comments

@Vaidic
Copy link

Vaidic commented Jul 19, 2021

While using opentracing-python-instrumentation for Postgres connection I noticed that the calls made inside the python with resources block are not being traced.

The DB calls made in the following code block is properly traced:

           conn = get_connection() // <--- this method returns the connection object already created at initialization
           cur = conn.cursor()
           cur.execute("SELECT 1")  
           cur.close()

However, if written with with resources the calls are not being traced:

            with get_connection() as conn:
                with conn.cursor() as cur:
                    cur.execute("SELECT 1")  

or even the following does not work :

            conn = get_connection()
            with conn.cursor() as cur:
                cur.execute("SELECT 1")  

Based on my debugging, I see that the call to ConnectionWrapper.cursor (in file _dbapi2.py) is not made when the cursor is called from within the with resources block, and then the subsequent calls to 'execute' hook (in psycopg2.py) are never made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant