-
Notifications
You must be signed in to change notification settings - Fork 3
[BOT ISSUE] Anthropic server_tool_use usage metrics silently dropped from span metrics #1728
Description
Summary
When Anthropic server-side tools (e.g., web search) are used, the API response includes a server_tool_use object in the usage field containing metrics like web_search_requests. The Anthropic instrumentation plugin's parseMetricsFromUsage function uses an explicit allowlist of four numeric fields and silently drops server_tool_use — both because it is not listed and because it is a nested object, not a number.
What instrumentation is missing
Metric extraction (js/src/instrumentation/plugins/anthropic-plugin.ts, lines 106–128): parseMetricsFromUsage explicitly enumerates exactly four fields:
saveIfExistsTo("input_tokens", "prompt_tokens");
saveIfExistsTo("output_tokens", "completion_tokens");
saveIfExistsTo("cache_read_input_tokens", "prompt_cached_tokens");
saveIfExistsTo("cache_creation_input_tokens", "prompt_cache_creation_tokens");The saveIfExistsTo helper (line 117) also has a typeof value === "number" guard, which would reject server_tool_use even if it were accessed, since its value is a nested object like { "web_search_requests": 3 }.
Vendor SDK types (js/src/vendor-sdk-types/anthropic.ts, lines 101–106): The AnthropicUsage type only declares input_tokens, output_tokens, cache_read_input_tokens, and cache_creation_input_tokens. There is no server_tool_use field and no index signature for pass-through of unknown fields.
Impact
Users who enable Anthropic server-side tools (web search, code execution) cannot see server tool usage metrics in their Braintrust spans. This makes it impossible to track web search request counts or other server tool usage for cost analysis or debugging.
Braintrust docs status
not_found — The Braintrust docs at https://www.braintrust.dev/docs/instrument/wrap-providers do not mention Anthropic server tool usage metrics.
Upstream reference
- Anthropic server-side tools documentation: https://docs.anthropic.com/en/docs/build-with-claude/tool-use/server-tools
- The
usageobject in API responses includesserver_tool_use: { web_search_requests: N }when server tools are used. - This is a stable, GA feature — web search is one of the primary server tools.
- Equivalent Python SDK gap: Anthropic: usage metrics extraction silently drops
server_tool_use,cache_creationbreakdown, and other new API fields braintrust-sdk-python#164 - Equivalent Ruby SDK gap: [BOT ISSUE] Anthropic server_tool_use usage metrics silently dropped braintrust-sdk-ruby#137
Local files inspected
js/src/instrumentation/plugins/anthropic-plugin.ts— lines 106–128:parseMetricsFromUsagefunctionjs/src/vendor-sdk-types/anthropic.ts— lines 101–106:AnthropicUsagetypejs/src/instrumentation/plugins/anthropic-channels.ts— channel definitionsjs/src/wrappers/anthropic.ts— wrapper proxy