WIP/PoC Fix psycopg2 instrument_connection #3043
Draft
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
Removes the attempt to set attribute
connection._is_instrumented_by_opentelemetry
becausepsycopg2.extensions.connection
does not allow setting of extra attributes and we getAttributeError
. Replaces with a set to instrumentor-level_is_instrumented_by_opentelemetry
as defined by inherited BaseInstrumentor (introduced in this PR).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 in a custom connection proxy class.Adds optional kwargs
enable_commenter
andcommenter_options
to more signatures to preserve sqlcommenting feature. Adds setting ofconnect_module
at DbApiIntegration init as per update in #3027Fixes # (issue)
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.