Skip to content
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

WIP/PoC Fix psycopg2 instrument_connection #3043

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tammy-baylis-swi
Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Nov 23, 2024

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. 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 for connection._otel_orig_cursor_factory so instead we store the value at instrumentor attribute _otel_cursor_factory. Since the call to instrument_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 and commenter_options to more signatures to preserve sqlcommenting feature. Adds setting of connect_module at DbApiIntegration init as per update in #3027

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • 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?

  • tox -e py312-test-instrumentation-psycopg2
  • Instrumented db client app that calls Psycopg2Instrumentor.instrument_connection
  • Instrumented db client app that calls Psycopg2Instrumentor.instrument

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant