Skip to content

Commit b947281

Browse files
authored
fix(core): Flatten gen_ai.request.available_tools in google-genai (#18194)
While investigating [this ticket](https://linear.app/getsentry/issue/JS-657/available-tools-json-should-be-a-stringified-json-array-of-objects-not) I noticed that available tools are sent as a nested instead of a flat array in google genai, which seems like a bug to me. The format I would expect and how we do it in other integrations is: [{tool-definition}, {tool-definition}] What we actually send atm is: [[{tool-definition}], [{tool-definition}]] This PR fixes this to instead send a flat list of tool definitions.
1 parent c8ca286 commit b947281

File tree

2 files changed

+6
-3
lines changed
  • dev-packages/node-integration-tests/suites/tracing/google-genai
  • packages/core/src/tracing/google-genai

2 files changed

+6
-3
lines changed

dev-packages/node-integration-tests/suites/tracing/google-genai/test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ describe('Google GenAI integration', () => {
204204
});
205205
});
206206

207+
const EXPECTED_AVAILABLE_TOOLS_JSON =
208+
'[{"name":"controlLight","parametersJsonSchema":{"type":"object","properties":{"brightness":{"type":"number"},"colorTemperature":{"type":"string"}},"required":["brightness","colorTemperature"]}}]';
209+
207210
const EXPECTED_TRANSACTION_TOOLS = {
208211
transaction: 'main',
209212
spans: expect.arrayContaining([
@@ -215,7 +218,7 @@ describe('Google GenAI integration', () => {
215218
'sentry.origin': 'auto.ai.google_genai',
216219
'gen_ai.system': 'google_genai',
217220
'gen_ai.request.model': 'gemini-2.0-flash-001',
218-
'gen_ai.request.available_tools': expect.any(String), // Should include tools
221+
'gen_ai.request.available_tools': EXPECTED_AVAILABLE_TOOLS_JSON,
219222
'gen_ai.request.messages': expect.any(String), // Should include contents
220223
'gen_ai.response.text': expect.any(String), // Should include response text
221224
'gen_ai.response.tool_calls': expect.any(String), // Should include tool calls
@@ -236,7 +239,7 @@ describe('Google GenAI integration', () => {
236239
'sentry.origin': 'auto.ai.google_genai',
237240
'gen_ai.system': 'google_genai',
238241
'gen_ai.request.model': 'gemini-2.0-flash-001',
239-
'gen_ai.request.available_tools': expect.any(String), // Should include tools
242+
'gen_ai.request.available_tools': EXPECTED_AVAILABLE_TOOLS_JSON,
240243
'gen_ai.request.messages': expect.any(String), // Should include contents
241244
'gen_ai.response.streaming': true,
242245
'gen_ai.response.text': expect.any(String), // Should include response text

packages/core/src/tracing/google-genai/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function extractRequestAttributes(
115115

116116
// Extract available tools from config
117117
if ('tools' in config && Array.isArray(config.tools)) {
118-
const functionDeclarations = config.tools.map(
118+
const functionDeclarations = config.tools.flatMap(
119119
(tool: { functionDeclarations: unknown[] }) => tool.functionDeclarations,
120120
);
121121
attributes[GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE] = JSON.stringify(functionDeclarations);

0 commit comments

Comments
 (0)