[bot] Google GenAI `generateImages` spans missing prompt input and use wrong span type
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 74/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- java
- Domain
- observability
Research direction
Start in braintrust-sdk/instrumentation/genai_1_18_0/src/main/java/com/google/genai/BraintrustApiClient.java, especially tagSpan lines 97–161, and review BraintrustGenAITest.java for existing span assertions. Add coverage for generateImages request and response parsing, including the prompt, image-generation metadata, and appropriate span categorization; done means the test verifies these values are captured instead of the current generateContent-only behavior.
Written by the indexing model from the issue text.
Description
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_jsononly 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
- Braintrust docs at https://www.braintrust.dev/docs/integrations/ai-providers/gemini document
generate_imagesas a traced surface for Python: supported - No mention of
generateImagesinstrumentation for Java: not_found
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), andgeneratedImagesresponse format - Braintrust Python tracing:
generate_imagesand 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 (tagSpaninput parsing: onlycontents/generationConfigextracted;promptfield absent); lines 116–149 (response parsing: onlyusageMetadatachecked; missing for image responses); line 156 (hardcodedtype: "llm")braintrust-sdk/instrumentation/genai_1_18_0/src/test/java/dev/braintrust/instrumentation/genai/v1_18_0/BraintrustGenAITest.java— nogenerateImagestest exists
- Dominant language
- Java
- Stars
- 21
- Forks
- 5
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from braintrustdata/braintrust-sdk-java
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
All issues in braintrustdata/braintrust-sdk-java
Similar issues
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
apache/flink-agents#1152 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
jenkinsci/blueocean-plugin#5417 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
objectionary/eo-graphs#75 ·