Skip to content

[bot] Google GenAI generateImages spans missing prompt input and use wrong span type #121

@braintrust-bot

Description

@braintrust-bot

Summary

When client.models.generateImages() is called through the instrumented Google GenAI client, a span is created (the call goes through ApiClient.request()), but the span contains no useful input data. The tagSpan() method in BraintrustApiClient only extracts fields specific to generateContent (contents, generationConfig, usageMetadata), which are absent from image generation requests and responses.

The result:

  • input_json only has {model: "..."} — the actual prompt text is not captured. This is the primary creative input and the most important thing to trace for image generation.
  • No metrics — image generation responses use response-level metadata (not usageMetadata), so no token or character counts are captured.
  • Wrong span type — hardcoded type: "llm" instead of something appropriate for image generation.

This is analogous to the embedContent gap tracked in #65, where calls are intercepted at HTTP level but parsed with the wrong field schema.

Braintrust already documents and traces generate_images for the Python SDK. The Java SDK makes the same API calls but the span tagging logic was never extended to handle them.

What is missing

BraintrustApiClient.tagSpan() (lines 50–161) handles only generateContent fields:

Request parsing (lines 97–113):

if (requestJson.containsKey("contents")) {          // generateContent field — not present in generateImages
    inputJson.put("contents", requestJson.get("contents"));
}
if (requestJson.containsKey("generationConfig")) {   // generateContent field — not present in generateImages
    inputJson.put("config", requestJson.get("generationConfig"));
}

A generateImages request body looks like:

{
  "prompt": "A photorealistic cat sitting on a moon",
  "config": {
    "numberOfImages": 2,
    "aspectRatio": "16:9",
    "negativePrompt": "blurry, low quality"
  }
}

Neither prompt nor config.numberOfImages/config.aspectRatio are extracted. The input_json stored in the span ends up as {model: "imagen-3.0-generate-001"} only — the prompt is silently dropped.

Response parsing (lines 116–149):

if (responseJson.get("usageMetadata") instanceof Map) {   // not present in generateImages responses
    ...
}

generateImages responses return generatedImages[].image.imageBytes (base64) and generatedImages[].generationParameters. No usageMetadata is present, so the metrics block is empty.

Span attributes (line 156):

span.setAttribute("braintrust.span_attributes", toJson(Map.of("type", "llm")));

Image generation is not an LLM call. Braintrust's Python tracer uses a different span categorization for image generation spans.

Braintrust docs status

Upstream sources

  • Google GenAI Java SDK generateImages: client.models.generateImages(String model, String prompt, GenerateImagesConfig config) — stable API, available in genai-java v1.18.0 (the version this module targets)
  • Imagen API reference: https://ai.google.dev/api/generate-images — documents prompt, config (numberOfImages, aspectRatio, negativePrompt, safetyFilterLevel, personGeneration), and generatedImages response format
  • Braintrust Python tracing: generate_images and async variants are explicitly listed as traced surfaces at https://www.braintrust.dev/docs/integrations/ai-providers/gemini

Local files inspected

  • braintrust-sdk/instrumentation/genai_1_18_0/src/main/java/com/google/genai/BraintrustApiClient.java — lines 97–113 (tagSpan input parsing: only contents/generationConfig extracted; prompt field absent); lines 116–149 (response parsing: only usageMetadata checked; missing for image responses); line 156 (hardcoded type: "llm")
  • braintrust-sdk/instrumentation/genai_1_18_0/src/test/java/dev/braintrust/instrumentation/genai/v1_18_0/BraintrustGenAITest.java — no generateImages test exists

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions