What instrumentation is missing
client.Messages.CountTokens() calls POST /v1/messages/count_tokens. The current anthropicRouter in trace/contrib/anthropic/traceanthropic.go only matches the exact path /v1/messages:
func anthropicRouter(cfg *middlewareConfig, path string) internal.MiddlewareTracer {
if path == "/v1/messages" {
return newMessagesTracer(cfg)
}
return nil
}
/v1/messages/count_tokens does not match, so every CountTokens() call is silently untraced — no span, no token metrics, no input metadata.
The endpoint accepts the same parameters as messages.New() (model, messages, system, tools, thinking, etc.) and returns {input_tokens, cache_creation_input_tokens, cache_read_input_tokens}. These map directly to the prompt_tokens, prompt_cache_creation_tokens, and prompt_cached_tokens metrics already parsed by parseUsageTokens() in trace/contrib/anthropic/traceanthropic.go. A dedicated countTokensTracer could emit a span with input metadata and token metrics but no output, analogous to how the embeddings tracer in trace/contrib/openai/embeddings.go omits the vector body.
Braintrust docs status
supported — Braintrust LLM spans already capture model, input, and token metrics for messages.New(); the count_tokens response provides the same token fields and can be recorded with the same span schema.
Source: https://www.braintrust.dev/docs
Upstream sources
- Anthropic API reference: https://docs.anthropic.com/en/api/messages-count-tokens
anthropic-sdk-go method: client.Messages.CountTokens(ctx, anthropic.MessageCountTokensParams{})
- SDK version in use:
github.com/anthropics/anthropic-sdk-go v1.23.0 (trace/contrib/anthropic/go.mod)
Local repo files inspected
trace/contrib/anthropic/traceanthropic.go — anthropicRouter (lines 104–110), parseUsageTokens
trace/contrib/anthropic/messages.go — existing messagesTracer
trace/contrib/anthropic/go.mod — SDK version
trace/contrib/openai/embeddings.go — pattern reference for token-only spans
What instrumentation is missing
client.Messages.CountTokens()callsPOST /v1/messages/count_tokens. The currentanthropicRouterintrace/contrib/anthropic/traceanthropic.goonly matches the exact path/v1/messages:/v1/messages/count_tokensdoes not match, so everyCountTokens()call is silently untraced — no span, no token metrics, no input metadata.The endpoint accepts the same parameters as
messages.New()(model, messages, system, tools, thinking, etc.) and returns{input_tokens, cache_creation_input_tokens, cache_read_input_tokens}. These map directly to theprompt_tokens,prompt_cache_creation_tokens, andprompt_cached_tokensmetrics already parsed byparseUsageTokens()intrace/contrib/anthropic/traceanthropic.go. A dedicatedcountTokensTracercould emit a span with input metadata and token metrics but no output, analogous to how the embeddings tracer intrace/contrib/openai/embeddings.goomits the vector body.Braintrust docs status
supported — Braintrust LLM spans already capture model, input, and token metrics for
messages.New(); the count_tokens response provides the same token fields and can be recorded with the same span schema.Source: https://www.braintrust.dev/docs
Upstream sources
anthropic-sdk-gomethod:client.Messages.CountTokens(ctx, anthropic.MessageCountTokensParams{})github.com/anthropics/anthropic-sdk-go v1.23.0(trace/contrib/anthropic/go.mod)Local repo files inspected
trace/contrib/anthropic/traceanthropic.go—anthropicRouter(lines 104–110),parseUsageTokenstrace/contrib/anthropic/messages.go— existingmessagesTracertrace/contrib/anthropic/go.mod— SDK versiontrace/contrib/openai/embeddings.go— pattern reference for token-only spans