Skip to content

Commit dee5203

Browse files
committed
fix(js/plugins/google-cloud): Update tests
1 parent 7b383c5 commit dee5203

File tree

2 files changed

+86
-27
lines changed

2 files changed

+86
-27
lines changed

js/plugins/google-cloud/src/gcpOpenTelemetry.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -413,32 +413,33 @@ class AdjustingTraceExporter implements SpanExporter {
413413
pathsTelemetry.tick(span, paths, this.logInputAndOutput, this.projectId);
414414
// Set root status explicitly
415415
span.attributes['genkit:rootState'] = span.attributes['genkit:state'];
416-
}
417-
if (type === 'action' && subtype === 'model') {
418-
// Report generate metrics () for all model actions
419-
generateTelemetry.tick(
420-
span,
421-
unused,
422-
this.logInputAndOutput,
423-
this.projectId
424-
);
425-
}
426-
if (type === 'action' && subtype === 'tool') {
427-
// TODO: Report input and output for tool actions
428-
}
429-
if (
430-
type === 'action' ||
431-
type === 'flow' ||
432-
type == 'flowStep' ||
433-
type == 'util'
434-
) {
435-
// Report request and latency metrics for all actions
436-
actionTelemetry.tick(
437-
span,
438-
unused,
439-
this.logInputAndOutput,
440-
this.projectId
441-
);
416+
} else {
417+
if (type === 'action' && subtype === 'model') {
418+
// Report generate metrics () for all model actions
419+
generateTelemetry.tick(
420+
span,
421+
unused,
422+
this.logInputAndOutput,
423+
this.projectId
424+
);
425+
}
426+
if (type === 'action' && subtype === 'tool') {
427+
// TODO: Report input and output for tool actions
428+
}
429+
if (
430+
type === 'action' ||
431+
type === 'flow' ||
432+
type == 'flowStep' ||
433+
type == 'util'
434+
) {
435+
// Report request and latency metrics for all actions
436+
actionTelemetry.tick(
437+
span,
438+
unused,
439+
this.logInputAndOutput,
440+
this.projectId
441+
);
442+
}
442443
}
443444
if (type === 'userEngagement') {
444445
// Report user acceptance and feedback metrics

js/plugins/google-cloud/tests/logs_test.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ describe('GoogleCloudLogs', () => {
336336
await getExportedSpans();
337337

338338
const logs = await getLogs(1, 100, logLines);
339-
expect(logs.length).toEqual(8);
339+
expect(logs.length).toEqual(10);
340340
const logObjectMessages = getStructuredLogMessages(logs);
341341
expect(logObjectMessages).toContain(
342342
'Config[testFlow > sub1 > sub2 > generate > testModel, testModel]'
@@ -349,6 +349,12 @@ describe('GoogleCloudLogs', () => {
349349
);
350350
expect(logObjectMessages).toContain('Input[testFlow, testFlow]');
351351
expect(logObjectMessages).toContain('Output[testFlow, testFlow]');
352+
expect(logObjectMessages).toContain(
353+
'Input[testFlow > sub1 > sub2 > generate, testFlow]'
354+
);
355+
expect(logObjectMessages).toContain(
356+
'Output[testFlow > sub1 > sub2 > generate, testFlow]'
357+
);
352358
// Ensure the model input/output has an associated role
353359
logs.map((log) => {
354360
const structuredLog = JSON.parse(log as string);
@@ -367,6 +373,58 @@ describe('GoogleCloudLogs', () => {
367373
});
368374
});
369375

376+
it('writes feature logs for generate without flow', async () => {
377+
const testModel = createModel(ai, 'testModel', async () => {
378+
return {
379+
message: {
380+
role: 'model',
381+
content: [
382+
{
383+
text: 'response',
384+
},
385+
],
386+
},
387+
finishReason: 'stop',
388+
usage: {
389+
inputTokens: 10,
390+
outputTokens: 14,
391+
inputCharacters: 8,
392+
outputCharacters: 16,
393+
inputImages: 1,
394+
outputImages: 3,
395+
},
396+
};
397+
});
398+
399+
await ai.generate({
400+
model: testModel,
401+
prompt: `a test prompt`,
402+
config: {
403+
temperature: 1.0,
404+
topK: 3,
405+
topP: 5,
406+
maxOutputTokens: 7,
407+
},
408+
});
409+
410+
await getExportedSpans();
411+
412+
const logs = await getLogs(1, 100, logLines);
413+
expect(logs.length).toEqual(7);
414+
const logObjectMessages = getStructuredLogMessages(logs);
415+
expect(logObjectMessages).toContain(
416+
'Config[generate > testModel, testModel]'
417+
);
418+
expect(logObjectMessages).toContain(
419+
'Input[generate > testModel, testModel] '
420+
);
421+
expect(logObjectMessages).toContain(
422+
'Output[generate > testModel, testModel] '
423+
);
424+
expect(logObjectMessages).toContain('Input[generate, generate]');
425+
expect(logObjectMessages).toContain('Output[generate, generate]');
426+
});
427+
370428
it('writes user feedback log', async () => {
371429
await appendSpan(
372430
'trace1',

0 commit comments

Comments
 (0)