opentelemetry-python-contrib
opentelemetry-python-contrib copied to clipboard
Fix psycopg2 instrument_connection AttributeError
trafficstars
Description
Removes the attempt to set attribute connection._is_instrumented_by_opentelemetry because psycopg2.extensions.connection does not allow setting of extra attributes and we get AttributeError. Similar AttributeError also happened with setattr for connection._otel_orig_cursor_factory so also removed.
Adds todos to re-add checks for connection-already-being-instrumented later, as discussed:
# TODO Add check for attempt to instrument a connection when already instrumented
# https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3138
Fixes https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2522
Type of change
Please delete options that are not relevant.
- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
How Has This Been Tested?
- [X]
tox -e py312-test-instrumentation-psycopg2 - [X] Instrumented db client app that calls
Psycopg2Instrumentor.instrument_connection - [X] Instrumented db client app that calls
Psycopg2Instrumentor.instrument
Does This PR Require a Core Repo Change?
- [ ] Yes. - Link to PR:
- [X] No.
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.
- [X] Followed the style guidelines of this project
- [x] Changelogs have been updated
- [X] Unit tests have been added
- [X] Documentation has been updated