fix(telemetry): emit Tool.execute span for MCP and plugin tools#25452
Merged
kitlangton merged 1 commit intodevfrom May 2, 2026
Merged
fix(telemetry): emit Tool.execute span for MCP and plugin tools#25452kitlangton merged 1 commit intodevfrom
kitlangton merged 1 commit intodevfrom
Conversation
MCP-served tools and plugin-defined tools were bypassing the Tool.execute span that wraps native tool runs. Native tools get the span via wrap() in tool/tool.ts, called from Tool.define(); MCP tools are constructed as AI SDK dynamicTools in mcp/index.ts and inserted via a parallel path in session/prompt.ts, and plugin tools are built in registry.ts fromPlugin() without going through Tool.define(). Verified against trace 33c8941c89094d50650c2b91e244c778: 28 ai.toolCall spans had only 24 Tool.execute children; the missing 4 were all MCP tools (sentry_*, exa_*). Cross-cutting telemetry filtering on operation=Tool.execute was silently dropping MCP and plugin traffic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sentry_*,exa_*, etc.) and plugin-defined tools were not emitting aTool.executespan. Only native tools built viaTool.define()got one, because the span lives insidewrap()intool/tool.ts.Effect.withSpan("Tool.execute", ...)to both bypassed paths, mirroring the attribute shape fromwrap():tool.name,tool.call_id,session.id,message.id.Evidence
Trace
33c8941c89094d50650c2b91e244c778had 28ai.toolCallspans and only 24Tool.executechildren. The 4 missing executions were exactly the MCP tools used in the session:sentry_search_issuessentry_find_organizationssentry_whoamiexa_web_search_exaNative tools (
bash,webfetch,glob,grep) all had matching pairs with the sametool.call_id.Permission.askfired 28 times (matchingai.toolCallcount), so MCP tools went through permission gating but skipped the execution wrapper specifically.Why it matters
ai.toolCallis observable.operation=Tool.executesilently excludes MCP and plugin traffic.Changes
packages/opencode/src/session/prompt.ts: wrap the MCPctx.ask+execute(args, opts)body withEffect.withSpan("Tool.execute", ...). Plugintool.execute.before/afterhooks remain outside the span, matching the native scope (wrap()covers decode + execute + truncate; thebefore/aftertriggers happen in the registry consumer).packages/opencode/src/tool/registry.ts: pipefromPlugin()'sEffect.genbody through the samewithSpanso user-defined tool files and plugin-supplied tools also emit the span.Verification
bun typecheck(packages/opencode): passesbun run test test/tool/registry.test.ts test/tool/tool-define.test.ts: 7/7 pass