Psycopg2 automatic instrumentation only partially works
Description
I found these docs.
When I instrument my connection like this: logfire.instrument_psycopg(connection) I get an error: `AttributeError: 'psycopg2.extensions.connection' object has no attribute '_is_instrumented_by_opentelemetry'
However, if I run logfire.instrument_psycopg() it works fine.
I found this strange because the docs suggested I could instrument a specific connection like this:
connection = psycopg.connect(
'dbname=database user=user password=secret host=0.0.0.0 port=5432'
)
# Or instrument just the connection:
logfire.instrument_psycopg(connection)
This is either a bug or user error, I am not sure how it could be user error though because the connection has worked fine for many months.
Python, Logfire & OS Versions, related packages (not required)
No response
Thanks for the report. I had tested psycopg2, and pyscopg v3 connections, but not psycopg2 connections :facepalm:
I've reported the underlying issue here: https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2522
I'm surprised no one else has reported it before!
Me too, now that you mention what it is!
Guess it's not a blocker because I can work around, but interesting to see I'm the one that hit it!
Since this issue is on OTel side, I'll be closing this one. 🙏
For people interested, you can watch this: https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2522