Skip to content

[BOT ISSUE] Gemini integration does not capture ThinkingConfig or map thoughtsTokenCount metric #51

@braintrust-bot

Description

@braintrust-bot

Summary

The Gemini (genai) integration does not capture the ThinkingConfig request parameter in span metadata, and does not map the thoughtsTokenCount response metric to a standard metric name. Thinking/reasoning is an official, documented Gemini 2.5+ feature that is already used within this repo's ADK integration tests.

What is missing

1. ThinkingConfig not captured from request

In trace/contrib/genai/generatecontent.go (lines 48–81), the metadata and generation config fields are explicitly listed:

metadataFields := []string{
    "model", "systemInstruction", "tools", "toolConfig", "safetySettings", "cachedContent",
}
// ...
configFields := []string{
    "temperature", "topP", "topK", "candidateCount", "maxOutputTokens",
    "stopSequences", "responseMimeType", "responseSchema",
}

thinkingConfig is absent from both lists. When a user sets ThinkingConfig with IncludeThoughts, ThinkingBudget, or ThinkingLevel, these parameters are silently dropped from the span metadata. Other comparable generation parameters (temperature, topP, maxOutputTokens) are all captured.

2. thoughtsTokenCount not mapped to a standard metric name

In parseUsageTokens (lines 167–196), four Gemini token fields are explicitly mapped:

Gemini field Mapped metric
promptTokenCount prompt_tokens
candidatesTokenCount completion_tokens
totalTokenCount tokens
cachedContentTokenCount prompt_cached_tokens

thoughtsTokenCount falls through to the default case and gets converted to thoughts_token_count via camelToSnake. While technically captured, it is not mapped to a recognizable standard metric name (e.g., completion_reasoning_tokens as used by the OpenAI integration for similar reasoning token tracking).

3. This repo already uses ThinkingConfig

The ADK integration tests in trace/contrib/adk/golden_test.go (lines 562–569) already exercise ThinkingConfig:

ThinkingConfig: &genai.ThinkingConfig{
    IncludeThoughts: true,
    ThinkingBudget:  &thinkingBudget,
},

This confirms the feature is actively used with Gemini models in this SDK's ecosystem.

Braintrust docs status

Extended thinking / reasoning token tracking is not explicitly documented in Braintrust docs. The OpenAI integration in this SDK captures completion_reasoning_tokens for reasoning models. Status: unclear (no explicit Braintrust docs for Gemini thinking tokens, but analogous OpenAI reasoning tokens are captured).

Upstream sources

  • Gemini thinking docs: https://ai.google.dev/gemini-api/docs/thinking
  • Supported on Gemini 2.5 (Flash, Pro, Flash-Lite) and Gemini 3 series
  • ThinkingConfig fields: IncludeThoughts (bool), ThinkingBudget (int32), ThinkingLevel (string)
  • Response usageMetadata includes thoughtsTokenCount for reasoning token usage

Braintrust docs sources

Local repo files inspected

  • trace/contrib/genai/generatecontent.go — metadata field lists and parseUsageTokens
  • trace/contrib/openai/traceopenai.goparseUsageTokens maps completion_reasoning_tokens (precedent)
  • trace/contrib/adk/golden_test.go — ThinkingConfig already in use
  • trace/contrib/genai/tracegenai_test.go — no thinking-related tests

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions