跳到正文
DEV Community· Zhongkai Fu·· 49 分鐘前AI 評分50

為何 Application Insights 的 GenAI trace 有資料,卻看不到提示詞?

Why our GenAI traces had data but showed no prompts in Application Insights

AI 導讀

Application Insights 的 GenAI trace 雖已記錄 gen_ai.input.messages 和 gen_ai.output.messages,但若匯出器把訊息寫成頂層 content 欄位,而檢視器只讀取 typed parts,輸入與輸出頁籤便會空白。

正文

Zhongkai Fu

A TensorSharp contributor noticed a strange mismatch: Application Insights showed gen_ai.input.messages and gen_ai.output.messages under Metadata, but the Input + Output tab was empty. The model had answered and the span had arrived. Why couldn’t the viewer show the conversation?

The exporter was writing each message with a top-level content field. The GenAI viewer looked for typed parts. 1w2w3y sent two otherwise identical chat spans to the same Application Insights resource. The flat form left the tab empty; the parts form rendered the system message, user message, and answer.

{"role":"user","content":"Hello"}
{"role":"user","parts":[{"type":"text","content":"Hello"}]}

The fix also models assistant calls as tool_call parts and tool results as tool_call_response parts. That matters when you’re debugging an agent: you can see whether the model made the wrong call, the tool returned an unexpected result, or the final answer misread a good result. In the contributor’s follow-up check, Application Insights rendered the full tool round trip.

My debugging checklist now: check that the span arrived, inspect the shape of the recorded attributes, then confirm the viewer renders one text-only request and one tool round trip. A permissive JSON schema can accept an extra field without the viewer doing anything with it. And use synthetic data for this check: prompt and tool payloads can contain sensitive information, so I wouldn’t enable content capture broadly just to debug a trace.

TensorSharp fix and reproduction · OpenTelemetry GenAI attributes

Disclosure: This article was drafted by an AI assistant. The reproduction and fix are documented in the linked PR.

來源:DEV Community · dev.to