What's hidden in the psycopg2 connect span?

Hi!, this is probably a weird one but I need to know. Recently our API needed to connect to an external cloud (api's at AWS, psql db is at azure).
We found that the connect span took more than a second to complete. That could be explained by inter cloud latency, but.. more than a second?! And what's more confusing is the fact that queries made to the same db instance run relatively fast (200ms avg)

So my question is, what's involved in that span that could explain this latency?

BTW: It's not DNS , I checked.

Thanks!

Hey @Rodrigo_Jimenez

The connect span represents the time it takes to call the psycopg2.connect() function. I can't really say what exactly could be slow there, as I'm not familiar enough with the internals of psycopg2. However, I do know that connecting to a PostgreSQL database can be relatively heavy, especially between cloud providers. Did you already look into connection pooling (e.g. pgbouncer) or persistent connections? That could limit the impact of latency while establishing the connection.

Cheers
Beni

Thanks.
I was actually trying not to use pg_bouncer or similiar for now until I know wha's up.
May be this is a delay I cant prevent and the only solution is connection pooling.
I can't even sniff this traffic since it's all TLS.
Thanks again!

I'm not sure what's causing these big delays but thanks for answering anyways.
I'll mark the solution.