File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ import {
58
58
} from 'genkit/model' ;
59
59
import { downloadRequestMedia } from 'genkit/model/middleware' ;
60
60
import { model } from 'genkit/plugin' ;
61
+ import { runInNewSpan } from 'genkit/tracing' ;
61
62
import { getApiKeyFromEnvVar , getGenkitClientHeader } from './common.js' ;
62
63
import { handleCacheIfNeeded } from './context-caching' ;
63
64
import { extractCacheConfig } from './context-caching/utils' ;
@@ -1426,8 +1427,30 @@ export function defineGoogleAIModel({
1426
1427
} ;
1427
1428
} ;
1428
1429
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 ( ) ;
1431
1454
}
1432
1455
) ;
1433
1456
}
You can’t perform that action at this time.
0 commit comments