Fix psycopg2 instrument_connection AttributeError#3043
Fix psycopg2 instrument_connection AttributeError#3043tammy-baylis-swi wants to merge 31 commits intoopen-telemetry:mainfrom
Conversation
354d085 to
7871734
Compare
7871734 to
fa46143
Compare
fa46143 to
a0c9940
Compare
instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py
Show resolved
Hide resolved
5bd1e94 to
b591b0a
Compare
instrumentation/opentelemetry-instrumentation-psycopg2/README.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
...pentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py
Outdated
Show resolved
Hide resolved
...pentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py
Show resolved
Hide resolved
|
|
||
| # Save cursor_factory in instrumentor map because | ||
| # psycopg2 connection type does not allow arbitrary attrs | ||
| self._otel_cursor_factories[connection] = connection.cursor_factory |
There was a problem hiding this comment.
We don't use the set of cursor factories for anything? Don't we need to check if the factory is in the set already or is that part of the TODO? I'd rather have the whole duplicate functionality there or you can leave it for a different PR but remove the set for now since it doesn't seem to be doing anything.
0a1360d to
680b0f5
Compare
xrmx
left a comment
There was a problem hiding this comment.
I find the name of the tests very confusing but yeah, better double spans than a crash I guess
|
@xrmx I've resolved merge conflicts and updated changelog for this one. Anything else? |
|
We've got a big release coming up 😺 Will this change be included? |
|
|
||
| # TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql | ||
| @staticmethod | ||
| def uninstrument_connection(connection): |
There was a problem hiding this comment.
I'm not sure we should leave this as a no-op.
If we used a class-level store (eg WeakKeyDictionary), we could track the factories using connection ID and then uninstrument_connection could work.
What do you think @tammy-baylis-swi?
|
Closing this in favour of #4257 |
Description
Removes the attempt to set attribute
connection._is_instrumented_by_opentelemetrybecausepsycopg2.extensions.connectiondoes not allow setting of extra attributes and we getAttributeError. SimilarAttributeErroralso happened with setattr forconnection._otel_orig_cursor_factoryso also removed.Adds todos to re-add checks for connection-already-being-instrumented later, as discussed:
Fixes #2522
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
tox -e py312-test-instrumentation-psycopg2Psycopg2Instrumentor.instrument_connectionPsycopg2Instrumentor.instrumentDoes This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.