Tool calls produce no span and the kubectl subprocess drops trace context
维护者通常 5 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- go, kubernetes
调研方向
Start with cmd/main.go, internal/telemetry/middleware.go, and pkg/k8s/k8s.go; trace how the HTTP handler extracts context and how runKubectlCommand starts the subprocess. First add or locate tests for incoming traceparent propagation and tool-call span creation. Done means failed and successful tool calls have the expected spans; carrying context through Kubernetes API requests may require replacing kubectl with client-go.
由索引模型根据 Issue 内容生成。
描述
Summary
With tracing enabled, an MCP tool call to kagent-tools doesn't show up in the caller's trace. The server extracts the incoming W3C traceparent, but it never starts a span for the request or the tool call. The k8s tools then run kubectl as a subprocess, which receives no trace context, so the Kubernetes API requests behind the call can't join the trace either.
We see this as an agent turn whose trace ends at the gateway's MCP hop: the tool call itself, and everything it did against the API server, is invisible.
Where (v0.3.1)
cmd/main.go: the HTTP handler is wrapped only intelemetry.HTTPMiddleware. There's nootelhttphandler and no other server span.internal/telemetry/middleware.goHTTPMiddleware: it callspropagator.Extract(...)and stores the trace and span IDs in the context, but starts no span. Its own comment saysExtractTraceInfohas no non-test callers since the Go SDK migration (#66).pkg/k8s/k8s.gorunKubectlCommand/runKubectlCommandWithTimeout: these runkubectlthroughcommands.NewCommandBuilder("kubectl"). The child process gets notraceparent, and kubectl has no way to send one.
The only spans in a tool call's context are the cache.* spans.
Expected
- A server span per MCP request (or per
tools/call), a child of the incomingtraceparent, named for the tool (for exampletools/call k8s_get_resources), with the tool name and an error status on failure. - Ideally, the Kubernetes API requests the tool makes are children of that span, so API-server tracing (
APIServerTracing) links up with the agent's trace.
Possible fixes
- Wrap the MCP handler in
otelhttp.NewHandler(or start a span inHTTPMiddleware), and start a child span per tool call in the handlers. That alone makes tool calls visible in the caller's trace. - For the Kubernetes requests: use client-go in-process for the read verbs, with an
otelhttptransport, instead of akubectlsubprocess. Thentraceparentreaches the API server. A subprocess can't carry it, because kubectl doesn't read trace context from its environment or flags.
Happy to help test a change.
- 主要语言
- Go
- 星标
- 39
- 派生
- 35
- 平均合并
- 4 天 10 小时
- 30 天内合并 PR
- 8
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
kagent-dev/tools 的其他 Issue
-
LLM-backed tools are registered without an LLM可能已有人在做 @ntmspavan 于 7 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 67/100
kagent-dev/tools#93 · 1 条评论 ·
维护者通常 5 天内回复
-
Helm chart sets env vars the server never reads可能已有人在做 @lbarrosby 于 11 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 67/100
kagent-dev/tools#92 ·
维护者通常 5 天内回复
-
[BUG] Failed commands return only "exit status 1"; the command's error never reaches the agent可能已有人在做 @sathpal 于 34 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 69/100
kagent-dev/tools#89 ·
维护者通常 5 天内回复
-
[BUG] MCP clients get no tools from v0.3.0: kubescape_get_vulnerability_details outputSchema is not an object可能重新可做 @nishanthchandr4 于 48 天前认领,目前没有进行中的 PR。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
kagent-dev/tools#87 · 2 条评论 ·
维护者通常 5 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 25/100
kagent-dev/tools#105 ·
维护者通常 5 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
Add CybeDefend未关闭
难度 1/5 1 小时以内 新手友好度 66/100
slavakurilyak/awesome-ai-agents#1031 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
kagent-dev/kagent#3792 ·
维护者通常 1 天内回复
-
ai-driven-qa bug claude Minor
难度 2/5 1-3 小时 新手友好度 68/100
linagora/cozy-stack#5374 ·
维护者通常 1 天内回复
-
new-compilers request
难度 2/5 1-3 小时 新手友好度 65/100
compiler-explorer/compiler-explorer#9640 ·
维护者通常 1 天内回复