OpenTelemetry, Activity.Current and a missing TraceId #1208
-
|
If I Invoke an agent with a question, that question along with all the tool definitions will be sent in an http request to the LLM. The LLM will respond with a tool call, which the agent framework will execute (a local function). The result of that tool call will be sent back to the LLM in a second http request. When I log the first http request it will have Activity.Current != null. So all logs will have a TraceId. But all invoked code after the response from the LLM will have Where did I lose the context? I'm trying to get a single TraceId for the entire conversation so that I can get a trace of all logs. I also think I might have gotten a bit lost when trying to add open telemetry. There must be an easier way right? 😅 Or don't I need to call |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It depends on what you want. The tracing at the IChatClient level and at the AIAgent level are each capable of tracing almost identical information, just to differently named activity sources, and with differently named spans, as the genai convention calls it "chat" for inference and "invoke_agent" for agents. However, the one at the agent level is sitting around the IChatClient, so it won't be privvy to the back and forth issued by the function invocation in the IChatClient pipeline. As such, at the agent level, you'll see a single request/response, whereas at the IChatClient level, you'll see each request that gets made.
Can you share a minimal repro for what you're seeing and what you expect to see? |
Beta Was this translation helpful? Give feedback.
It depends on what you want. The tracing at the IChatClient level and at the AIAgent level are each capable of tracing almost identical information, just to differently named activity sources, and with differently named spans, as the genai convention calls it "chat" for inference and "invoke_agent" for agents. However, the one at the agent level is sitting around the IChatClient, so it won't be privvy to the back and forth issued by the function invocation in the IChatClient pipeline. As such, at the agent level, you'll see a single request/response, whereas at the IChatClient level, you'll see each request …