Make a Langfuse trace worth opening: question, answer, session, no probe noise

This commit is contained in:
2026-08-21 14:45:32 +07:00
parent 53582b6030
commit f3eaab0948
16 changed files with 733 additions and 5 deletions
+22
View File
@@ -191,6 +191,28 @@ class PostgresTraceRepository:
raise FeedbackTraceNotFound(trace_id)
return str(row[0])
def otel_trace_id_for(self, trace_id: str) -> str | None:
"""The OpenTelemetry id of a persisted answer, for attaching a score.
Separate from `save_feedback` rather than folded into its RETURNING
clause: that method's `-> str` shape is part of the `TraceWriter`
protocol the router depends on, and widening it to carry an unrelated
id would make every implementation and test carry it too. Feedback is
rare enough that a second short query costs nothing.
None when the row has no OTel id -- true for every answer produced
while tracing was off, which is most of the history predating
2026-08-21. Callers skip posting rather than inventing one.
"""
import psycopg
with psycopg.connect(self._dsn, connect_timeout=5) as connection:
row = connection.execute(
"SELECT otel_trace_id FROM rag_retrieval_trace WHERE trace_id = %s",
(trace_id,),
).fetchone()
return str(row[0]) if row and row[0] else None
class PostgresConversationStore:
"""Durable, cross-worker replacement for `RagAgent`'s in-process