pydantic / logfire

Uncomplicated Observability for Python and beyond! 🪵🔥
https://docs.pydantic.dev/logfire/
MIT License
1.66k stars 45 forks source link

Psycopg2 automatic instrumentation only partially works #166

Open bllchmbrs opened 1 month ago

bllchmbrs commented 1 month ago

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

alexmojaki commented 1 month ago

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!

bllchmbrs commented 1 month ago

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!