Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#121 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
java
领域
observability

调研方向

从 braintrust-sdk/instrumentation/genai_1_18_0/src/main/java/com/google/genai/BraintrustApiClient.java 开始,重点查看第 97–161 行的 tagSpan,并检查 BraintrustGenAITest.java 中现有的 span 断言。为 generateImages 请求和响应的解析添加测试覆盖,包括 prompt、图像生成元数据以及适当的 span 分类;完成标准是测试能够验证这些值已被捕获,而不是当前仅支持 generateContent 的行为。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Java
星标
21
派生
5
平均合并
1 天 20 小时
30 天内合并 PR
8

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

braintrustdata/braintrust-sdk-java 的其他 Issue

查看 braintrustdata/braintrust-sdk-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。