Question: Ability to query clickhouse to get user session messages
Mohit21GoJs opened this issue · 5 comments
Hi Team,
I would like to know is it recommended to query the clickhouse to query the user session history, we have an app which would like to retrieve history of messages in a session, i believe it can be achieved through clickhouse, is this a recommended practice?
No, I don't think that's the way to go.
While we do store session id in Clickhouse, Clickhouse is primarily an analytics tool for statistical queries such as session duration, message count per session etc. With Laminar, we store sessions in Postgres as well, and you can see them in our frontend in the sessions view. I will improve the doc with screenshots later this weekend, but here's a good starting point: https://docs.lmnr.ai/tracing/structure#grouping-traces
If you need other features in the sessions view than what we currently offer, we are always looking for feedback!
@dinmukhamedm Thanks a lot for the guidance, so for my use case we are associating session with traces and hence we are looking for query the traces for a particular session, afaik i see an endpoint to get all sessions which is reading sessions from database but in our case we need something like GET /sessions/:sessionId which returns us all the traces of a particular session as we would like to use it in our dashboard for our app. Do you think it makes sense here?
@Mohit21GoJs I get what you mean. This data can be queried from Postgres. It would essentially be something (roughly) like:
SELECT * FROM traces
-- optionally JOIN spans ON spans.trace_id = traces.id
WHERE session_id = '<YOUR_SESSION_ID>'
The traces table is already indexed on session_id
with B-Tree index, so this query should be fast, though hash index may make a little bit more sense for this case.
I didn't quite get from your message though – is this something you would like to see in Laminar or something you would want to implement yourself using Laminar's data stores?
@dinmukhamedm Thanks for the solution. I believe the database query will work but in my opinion this is a feature that should be owned by lmnr app server as it is owning the database and if you believe this api can help laminar vision i can create a task and create a pull request.