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

dbapi instrumentation breaks psycopg2 when registering types. #1077

Closed
lkiss80 opened this issue Apr 29, 2022 · 1 comment · Fixed by #1097
Closed

dbapi instrumentation breaks psycopg2 when registering types. #1077

lkiss80 opened this issue Apr 29, 2022 · 1 comment · Fixed by #1097
Assignees
Labels
bug Something isn't working

Comments

@lkiss80
Copy link

lkiss80 commented Apr 29, 2022

Describe your environment
I'm using dbapi instrumentation to instrument postgresql. When I attempt to register jsonb, psycopg2 crashes. This issue is nearly identical to #143, with the exception that I'm not using Psycopg2Instrumentor.

The reason I'm using dbapi instrumentation vs Psycopg2Instrumentor is because the latter does not support capturing parameters as span attributes.

Steps to reproduce

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.instrumentation import dbapi as dbapi_instrumentor
import psycopg2
import psycopg2.extras

trace.set_tracer_provider(TracerProvider())
db_connection_attributes = {
    "database": "info.dbname",
    "port": "info.port",
    "host": "info.host",
    "user": "info.user",
}
dbapi_instrumentor.trace_integration(
    psycopg2,
    "connect",
    "postgresql",
    db_connection_attributes,
    capture_parameters=True,
)

cnx = psycopg2.connect(host='localhost', port='5432', dbname='postgres', password='1234', user='postgres')
psycopg2.extras.register_default_jsonb(conn_or_curs=cnx, loads=lambda x: x)

results in

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/psycopg2/_json.py", line 156, in register_default_jsonb
    loads=loads, oid=JSONB_OID, array_oid=JSONBARRAY_OID, name='jsonb')
  File "/usr/local/lib/python3.7/site-packages/psycopg2/_json.py", line 125, in register_json
    register_type(JSON, not globally and conn_or_curs or None)
TypeError: argument 2 must be a connection, cursor or None

What is the expected behavior?
For psycopg2 to not crash when used with dbapi instrumentation.

What is the actual behavior?
It crashes when psycopg2 enforces connection or cursor types.

Additional context
Add any other context about the problem here.

@lkiss80 lkiss80 added the bug Something isn't working label Apr 29, 2022
ocelotl added a commit to ocelotl/opentelemetry-python-contrib that referenced this issue May 19, 2022
@ocelotl ocelotl self-assigned this May 19, 2022
ocelotl added a commit to ocelotl/opentelemetry-python-contrib that referenced this issue May 19, 2022
ocelotl added a commit to ocelotl/opentelemetry-python-contrib that referenced this issue May 23, 2022
ocelotl added a commit to ocelotl/opentelemetry-python-contrib that referenced this issue May 24, 2022
ocelotl added a commit to ocelotl/opentelemetry-python-contrib that referenced this issue May 24, 2022
ocelotl added a commit to ocelotl/opentelemetry-python-contrib that referenced this issue Jun 6, 2022
ocelotl added a commit that referenced this issue Jun 7, 2022
* Refactor TracedConnectionProxy

Fixes #1077

* Remove unecessary methods
@lkiss80
Copy link
Author

lkiss80 commented Jun 9, 2023

If the fix for this has been reverted, should the issue be reopened? Or is being tracked elsewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants