fix: Update PsycopgInstrumentor.instrument_connection to use async cursor factory#3956
Conversation
93f0638 to
b3a3ee1
Compare
|
Can we add some unit tests to cover this scenario? Also make sure to add a changelog entry. |
Yup, updated the existing tests and added a new test for this change. |
ddb7153 to
e2ff5af
Compare
xrmx
left a comment
There was a problem hiding this comment.
Please rebase / merge main and add a CHANGELOG entry.
e2ff5af to
5670b96
Compare
Rebased and updated the |
|
@dspatoulas pylint is not happy
|
@xrmx sorry about that, I ran the tests locally but not the linter 🤦♂️ |
…cursor factory (open-telemetry#3956) * Fix instrument_connection to use async cursor factory for `AsyncConnection` * Update tests for psycopg async cursor factory change * Add `psycopg` async cursor fix to CHANGELOG.md * Fix pylint error for `MockAsyncConnection.cursor` * Update CHANGELOG.md --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
…cursor factory (open-telemetry#3956) * Fix instrument_connection to use async cursor factory for `AsyncConnection` * Update tests for psycopg async cursor factory change * Add `psycopg` async cursor fix to CHANGELOG.md * Fix pylint error for `MockAsyncConnection.cursor` * Update CHANGELOG.md --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
…cursor factory (open-telemetry#3956) * Fix instrument_connection to use async cursor factory for `AsyncConnection` * Update tests for psycopg async cursor factory change * Add `psycopg` async cursor fix to CHANGELOG.md * Fix pylint error for `MockAsyncConnection.cursor` * Update CHANGELOG.md --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
Description
Update
PsycopgInstrumentor.instrument_connectionto support both sync and asyncpsycopgconnections by configuring the appropriatecursor_factory.Previously,
instrument_connectionalways used the sync cursor factory and did not properly handleAsyncConnectioninstances. As a result, calls made through an async connection would fail because of the async context.With this change:
connectionis apsycopg.AsyncConnection, we setconnection.cursor_factoryto_new_cursor_async_factory(...).connection.cursor_factoryto_new_cursor_factory(...).This aligns
instrument_connectionwith the behavior of the globalinstrument()helper and ensures both sync and async connections are correctly traced.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Updated the tests in the
psycopginstrumentation test suite to cover both sync and async connections, added a new test for the async connection code path that was previously not tested.Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.