Skip to content

[bot] Google GenAI generateImages (Imagen) not instrumented in Go SDK #157

@braintrust-bot

Description

@braintrust-bot

What instrumentation is missing

The Google GenAI Go SDK (google.golang.org/genai v1.41.0) exposes an image generation API via client.Models.GenerateImages() (Imagen models). The genai HTTP router in trace/contrib/genai/tracegenai.go only matches four path patterns:

func containsGenerateContent(path string) bool {
    return strings.Contains(path, ":generateContent") ||
        strings.Contains(path, "/generateContent") ||
        strings.Contains(path, ":streamGenerateContent") ||
        strings.Contains(path, "/streamGenerateContent")
}

func containsEmbedContent(path string) bool {
    return strings.Contains(path, ":embedContent") ||
        strings.Contains(path, "/embedContent") ||
        strings.Contains(path, ":batchEmbedContents") ||
        strings.Contains(path, "/batchEmbedContents")
}

The Imagen API uses the :predict method suffix:

POST https://generativelanguage.googleapis.com/v1beta/models/imagen-4.0-generate-001:predict

This path contains neither :generateContent nor :embedContent variants, so genaiRouter returns nil and all GenerateImages calls are untraced.

Go SDK usage

result, err := client.Models.GenerateImages(ctx,
    "imagen-4.0-generate-001",
    "A photorealistic image of a cat",
    &genai.GenerateImagesConfig{NumberOfImages: 1},
)

What could be traced

A dedicated generateImagesTracer (similar to the existing generateContentTracer and embedContentTracer) matching :predict paths on Imagen model IDs could capture:

  • braintrust.input_json: {"model": "imagen-4.0-generate-001", "prompt": "...", "config": {...}}
  • braintrust.output_json: image output summary — e.g. {"images_count": 1, "mime_type": "image/png"} (raw pixel bytes omitted, matching the embeddingsOutputSummary convention of not logging raw vectors)
  • braintrust.metadata: model, numberOfImages, aspectRatio, safetyFilterLevel, outputOptions

Note: the :predict path is also shared by Imagen's EditImage and UpscaleImage methods; the model ID in the path (e.g. imagen-4.0-generate-001 vs imagegeneration@006) distinguishes them.

Braintrust docs status

supported (Python only) — the Braintrust Gemini integration docs include this in the operations table:

"generate_images and async generate_images | Image generation calls, with generated image output captured in the span output. Python only."

This confirms generate_images tracing is an intended Braintrust capability for the GenAI SDK; Go is currently the only unsupported runtime.

Source: https://www.braintrust.dev/docs/integrations/ai-providers/gemini

Upstream sources

Local repo files inspected

  • trace/contrib/genai/tracegenai.gogenaiRouter and path-matching helpers (containsGenerateContent, containsEmbedContent): no :predict case
  • trace/contrib/genai/generatecontent.go — reference pattern for request parsing and response instrumentation
  • trace/contrib/genai/embedcontent.go — reference pattern for output summary (shape-only, no raw vectors)
  • trace/contrib/genai/go.modgoogle.golang.org/genai v1.41.0 (Models.GenerateImages available in this version)
  • trace/contrib/genai/tracegenai_test.go — no tests for :predict / Imagen paths
  • examples/internal/genai/main.go — no GenerateImages example

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions