Fix psycopg2 (un)instrument_connection to use weakref, not mutate connection object#4257
Merged
xrmx merged 11 commits intoopen-telemetry:mainfrom Mar 3, 2026
Conversation
JWinermaSplunk
approved these changes
Feb 25, 2026
JWinermaSplunk
left a comment
There was a problem hiding this comment.
I am not aware of the previous PR, but this LGTM!
MikeGoldsmith
approved these changes
Feb 25, 2026
Member
MikeGoldsmith
left a comment
There was a problem hiding this comment.
Looks great, thanks @tammy-baylis-swi 👍🏻
This was referenced Feb 26, 2026
xrmx
approved these changes
Feb 27, 2026
instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py
Outdated
Show resolved
Hide resolved
herin049
reviewed
Feb 27, 2026
...pentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py
Outdated
Show resolved
Hide resolved
...pentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py
Outdated
Show resolved
Hide resolved
herin049
approved these changes
Mar 2, 2026
Contributor
|
LGTM! |
shuningc
pushed a commit
to shuningc/opentelemetry-python-contrib
that referenced
this pull request
Mar 5, 2026
…nection object (open-telemetry#4257) * Fix psycopg2 (un)instrument_connection to use weakref, not mutate object * Changelog * conditional import for docs types * Lint * SImplify test * Simplify * Fix docs --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Changes psycopg2 instrumentation's
instrument_connectionanduninstrument_connectionfunctions to use aWeakKeyDictionarystore and retrieve original connection objects (respectively). Removes the attempts to set attributes on the connection objects themselves becausepsycopg2.extensions.connectiondoes not allow setting of extra attributes and we get AttributeError.This is an alternative/replacement for #3043
Fixes #2522 and #3138
Suggested in this PR's comment!
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
tox -e py312-test-opentelemetry-instrumentation-psycopg2-0Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.