WeKnora/internal/handler/session
wizardchen 55caeefc3d feat(observability): log end-to-end TTFB on both ends of chat stream
To diagnose where latency lives between "user hits send" and "first
token appears" we need a single number that can be matched across
the browser console and the server log. Add correlated TTFB markers
keyed by X-Request-ID:

Frontend (streame.ts)

* Generate the X-Request-ID once and reuse it for logging.
* Log request:start when fetchEventSource is invoked, response:headers
  when onopen fires, and response:first_answer the first time an SSE
  payload with response_type === 'answer' arrives. Filtering by event
  type avoids treating session_title / references / tool_call as the
  "first token".

Backend (session handler)

* parseQARequest records the wall-clock entry time and logs TTFB:start
  with the same X-Request-ID.
* qaRequestContext carries receivedAt through to the stream handler.
* AgentStreamHandler emits a one-shot TTFB:first_answer_chunk log the
  first time it observes an AgentFinalAnswerData chunk, so the delta
  against TTFB:start is the server's request-in → first-token-out
  budget.

The frontend delta minus the backend delta is then attributable to
network + gin middleware, which were previously invisible.
2026-05-12 21:16:37 +08:00
..
agent_stream_handler.go feat(observability): log end-to-end TTFB on both ends of chat stream 2026-05-12 21:16:37 +08:00
attachment_processor.go fix:attachment_document_failed 2026-04-29 22:34:13 +08:00
handler.go refactor(agent): rebuild multi-turn history from DB, drop llmcontext layer 2026-05-12 12:26:24 +08:00
helpers.go feat(observability): log end-to-end TTFB on both ends of chat stream 2026-05-12 21:16:37 +08:00
image_upload.go feat(video): update ASR terminology and file type labels for improved clarity 2026-04-14 22:59:14 +08:00
qa.go feat(observability): log end-to-end TTFB on both ends of chat stream 2026-05-12 21:16:37 +08:00
stream.go docs(api): add and fix swag annotations on handlers 2026-05-12 13:16:58 +08:00
title.go feat: 支持知识库选择模式和标题生成模型配置 2025-12-29 14:35:13 +08:00
types.go feat: attachment_support 2026-04-10 12:49:20 +08:00