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

Refactor TracedConnectionProxy #1097

Merged
merged 2 commits into from
Jun 7, 2022
Merged

Conversation

ocelotl
Copy link
Contributor

@ocelotl ocelotl commented May 19, 2022

Fixes #1077

Fixing this issue is a bit complicated:

Here it is suggested that we may monkey patch the register_types function instead of wrapping the connection/cursor. The problem with this approach is that it may be necessary to do this kind of patching in private modules of the Psycopg2 library that may change paths unexpectedly (since they are private), causing our instrumentation to be breakable with any release of Psycopg2.

@owais suggests here that we should patch the classes themselves instead of wrapping to avoid problems with type checking. I understand the point but I think this approach also has the problem that it may require importing from private modules to patch effectively.

The particular issue here happens because PyObject_TypeCheck is used in Psycopg2 register_types and this type checking implemented in C is more restrictive than isinstance (wrapt.ObjectProxy objects passes an isinstance check against the type of the wrapped object).

The solution implemented here is able to pass the PyObject_TypeCheck because the connection created dynamically inherits from the class of the original connection, something wrapt.ObjectProxy does not.

@ocelotl ocelotl self-assigned this May 19, 2022
@ocelotl ocelotl added the Skip Changelog PRs that do not require a CHANGELOG.md entry label May 19, 2022
@ocelotl ocelotl marked this pull request as ready for review May 19, 2022 01:56
@ocelotl ocelotl requested a review from a team May 19, 2022 01:56
@ocelotl ocelotl marked this pull request as draft May 23, 2022 07:53
@ocelotl ocelotl force-pushed the issue_1077 branch 3 times, most recently from 9467bd0 to 7455ba9 Compare May 24, 2022 10:28
@ocelotl ocelotl marked this pull request as ready for review May 24, 2022 11:43
@ocelotl ocelotl merged commit 6876ad8 into open-telemetry:main Jun 7, 2022
@ocelotl ocelotl deleted the issue_1077 branch June 7, 2022 17:21
@phillipuniverse
Copy link
Contributor

phillipuniverse commented Jul 5, 2022

@ocelotl I think this might have caused a regression in the 0.32b0 release for SQLIte at #1179

@ocelotl ocelotl mentioned this pull request Feb 10, 2023
ocelotl added a commit that referenced this pull request Feb 10, 2023
ocelotl added a commit to ocelotl/opentelemetry-python-contrib that referenced this pull request Feb 10, 2023
Several issues have arisen from this bugfix, reverting here until a
better solution can be found.

Fixes open-telemetry#1658
ocelotl added a commit to ocelotl/opentelemetry-python-contrib that referenced this pull request Feb 10, 2023
Several issues have arisen from this bugfix, reverting here until a
better solution can be found.

Fixes open-telemetry#1658
ocelotl added a commit to ocelotl/opentelemetry-python-contrib that referenced this pull request Feb 12, 2023
Several issues have arisen from this bugfix, reverting here until a
better solution can be found.

Fixes open-telemetry#1658
ocelotl added a commit that referenced this pull request Feb 13, 2023
Several issues have arisen from this bugfix, reverting here until a
better solution can be found.

Fixes #1658

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
shalevr added a commit to shalevr/opentelemetry-python-contrib that referenced this pull request Feb 23, 2023
…/github.com/shalevr/opentelemetry-python-contrib into Change-metrics-tests-to-work-with-test_base

* 'Change-metrics-tests-to-work-with-test_base' of https://github.com/shalevr/opentelemetry-python-contrib:
  Fix issue with Flask instrumentation when a request spawn children threads and copies the request context (open-telemetry#1654)
  Add connection attributes to sqlalchemy connect span (open-telemetry#1608)
  Add boto3sqs to docs (open-telemetry#1666)
  Audit and test opentelemetry-instrumentation-elasticsearch NoOpTracer… (open-telemetry#1616)
  Copy change log updates from release/v1.16.x-0.37bx (open-telemetry#1683)
  Update version to 1.17.0.dev/0.38b0.dev (open-telemetry#1677)
  Fix CI Failure (open-telemetry#1680)
  Add better debugging if hatch subprocess fails (open-telemetry#1672)
  Add confluent kafka docs (open-telemetry#1668)
  Support aio_pika 9 (open-telemetry#1670)
  Audit and test opentelemetry-instrumentation-wsgi NoOpTracerProvider (open-telemetry#1610)
  bot (open-telemetry#1667)
  Add commit method for ConfluentKafkaInstrumentor's ProxiedConsumer (open-telemetry#1656)
  Revert open-telemetry#1097 (open-telemetry#1660)
  Audit and test opentelemetry-instrumentation-django NoOpTracerProvider (open-telemetry#1611)
  Audit and test opentelemetry-instrumentation-aiohttp-client NoOpTrace… (open-telemetry#1612)
  Audit and test opentelemetry-instrumentation-flask NoOpTracerProvider (open-telemetry#1614)
  Audit and test opentelemetry-instrumentation-dbapi NoOpTracerProvider (open-telemetry#1607)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dbapi instrumentation breaks psycopg2 when registering types.
4 participants