The client.chat() instrumentation has two issues where span attributes are silently dropped.
1. Token usage attributes never recorded
After calling client.chat(), the following span attributes are always absent:
gen_ai.usage.prompt_tokens
gen_ai.usage.completion_tokens
llm.usage.total_tokens
2. User message recorded under wrong attribute key
The current user message (params.message) is stored under gen_ai.prompt.N.user, while all chat history messages are stored under gen_ai.prompt.N.content. Consumers reading .content will see the conversation history but miss the user turn that triggered the request.
Steps to reproduce:
- Instrument
CohereClient and call client.chat()
- Inspect the resulting span and observe that
gen_ai.usage.prompt_tokens, gen_ai.usage.completion_tokens, and llm.usage.total_tokens are missing
- Observe that the user message appears under
gen_ai.prompt.0.user instead of gen_ai.prompt.0.content
Environment:
cohere-ai: current SDK (v2 response shape — NonStreamedChatResponse)
@traceloop/instrumentation-cohere: latest
The
client.chat()instrumentation has two issues where span attributes are silently dropped.1. Token usage attributes never recorded
After calling
client.chat(), the following span attributes are always absent:gen_ai.usage.prompt_tokensgen_ai.usage.completion_tokensllm.usage.total_tokens2. User message recorded under wrong attribute key
The current user message (
params.message) is stored undergen_ai.prompt.N.user, while all chat history messages are stored undergen_ai.prompt.N.content. Consumers reading.contentwill see the conversation history but miss the user turn that triggered the request.Steps to reproduce:
CohereClientand callclient.chat()gen_ai.usage.prompt_tokens,gen_ai.usage.completion_tokens, andllm.usage.total_tokensare missinggen_ai.prompt.0.userinstead ofgen_ai.prompt.0.contentEnvironment:
cohere-ai: current SDK (v2 response shape —NonStreamedChatResponse)@traceloop/instrumentation-cohere: latest