-
Notifications
You must be signed in to change notification settings - Fork 632
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
Fix psycopg2 instrument_connection AttributeError #3043
Open
tammy-baylis-swi
wants to merge
17
commits into
open-telemetry:main
Choose a base branch
from
tammy-baylis-swi:fix-psycopg2-instrument-connection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix psycopg2 instrument_connection AttributeError #3043
tammy-baylis-swi
wants to merge
17
commits into
open-telemetry:main
from
tammy-baylis-swi:fix-psycopg2-instrument-connection
+107
−37
Conversation
This file contains 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
tammy-baylis-swi
changed the title
WIP/PoC Fix psycopg2 instrument_connection
Fix psycopg2 instrument_connection
Dec 5, 2024
tammy-baylis-swi
force-pushed
the
fix-psycopg2-instrument-connection
branch
from
December 5, 2024 00:22
354d085
to
7871734
Compare
tammy-baylis-swi
changed the title
Fix psycopg2 instrument_connection
Fix psycopg2 instrument_connection AttributeError
Dec 5, 2024
tammy-baylis-swi
force-pushed
the
fix-psycopg2-instrument-connection
branch
from
December 5, 2024 00:30
7871734
to
fa46143
Compare
tammy-baylis-swi
force-pushed
the
fix-psycopg2-instrument-connection
branch
from
December 5, 2024 00:37
fa46143
to
a0c9940
Compare
tammy-baylis-swi
commented
Dec 5, 2024
instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py
Show resolved
Hide resolved
tammy-baylis-swi
force-pushed
the
fix-psycopg2-instrument-connection
branch
from
December 5, 2024 21:18
5bd1e94
to
b591b0a
Compare
xrmx
reviewed
Dec 6, 2024
instrumentation/opentelemetry-instrumentation-psycopg2/README.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
lzchen
reviewed
Dec 20, 2024
...pentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py
Outdated
Show resolved
Hide resolved
lzchen
reviewed
Dec 20, 2024
...pentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py
Show resolved
Hide resolved
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
"Breaking bugfix": this includes removal of the
@staticmethod
decorators from this instrumentor'sinstrument_
/uninstrument_connection
methods because the following approach sets/gets instrumentor instance-level attributes. The methods were made static in #549. Not sure if it helps my argument but I'll note that theinstrument_connection
methods for the instrumentors of aiopg, DB-API integration, mysql-connector, and the util-http are not static (anymore?) either. Also, the existing unit tests call it asPsycopg2Instrumentor().instrument_connection(cnx)
anyway and the documentation does not provide any examples.Removes the attempt to set attribute
connection._is_instrumented_by_opentelemetry
becausepsycopg2.extensions.connection
does not allow setting of extra attributes and we getAttributeError
. To preserve this behavior, replaces with a set to instrumentor instance-level_is_instrumented_by_opentelemetry
as defined by inherited BaseInstrumentor (introduced in this PR). We only need to set forinstrument_connection
and not_instrument
because the latter's caller, BaseInstrumentor.instrument, does it.Similar
AttributeError
also happened with setattr forconnection._otel_orig_cursor_factory
so instead we store the value at instrumentor attribute_otel_cursor_factory
. Since the call toinstrument_connection
is done at the connection level I think it's ok to store at this level instead of one more granular like the custom connection proxy class.Also fixes the documentation a bit.
Fixes #2522
Alternative fix
An alternative fix that could keep these methods static is in this other PR: #2795. However, that approach removes connection.cursor_factory parts that might be needed for the fix in #246 to support JSON and JSONB types of DB columns. It also stops using
_is_instrumented_by_opentelemetry
. See also PR comment.Please let me know what you think! I'm fine with whichever approach.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
tox -e py312-test-instrumentation-psycopg2
Psycopg2Instrumentor.instrument_connection
Psycopg2Instrumentor.instrument
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.