logfire icon indicating copy to clipboard operation
logfire copied to clipboard

Support the postgres wire protocol

Open jgpruitt opened this issue 5 months ago • 6 comments

Description

Using SQL to query traces is a truly remarkable feature. Currently, it appears to be locked behind the UI or MCP, though. I want to use a query tool like psql. I LIVE in psql. I am primarily using Claude Code with MCP to explore my tracing data, but I'm fully capable of writing my own SQL queries to get exactly what I want. Supporting the postgres wire protocol and exposing an endpoint that I could use with general-purpose query tools like psql would unlock so much power.

jgpruitt avatar Oct 02 '25 15:10 jgpruitt

Currently, it appears to be locked behind the UI or MCP, though

No, you can use https://logfire.pydantic.dev/docs/how-to-guides/query-api/

(but btw please set a min_timestamp when you do)

alexmojaki avatar Oct 02 '25 15:10 alexmojaki

Thanks for the link to the docs to the API. I share John's desire to be able to connect to the query API directly within a SQL client as that'd be really cool I think to leverage the tooling that exists around SQL query writing into interacting with the API (vs using a HTTP client as suggested in the docs).

I made a PoC of what that could look like with regards to the postgresql wire protocol to make @jgpruitt happy, which is available at https://github.com/timescale/logfire-pg.

MasterOdin avatar Oct 05 '25 05:10 MasterOdin

oh nice! We actually had this before - @adriangb implemented the entire PG wire protocol in python. We removed it when we switched database.

It's definitely something we want to re-add, but haven't had time yet.

I always throught it would be better implemented in Rust than Python, maybe @adriangb would be keener on doing it in rust now?

samuelcolvin avatar Oct 05 '25 06:10 samuelcolvin

@MasterOdin curious how you'd feel about using Arrow Flight SQL as the wire protocol instead?

adriangb avatar Oct 05 '25 11:10 adriangb

Personally, psql is my preferred database query tool by a long shot. Arrow Flight SQL would not work for it, though I believe it works for others.

jgpruitt avatar Oct 09 '25 15:10 jgpruitt

My only potential concern would be on client support for Arrow Flight SQL as I've not heard it. I do use duckdb some, and I think that the airport extension should work, but I'm not totally certain.

Like I think having something that is postgres wire compatible would ease adoption, so long as it's not too onerous to use Flight SQL, should be fine, and then there's still the project I linked above for someone who absolutely needed postgres wire compatibility to analyse logfire records.

MasterOdin avatar Oct 13 '25 18:10 MasterOdin