Skip to content

Commit 2a17d13

Browse files
committed
feat(plugins/googlai): restore debugTraces in v2 plugin migration
1 parent 1cbd3fb commit 2a17d13

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

js/plugins/googleai/src/gemini.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
} from 'genkit/model';
5959
import { downloadRequestMedia } from 'genkit/model/middleware';
6060
import { model } from 'genkit/plugin';
61+
import { runInNewSpan } from 'genkit/tracing';
6162
import { getApiKeyFromEnvVar, getGenkitClientHeader } from './common.js';
6263
import { handleCacheIfNeeded } from './context-caching';
6364
import { extractCacheConfig } from './context-caching/utils';
@@ -1426,8 +1427,30 @@ export function defineGoogleAIModel({
14261427
};
14271428
};
14281429

1429-
// TODO v2: no ai.registry available here; run without the debug span wrapper.
1430-
return await callGemini();
1430+
// If debugTraces is enabled, we wrap the actual model call with a span, add raw
1431+
// API params as input.
1432+
return debugTraces
1433+
? await runInNewSpan(
1434+
{
1435+
metadata: {
1436+
name: streamingRequested ? 'sendMessageStream' : 'sendMessage',
1437+
},
1438+
},
1439+
async (metadata) => {
1440+
metadata.input = {
1441+
sdk: '@google/generative-ai',
1442+
cache: cache,
1443+
model: genModel.model,
1444+
chatOptions: updatedChatRequest,
1445+
parts: msg.parts,
1446+
options,
1447+
};
1448+
const response = await callGemini();
1449+
metadata.output = response.custom;
1450+
return response;
1451+
}
1452+
)
1453+
: await callGemini();
14311454
}
14321455
);
14331456
}

0 commit comments

Comments
 (0)