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

Fix psycopg2 instrument issue #2795

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

qiuge615
Copy link
Contributor

Description

Currently there is issue with psycopg2, the instrumentation can not work as expected. Update the codes based on mysql and sqlite3 to resolve the issue. Will check the two properties _otel_orig_cursor_factory and _is_instrumented_by_opentelemetry in subsequent issue later.
Fix one issue in unit test, assign instrumented connection to cnx.

Fixes #2522

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Tested with below command to run unit test
tox -e py310-test-opentelemetry-instrumentation-psycopg2

Tested traces with local environment and the traces are displayed without error.

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

@kayhern kayhern requested a review from a team August 28, 2024 18:45
Copy link
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is missing a test showing what is currently not working

@qiuge615
Copy link
Contributor Author

qiuge615 commented Sep 3, 2024

Thanks for your suggestion, I will add a test case for it.

@qiuge615
Copy link
Contributor Author

qiuge615 commented Sep 5, 2024

I think this is missing a test showing what is currently not working
Added test case for this. It will be failed when running with previous codes, since there is no property _is_instrumented_by_opentelemetry in connection object. Please review and let me know if there is anything I need to update, thanks.

@kayhern kayhern requested a review from a team as a code owner September 26, 2024 14:39
connection._is_instrumented_by_opentelemetry = True
else:
def instrument_connection(self, connection, tracer_provider=None):
if isinstance(connection, ObjectProxy):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure this solves the original issue (we still don't know WHY the error is being generated when we are trying to access _is_instrumented_by_opentelemetry field but this current change is fine as a short-term solution. Please add a TODO or follow-up issue to investigate.

@lzchen
Copy link
Contributor

lzchen commented Oct 28, 2024

@qiuge615

Please allow for maintainer edits so we can rebase for you.

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