Support psycopg 3
Problem Statement
Hi, I'm not sure if I'm missing something but I cannot find sentry's support for psycopg v3 (well, named psycopg ) and If I try a simple test I cannot find sql query information in sentry when using psycopg3.
Am I missing something ? I feel like I'm missing something since I cannot also find the psycopg2 integration, but I'm not very familiar with sentry's code, so maybe I'm looking in the wrong places.
And if it's not yet supported, do you plan to support it?
Thanks for this great project!
Solution Brainstorm
I guess, we would have to add a specific integration for psycopg3. I'm not sure I feel confident to do a correct and clean implementation of this, but I can try if you want.
Note: For the solution, I'm not aware of all the implication, but maybe we can also just implement this as an opentelemetry-python-contrib integration (they have psycopg2 but not psycopg3 yet (cf https://github.com/open-telemetry/opentelemetry-python-contrib/issues/1751).
But I did not manage to make the sentry OTEL integration work and send performance report to sentry :sweat_smile:
Hey @antoine-de!
Thanks for writing in! We have no integrations for the low level psycopg lib but for higher level database access libs like Django ORM or SQLAlchemy or asyncpg.
In my test application I have psycopg==3.1.12 and the spans show up as expected.
How do you connect to your database?
I only use psycopg directly, no ORM, so I do things like:
with psycopg.connect("url") as conn:
conn.execute("some sql") # or use a cursor
In that case it's expected behavior that nothing shows up in Sentry @antoine-de -- we'd need an integration specifically for psycopg, which doesn't exist at the moment.
We don't have any concrete plans to add it in the near future. However, if you or someone else feels like contributing it, please go ahead! We have this checklist that might be helpful and one can also get inspired by the existing DB integrations (e.g. asyncpg). It also doesn't have to be perfect, we can iron out the details during PR review.
Hey @sentrivana,
I wanted to work on creating this integration. As psycopg2 (v2) and psycopg (v3) are different packages, my first idea is I can just develop it for v2 because v2 has got lot more user community than v3.
Should this new integration be for version V2.9.9 which is the latest version ?
Also should this be the place to ask any questions I might have in regards to this ?
As described in my comment above (https://github.com/getsentry/sentry-python/issues/2427#issuecomment-1757302951) we do not need a dedicated psycopg3 integrations, because we hook into sqlalchemy and django.
So please do not create an integration @vagi8 ! But thanks for the dedication! Really love it.
(and also thanks for patience with the django pr you supplied)
I'm not sure I understand @antonpirker , don't sentry also need a psycopg3 integration for users using psycopg3 without sqlalchemy or django?
For my use case, I added a simple spycopg3 integration directly in my project to iterate quickly (here), but I can try to send a PR if you think this can be useful to others.
Yes for the case that you do not use SQLAlchemy or Django a distinct integration would be useful. I just meant if you use SQLAlchemy or Django, then psycopg3 should "just work".
In this case a distinct integration would definitely make sense. (I honestly was not thinking about people using a postgres db without ORM)
No problem, I might be a weird one for not liking ORMs too much :grin:
I'll try to find the time to open a PR with what I have.
I need psycogpg support. Has anyone got this working with open telemetry?
@ibash-corpusant, sounds like @antoine-de got it to work with Otel, see this comment: https://github.com/getsentry/sentry-python/issues/2427#issuecomment-1754658277.