-
Notifications
You must be signed in to change notification settings - Fork 798
Fix psycopg2 instrument issue #2795
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
bc77e8f
224e03a
72ab2f3
092b8ba
6a8046a
4614565
dbd4483
4d4ca41
87d74c5
17f23e3
30cff63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,8 @@ | |
import typing | ||
from typing import Collection | ||
|
||
from wrapt import ObjectProxy | ||
|
||
import psycopg2 | ||
from psycopg2.extensions import ( | ||
cursor as pg_cursor, # pylint: disable=no-name-in-module | ||
|
@@ -158,33 +160,33 @@ def _uninstrument(self, **kwargs): | |
dbapi.unwrap_connect(psycopg2, "connect") | ||
|
||
# TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql | ||
@staticmethod | ||
def instrument_connection(connection, tracer_provider=None): | ||
if not hasattr(connection, "_is_instrumented_by_opentelemetry"): | ||
connection._is_instrumented_by_opentelemetry = False | ||
|
||
if not connection._is_instrumented_by_opentelemetry: | ||
setattr( | ||
connection, _OTEL_CURSOR_FACTORY_KEY, connection.cursor_factory | ||
) | ||
connection.cursor_factory = _new_cursor_factory( | ||
tracer_provider=tracer_provider | ||
) | ||
connection._is_instrumented_by_opentelemetry = True | ||
else: | ||
def instrument_connection(self, connection, tracer_provider=None): | ||
if isinstance(connection, ObjectProxy): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
_logger.warning( | ||
"Attempting to instrument Psycopg connection while already instrumented" | ||
) | ||
return connection | ||
return connection | ||
|
||
db_integration = DatabaseApiIntegration( | ||
__name__, | ||
self._DATABASE_SYSTEM, | ||
connection_attributes=self._CONNECTION_ATTRIBUTES, | ||
version=__version__, | ||
tracer_provider=tracer_provider, | ||
) | ||
db_integration.get_connection_attributes(connection) | ||
db_integration.cursor_factory = _new_cursor_factory( | ||
tracer_provider=tracer_provider | ||
) | ||
return dbapi.get_traced_connection_proxy(connection, db_integration) | ||
|
||
# TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql | ||
@staticmethod | ||
def uninstrument_connection(connection): | ||
def uninstrument_connection(self, connection): | ||
connection.cursor_factory = getattr( | ||
connection, _OTEL_CURSOR_FACTORY_KEY, None | ||
) | ||
|
||
return connection | ||
return dbapi.uninstrument_connection(connection) | ||
|
||
|
||
# TODO(owais): check if core dbapi can do this for all dbapi implementations e.g, pymysql and mysql | ||
|
Uh oh!
There was an error while loading. Please reload this page.