-
Notifications
You must be signed in to change notification settings - Fork 643
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
Instrumentation breaks psycopg2 when registering types. #143
Comments
On a related note, we might want to reevaluate if we should be wrapping objects with different types or patching classes in place as a lot more libraries may rely on such runtime type checking. In general, instrumentation should not change the behavior of instrumented libraries in any way. I think swapping out types/implementations probably counts as changing behavior as |
Yes, using |
Unless I've misunderstood, is it possible we did not fully port the ddtrace reference? For example: opentelemetry-python-contrib/reference/ddtrace/contrib/psycopg/patch.py Lines 127 to 130 in 5aee3ce
opentelemetry-python-contrib/reference/ddtrace/contrib/psycopg/patch.py Lines 140 to 143 in 5aee3ce
opentelemetry-python-contrib/reference/ddtrace/contrib/psycopg/patch.py Lines 162 to 165 in 5aee3ce
|
Describe your environment
PostgreSQL supports JSON and JSONB types of DB columns. psycopg2 supports registering custom typecasters for these types. Most of the registration functions accept a connection or a cursor instance. The library crashes if anything else is passed in place of a connection or a cursor.
Most higher level frameworks and ORMs support these features out of the box meaning they crash as well. For example, django projects using psycopg2 driver will crash.
Steps to reproduce
Running the following program
results in the following exception:
What is the expected behavior?
For the instrumentation to not crash psycopg2 ever.
What is the actual behavior?
It crashes when psycopg2 enforces connection or cursor types.
Additional context
This is happening because instrumentation wraps connection factories and returns wrapt.ObjectProxy instances that wrap connection or cursor objects. These objects fail the type checks psycopg2 runs internally (probably in C code).
Here: https://github.com/open-telemetry/opentelemetry-python/blob/6019a91980ec84bbf969b0d82d44483c93f3ea4c/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py#L287-L304
And here: https://github.com/open-telemetry/opentelemetry-python/blob/6019a91980ec84bbf969b0d82d44483c93f3ea4c/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py#L361-L389
The solution might be to change how DBAPI instrumentation works and patch actual connection and cursor classes instead of wrap with object proxies.
The text was updated successfully, but these errors were encountered: