add(OTel): Add OTel logging for MalformedJsonEvent (#6912)

Co-authored-by: Shnatu <snatu@google.com>
Co-authored-by: cornmander <shikhman@google.com>
This commit is contained in:
Shardul Natu
2025-08-24 19:11:41 -07:00
committed by GitHub
parent bedd1d2c20
commit 1918f4466b
5 changed files with 62 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ import {
EVENT_TOOL_CALL,
EVENT_USER_PROMPT,
EVENT_FLASH_FALLBACK,
EVENT_MALFORMED_JSON_RESPONSE,
} from './constants.js';
import {
logApiRequest,
@@ -35,6 +36,7 @@ import {
logToolCall,
logFlashFallback,
logChatCompression,
logMalformedJsonResponse,
} from './loggers.js';
import { ToolCallDecision } from './tool-call-decision.js';
import {
@@ -44,6 +46,7 @@ import {
ToolCallEvent,
UserPromptEvent,
FlashFallbackEvent,
MalformedJsonResponseEvent,
makeChatCompressionEvent,
} from './types.js';
import * as metrics from './metrics.js';
@@ -818,4 +821,31 @@ describe('loggers', () => {
});
});
});
describe('logMalformedJsonResponse', () => {
beforeEach(() => {
vi.spyOn(ClearcutLogger.prototype, 'logMalformedJsonResponseEvent');
});
it('logs the event to Clearcut and OTEL', () => {
const mockConfig = makeFakeConfig();
const event = new MalformedJsonResponseEvent('test-model');
logMalformedJsonResponse(mockConfig, event);
expect(
ClearcutLogger.prototype.logMalformedJsonResponseEvent,
).toHaveBeenCalledWith(event);
expect(mockLogger.emit).toHaveBeenCalledWith({
body: 'Malformed JSON response from test-model.',
attributes: {
'session.id': 'test-session-id',
'event.name': EVENT_MALFORMED_JSON_RESPONSE,
'event.timestamp': '2025-01-01T00:00:00.000Z',
model: 'test-model',
},
});
});
});
});