logfire icon indicating copy to clipboard operation
logfire copied to clipboard

Psycopg2 automatic instrumentation only partially works

Open bllchmbrs opened this issue 1 year ago • 2 comments

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

bllchmbrs avatar May 13 '24 04:05 bllchmbrs

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!

alexmojaki avatar May 13 '24 11:05 alexmojaki

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!

bllchmbrs avatar May 13 '24 15:05 bllchmbrs

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

Kludex avatar Jul 18 '24 07:07 Kludex