-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Summary
When Google Search grounding is enabled via tools: [{ googleSearch: {} }], the @google/genai SDK returns groundingMetadata on the response containing search citations, source URIs, and confidence scores. The current Google GenAI instrumentation plugin does not capture this metadata in either the streaming aggregation or the span metadata, so grounding details are silently lost in traced spans.
Non-streaming calls pass through the raw response object as output, so groundingMetadata is incidentally preserved there — but it is never extracted into span metadata where it would be queryable, and it is completely lost in streaming.
What is missing
- Streaming aggregation (
js/src/instrumentation/plugins/google-genai-plugin.ts,aggregateGenerateContentChunks): Only extractscandidates,usageMetadata,text,functionCall,codeExecutionResult,executableCode, andthoughtfrom chunks.groundingMetadatais not accumulated or forwarded. - Metadata extraction (
extractMetadata): Only capturesmodel,config, andtoolsfrom the request params. Does not extractgroundingMetadatafrom the response. - Vendor SDK types (
js/src/vendor-sdk-types/google-genai.ts):GoogleGenAIGenerateContentResponsehas no explicitgroundingMetadatafield (only a catch-all[key: string]: unknown). - E2E tests: No scenario uses
googleSearchtool configuration or validates grounding metadata.
Upstream reference
- Google AI Gemini grounding docs: https://ai.google.dev/gemini-api/docs/grounding
groundingMetadataresponse fields include:searchEntryPoint— rendered content for the search widgetgroundingChunks— array of{ web: { uri, title } }source documentswebSearchQueries— the search queries the model issuedgroundingSupports— text segments with confidence scores and chunk indices
- Available on models like
gemini-2.0-flashandgemini-2.5-prowhen grounding is enabled.
Braintrust docs status
The Braintrust Google GenAI integration page documents generateContent and generateContentStream but does not mention grounding metadata (not_found).
Precedent in this repo
The Python SDK has an equivalent open issue: braintrustdata/braintrust-sdk-python#153.
Local files inspected
js/src/instrumentation/plugins/google-genai-plugin.ts— streaming aggregation and metadata extractionjs/src/instrumentation/plugins/google-genai-channels.ts— channel definitionsjs/src/vendor-sdk-types/google-genai.ts— response type definitionsjs/src/wrappers/google-genai.ts— wrapper proxye2e/scenarios/google-genai-instrumentation/scenario.impl.mjs— e2e test scenarios