Skip to content

Commit 7542e93

Browse files
bryanatkinsonhendrixmar
authored andcommitted
fix(js/plugins/google-cloud): Add missing role field to structured input and output logs from GCP plugin (#3093)
1 parent ef4d891 commit 7542e93

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

js/plugins/google-cloud/src/telemetry/generate.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ class GenerateTelemetry implements Telemetry {
260260
logger.logStructured(`Input[${path}, ${model}] ${partCounts}`, {
261261
...sharedMetadata,
262262
content: this.toPartLogContent(part),
263+
role: msg.role,
263264
partIndex: partIdx,
264265
totalParts: parts,
265266
messageIndex: msgIdx,
@@ -302,6 +303,7 @@ class GenerateTelemetry implements Telemetry {
302303
...initial,
303304
...sharedMetadata,
304305
content: this.toPartLogContent(part),
306+
role: message.role,
305307
partIndex: partIdx,
306308
totalParts: parts,
307309
candidateIndex: 0,

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe('GoogleCloudLogs', () => {
296296
const testModel = createModel(ai, 'testModel', async () => {
297297
return {
298298
message: {
299-
role: 'user',
299+
role: 'model',
300300
content: [
301301
{
302302
text: 'response',
@@ -336,6 +336,7 @@ describe('GoogleCloudLogs', () => {
336336
await getExportedSpans();
337337

338338
const logs = await getLogs(1, 100, logLines);
339+
expect(logs.length).toEqual(8);
339340
const logObjectMessages = getStructuredLogMessages(logs);
340341
expect(logObjectMessages).toContain(
341342
'Config[testFlow > sub1 > sub2 > generate > testModel, testModel]'
@@ -348,6 +349,22 @@ describe('GoogleCloudLogs', () => {
348349
);
349350
expect(logObjectMessages).toContain('Input[testFlow, testFlow]');
350351
expect(logObjectMessages).toContain('Output[testFlow, testFlow]');
352+
// Ensure the model input/output has an associated role
353+
logs.map((log) => {
354+
const structuredLog = JSON.parse(log as string);
355+
if (
356+
structuredLog.message ===
357+
'Input[testFlow > sub1 > sub2 > generate > testModel, testModel] '
358+
) {
359+
expect(structuredLog.role).toBe('user');
360+
}
361+
if (
362+
structuredLog.message ===
363+
'Output[testFlow > sub1 > sub2 > generate > testModel, testModel]'
364+
) {
365+
expect(structuredLog.role).toBe('model');
366+
}
367+
});
351368
});
352369

353370
it('writes user feedback log', async () => {

0 commit comments

Comments
 (0)