Skip to content

Bug(instrumentation-cohere): chat() missing token usage and user message attributes #1035

Description

@KalinaKatrapelova

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:

  1. Instrument CohereClient and call client.chat()
  2. Inspect the resulting span and observe that gen_ai.usage.prompt_tokens, gen_ai.usage.completion_tokens, and llm.usage.total_tokens are missing
  3. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions