@google/gemini-cli-core 0.10.0-nightly.20251009.cd354aeb → 0.10.0-nightly.20251010.558be873

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/src/config/config.d.ts +3 -0
  2. package/dist/src/config/config.js +5 -0
  3. package/dist/src/config/config.js.map +1 -1
  4. package/dist/src/config/config.test.js +22 -0
  5. package/dist/src/config/config.test.js.map +1 -1
  6. package/dist/src/core/client.d.ts +1 -1
  7. package/dist/src/core/client.js +16 -3
  8. package/dist/src/core/client.js.map +1 -1
  9. package/dist/src/core/client.test.js +85 -0
  10. package/dist/src/core/client.test.js.map +1 -1
  11. package/dist/src/core/turn.d.ts +6 -2
  12. package/dist/src/core/turn.js +6 -0
  13. package/dist/src/core/turn.js.map +1 -1
  14. package/dist/src/core/turn.test.js +13 -1
  15. package/dist/src/core/turn.test.js.map +1 -1
  16. package/dist/src/generated/git-commit.d.ts +2 -2
  17. package/dist/src/generated/git-commit.js +2 -2
  18. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +12 -4
  19. package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
  20. package/dist/src/telemetry/constants.d.ts +0 -34
  21. package/dist/src/telemetry/constants.js +0 -36
  22. package/dist/src/telemetry/constants.js.map +1 -1
  23. package/dist/src/telemetry/loggers.d.ts +1 -1
  24. package/dist/src/telemetry/loggers.js +83 -315
  25. package/dist/src/telemetry/loggers.js.map +1 -1
  26. package/dist/src/telemetry/loggers.test.js +5 -2
  27. package/dist/src/telemetry/loggers.test.js.map +1 -1
  28. package/dist/src/telemetry/metrics.d.ts +5 -1
  29. package/dist/src/telemetry/metrics.js +2 -1
  30. package/dist/src/telemetry/metrics.js.map +1 -1
  31. package/dist/src/telemetry/telemetryAttributes.d.ts +8 -0
  32. package/dist/src/telemetry/telemetryAttributes.js +15 -0
  33. package/dist/src/telemetry/telemetryAttributes.js.map +1 -0
  34. package/dist/src/telemetry/types.d.ts +100 -2
  35. package/dist/src/telemetry/types.js +570 -33
  36. package/dist/src/telemetry/types.js.map +1 -1
  37. package/dist/src/telemetry/uiTelemetry.d.ts +1 -1
  38. package/dist/src/telemetry/uiTelemetry.js +1 -1
  39. package/dist/src/telemetry/uiTelemetry.js.map +1 -1
  40. package/dist/src/telemetry/uiTelemetry.test.js +1 -1
  41. package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
  42. package/dist/src/tools/smart-edit.d.ts +0 -19
  43. package/dist/src/tools/smart-edit.js +11 -47
  44. package/dist/src/tools/smart-edit.js.map +1 -1
  45. package/dist/src/tools/smart-edit.test.js +0 -59
  46. package/dist/src/tools/smart-edit.test.js.map +1 -1
  47. package/dist/src/tools/tool-error.d.ts +21 -0
  48. package/dist/src/tools/tool-error.js +27 -0
  49. package/dist/src/tools/tool-error.js.map +1 -1
  50. package/dist/src/utils/pathCorrector.d.ts +25 -0
  51. package/dist/src/utils/pathCorrector.js +33 -0
  52. package/dist/src/utils/pathCorrector.js.map +1 -0
  53. package/dist/src/utils/pathCorrector.test.d.ts +6 -0
  54. package/dist/src/utils/pathCorrector.test.js +83 -0
  55. package/dist/src/utils/pathCorrector.test.js.map +1 -0
  56. package/dist/tsconfig.tsbuildinfo +1 -1
  57. package/package.json +1 -1
@@ -4,51 +4,20 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { logs } from '@opentelemetry/api-logs';
7
- import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
8
- import { EVENT_API_ERROR, EVENT_API_REQUEST, EVENT_API_RESPONSE, EVENT_CLI_CONFIG, EVENT_EXTENSION_UNINSTALL, EVENT_EXTENSION_ENABLE, EVENT_IDE_CONNECTION, EVENT_TOOL_CALL, EVENT_USER_PROMPT, EVENT_FLASH_FALLBACK, EVENT_NEXT_SPEAKER_CHECK, SERVICE_NAME, EVENT_SLASH_COMMAND, EVENT_CONVERSATION_FINISHED, EVENT_CHAT_COMPRESSION, EVENT_MALFORMED_JSON_RESPONSE, EVENT_INVALID_CHUNK, EVENT_CONTENT_RETRY, EVENT_CONTENT_RETRY_FAILURE, EVENT_FILE_OPERATION, EVENT_TOOL_OUTPUT_TRUNCATED, EVENT_RIPGREP_FALLBACK, EVENT_MODEL_ROUTING, EVENT_EXTENSION_INSTALL, EVENT_MODEL_SLASH_COMMAND, EVENT_EXTENSION_DISABLE, EVENT_SMART_EDIT_STRATEGY, EVENT_SMART_EDIT_CORRECTION, EVENT_AGENT_START, EVENT_AGENT_FINISH, EVENT_WEB_FETCH_FALLBACK_ATTEMPT, } from './constants.js';
7
+ import { SERVICE_NAME } from './constants.js';
8
+ import { EVENT_API_ERROR, EVENT_API_RESPONSE, EVENT_TOOL_CALL, } from './types.js';
9
9
  import { recordApiErrorMetrics, recordToolCallMetrics, recordChatCompressionMetrics, recordFileOperationMetric, recordInvalidChunk, recordContentRetry, recordContentRetryFailure, recordModelRoutingMetrics, recordModelSlashCommand, getConventionAttributes, recordTokenUsageMetrics, recordApiResponseMetrics, recordAgentRunMetrics, } from './metrics.js';
10
10
  import { isTelemetrySdkInitialized } from './sdk.js';
11
11
  import { uiTelemetryService } from './uiTelemetry.js';
12
12
  import { ClearcutLogger } from './clearcut-logger/clearcut-logger.js';
13
- import { safeJsonStringify } from '../utils/safeJsonStringify.js';
14
- import { UserAccountManager } from '../utils/userAccountManager.js';
15
- const shouldLogUserPrompts = (config) => config.getTelemetryLogPromptsEnabled();
16
- function getCommonAttributes(config) {
17
- const userAccountManager = new UserAccountManager();
18
- const email = userAccountManager.getCachedGoogleAccount();
19
- return {
20
- 'session.id': config.getSessionId(),
21
- ...(email && { 'user.email': email }),
22
- };
23
- }
24
13
  export function logCliConfiguration(config, event) {
25
14
  ClearcutLogger.getInstance(config)?.logStartSessionEvent(event);
26
15
  if (!isTelemetrySdkInitialized())
27
16
  return;
28
- const attributes = {
29
- ...getCommonAttributes(config),
30
- 'event.name': EVENT_CLI_CONFIG,
31
- 'event.timestamp': new Date().toISOString(),
32
- model: event.model,
33
- embedding_model: event.embedding_model,
34
- sandbox_enabled: event.sandbox_enabled,
35
- core_tools_enabled: event.core_tools_enabled,
36
- approval_mode: event.approval_mode,
37
- api_key_enabled: event.api_key_enabled,
38
- vertex_ai_enabled: event.vertex_ai_enabled,
39
- log_user_prompts_enabled: event.telemetry_log_user_prompts_enabled,
40
- file_filtering_respect_git_ignore: event.file_filtering_respect_git_ignore,
41
- debug_mode: event.debug_enabled,
42
- mcp_servers: event.mcp_servers,
43
- mcp_servers_count: event.mcp_servers_count,
44
- mcp_tools: event.mcp_tools,
45
- mcp_tools_count: event.mcp_tools_count,
46
- output_format: event.output_format,
47
- };
48
17
  const logger = logs.getLogger(SERVICE_NAME);
49
18
  const logRecord = {
50
- body: 'CLI configuration loaded.',
51
- attributes,
19
+ body: event.toLogBody(),
20
+ attributes: event.toOpenTelemetryAttributes(config),
52
21
  };
53
22
  logger.emit(logRecord);
54
23
  }
@@ -56,23 +25,10 @@ export function logUserPrompt(config, event) {
56
25
  ClearcutLogger.getInstance(config)?.logNewPromptEvent(event);
57
26
  if (!isTelemetrySdkInitialized())
58
27
  return;
59
- const attributes = {
60
- ...getCommonAttributes(config),
61
- 'event.name': EVENT_USER_PROMPT,
62
- 'event.timestamp': new Date().toISOString(),
63
- prompt_length: event.prompt_length,
64
- prompt_id: event.prompt_id,
65
- };
66
- if (event.auth_type) {
67
- attributes['auth_type'] = event.auth_type;
68
- }
69
- if (shouldLogUserPrompts(config)) {
70
- attributes['prompt'] = event.prompt;
71
- }
72
28
  const logger = logs.getLogger(SERVICE_NAME);
73
29
  const logRecord = {
74
- body: `User prompt. Length: ${event.prompt_length}.`,
75
- attributes,
30
+ body: event.toLogBody(),
31
+ attributes: event.toOpenTelemetryAttributes(config),
76
32
  };
77
33
  logger.emit(logRecord);
78
34
  }
@@ -86,23 +42,10 @@ export function logToolCall(config, event) {
86
42
  ClearcutLogger.getInstance(config)?.logToolCallEvent(event);
87
43
  if (!isTelemetrySdkInitialized())
88
44
  return;
89
- const attributes = {
90
- ...getCommonAttributes(config),
91
- ...event,
92
- 'event.name': EVENT_TOOL_CALL,
93
- 'event.timestamp': new Date().toISOString(),
94
- function_args: safeJsonStringify(event.function_args, 2),
95
- };
96
- if (event.error) {
97
- attributes['error.message'] = event.error;
98
- if (event.error_type) {
99
- attributes['error.type'] = event.error_type;
100
- }
101
- }
102
45
  const logger = logs.getLogger(SERVICE_NAME);
103
46
  const logRecord = {
104
- body: `Tool call: ${event.function_name}${event.decision ? `. Decision: ${event.decision}` : ''}. Success: ${event.success}. Duration: ${event.duration_ms}ms.`,
105
- attributes,
47
+ body: event.toLogBody(),
48
+ attributes: event.toOpenTelemetryAttributes(config),
106
49
  };
107
50
  logger.emit(logRecord);
108
51
  recordToolCallMetrics(config, event.duration_ms, {
@@ -110,22 +53,24 @@ export function logToolCall(config, event) {
110
53
  success: event.success,
111
54
  decision: event.decision,
112
55
  tool_type: event.tool_type,
56
+ ...(event.metadata
57
+ ? {
58
+ model_added_lines: event.metadata['model_added_lines'],
59
+ model_removed_lines: event.metadata['model_removed_lines'],
60
+ user_added_lines: event.metadata['user_added_lines'],
61
+ user_removed_lines: event.metadata['user_removed_lines'],
62
+ }
63
+ : {}),
113
64
  });
114
65
  }
115
66
  export function logToolOutputTruncated(config, event) {
116
67
  ClearcutLogger.getInstance(config)?.logToolOutputTruncatedEvent(event);
117
68
  if (!isTelemetrySdkInitialized())
118
69
  return;
119
- const attributes = {
120
- ...getCommonAttributes(config),
121
- ...event,
122
- 'event.name': EVENT_TOOL_OUTPUT_TRUNCATED,
123
- 'event.timestamp': new Date().toISOString(),
124
- };
125
70
  const logger = logs.getLogger(SERVICE_NAME);
126
71
  const logRecord = {
127
- body: `Tool output truncated for ${event.tool_name}.`,
128
- attributes,
72
+ body: event.toLogBody(),
73
+ attributes: event.toOpenTelemetryAttributes(config),
129
74
  };
130
75
  logger.emit(logRecord);
131
76
  }
@@ -133,29 +78,10 @@ export function logFileOperation(config, event) {
133
78
  ClearcutLogger.getInstance(config)?.logFileOperationEvent(event);
134
79
  if (!isTelemetrySdkInitialized())
135
80
  return;
136
- const attributes = {
137
- ...getCommonAttributes(config),
138
- 'event.name': EVENT_FILE_OPERATION,
139
- 'event.timestamp': new Date().toISOString(),
140
- tool_name: event.tool_name,
141
- operation: event.operation,
142
- };
143
- if (event.lines) {
144
- attributes['lines'] = event.lines;
145
- }
146
- if (event.mimetype) {
147
- attributes['mimetype'] = event.mimetype;
148
- }
149
- if (event.extension) {
150
- attributes['extension'] = event.extension;
151
- }
152
- if (event.programming_language) {
153
- attributes['programming_language'] = event.programming_language;
154
- }
155
81
  const logger = logs.getLogger(SERVICE_NAME);
156
82
  const logRecord = {
157
- body: `File operation: ${event.operation}. Lines: ${event.lines}.`,
158
- attributes,
83
+ body: event.toLogBody(),
84
+ attributes: event.toOpenTelemetryAttributes(config),
159
85
  };
160
86
  logger.emit(logRecord);
161
87
  recordFileOperationMetric(config, {
@@ -170,16 +96,10 @@ export function logApiRequest(config, event) {
170
96
  ClearcutLogger.getInstance(config)?.logApiRequestEvent(event);
171
97
  if (!isTelemetrySdkInitialized())
172
98
  return;
173
- const attributes = {
174
- ...getCommonAttributes(config),
175
- ...event,
176
- 'event.name': EVENT_API_REQUEST,
177
- 'event.timestamp': new Date().toISOString(),
178
- };
179
99
  const logger = logs.getLogger(SERVICE_NAME);
180
100
  const logRecord = {
181
- body: `API request to ${event.model}.`,
182
- attributes,
101
+ body: event.toLogBody(),
102
+ attributes: event.toOpenTelemetryAttributes(config),
183
103
  };
184
104
  logger.emit(logRecord);
185
105
  }
@@ -187,16 +107,10 @@ export function logFlashFallback(config, event) {
187
107
  ClearcutLogger.getInstance(config)?.logFlashFallbackEvent();
188
108
  if (!isTelemetrySdkInitialized())
189
109
  return;
190
- const attributes = {
191
- ...getCommonAttributes(config),
192
- ...event,
193
- 'event.name': EVENT_FLASH_FALLBACK,
194
- 'event.timestamp': new Date().toISOString(),
195
- };
196
110
  const logger = logs.getLogger(SERVICE_NAME);
197
111
  const logRecord = {
198
- body: `Switching to flash as Fallback.`,
199
- attributes,
112
+ body: event.toLogBody(),
113
+ attributes: event.toOpenTelemetryAttributes(config),
200
114
  };
201
115
  logger.emit(logRecord);
202
116
  }
@@ -204,16 +118,10 @@ export function logRipgrepFallback(config, event) {
204
118
  ClearcutLogger.getInstance(config)?.logRipgrepFallbackEvent();
205
119
  if (!isTelemetrySdkInitialized())
206
120
  return;
207
- const attributes = {
208
- ...getCommonAttributes(config),
209
- ...event,
210
- 'event.name': EVENT_RIPGREP_FALLBACK,
211
- 'event.timestamp': new Date().toISOString(),
212
- };
213
121
  const logger = logs.getLogger(SERVICE_NAME);
214
122
  const logRecord = {
215
- body: `Switching to grep as fallback.`,
216
- attributes,
123
+ body: event.toLogBody(),
124
+ attributes: event.toOpenTelemetryAttributes(config),
217
125
  };
218
126
  logger.emit(logRecord);
219
127
  }
@@ -227,25 +135,10 @@ export function logApiError(config, event) {
227
135
  ClearcutLogger.getInstance(config)?.logApiErrorEvent(event);
228
136
  if (!isTelemetrySdkInitialized())
229
137
  return;
230
- const attributes = {
231
- ...getCommonAttributes(config),
232
- ...event,
233
- 'event.name': EVENT_API_ERROR,
234
- 'event.timestamp': new Date().toISOString(),
235
- ['error.message']: event.error,
236
- model_name: event.model,
237
- duration: event.duration_ms,
238
- };
239
- if (event.error_type) {
240
- attributes['error.type'] = event.error_type;
241
- }
242
- if (typeof event.status_code === 'number') {
243
- attributes[SemanticAttributes.HTTP_STATUS_CODE] = event.status_code;
244
- }
245
138
  const logger = logs.getLogger(SERVICE_NAME);
246
139
  const logRecord = {
247
- body: `API error for ${event.model}. Error: ${event.error}. Duration: ${event.duration_ms}ms.`,
248
- attributes,
140
+ body: event.toLogBody(),
141
+ attributes: event.toOpenTelemetryAttributes(config),
249
142
  };
250
143
  logger.emit(logRecord);
251
144
  recordApiErrorMetrics(config, event.duration_ms, {
@@ -274,24 +167,10 @@ export function logApiResponse(config, event) {
274
167
  ClearcutLogger.getInstance(config)?.logApiResponseEvent(event);
275
168
  if (!isTelemetrySdkInitialized())
276
169
  return;
277
- const attributes = {
278
- ...getCommonAttributes(config),
279
- ...event,
280
- 'event.name': EVENT_API_RESPONSE,
281
- 'event.timestamp': new Date().toISOString(),
282
- };
283
- if (event.response_text) {
284
- attributes['response_text'] = event.response_text;
285
- }
286
- if (event.status_code) {
287
- if (typeof event.status_code === 'number') {
288
- attributes[SemanticAttributes.HTTP_STATUS_CODE] = event.status_code;
289
- }
290
- }
291
170
  const logger = logs.getLogger(SERVICE_NAME);
292
171
  const logRecord = {
293
- body: `API response from ${event.model}. Status: ${event.status_code || 'N/A'}. Duration: ${event.duration_ms}ms.`,
294
- attributes,
172
+ body: event.toLogBody(),
173
+ attributes: event.toOpenTelemetryAttributes(config),
295
174
  };
296
175
  logger.emit(logRecord);
297
176
  const conventionAttributes = getConventionAttributes(event);
@@ -319,33 +198,32 @@ export function logLoopDetected(config, event) {
319
198
  ClearcutLogger.getInstance(config)?.logLoopDetectedEvent(event);
320
199
  if (!isTelemetrySdkInitialized())
321
200
  return;
322
- const attributes = {
323
- ...getCommonAttributes(config),
324
- ...event,
325
- };
326
201
  const logger = logs.getLogger(SERVICE_NAME);
327
202
  const logRecord = {
328
- body: `Loop detected. Type: ${event.loop_type}.`,
329
- attributes,
203
+ body: event.toLogBody(),
204
+ attributes: event.toOpenTelemetryAttributes(config),
330
205
  };
331
206
  logger.emit(logRecord);
332
207
  }
333
- export function logLoopDetectionDisabled(config, _event) {
208
+ export function logLoopDetectionDisabled(config, event) {
334
209
  ClearcutLogger.getInstance(config)?.logLoopDetectionDisabledEvent();
210
+ if (!isTelemetrySdkInitialized())
211
+ return;
212
+ const logger = logs.getLogger(SERVICE_NAME);
213
+ const logRecord = {
214
+ body: event.toLogBody(),
215
+ attributes: event.toOpenTelemetryAttributes(config),
216
+ };
217
+ logger.emit(logRecord);
335
218
  }
336
219
  export function logNextSpeakerCheck(config, event) {
337
220
  ClearcutLogger.getInstance(config)?.logNextSpeakerCheck(event);
338
221
  if (!isTelemetrySdkInitialized())
339
222
  return;
340
- const attributes = {
341
- ...getCommonAttributes(config),
342
- ...event,
343
- 'event.name': EVENT_NEXT_SPEAKER_CHECK,
344
- };
345
223
  const logger = logs.getLogger(SERVICE_NAME);
346
224
  const logRecord = {
347
- body: `Next speaker check.`,
348
- attributes,
225
+ body: event.toLogBody(),
226
+ attributes: event.toOpenTelemetryAttributes(config),
349
227
  };
350
228
  logger.emit(logRecord);
351
229
  }
@@ -353,15 +231,10 @@ export function logSlashCommand(config, event) {
353
231
  ClearcutLogger.getInstance(config)?.logSlashCommandEvent(event);
354
232
  if (!isTelemetrySdkInitialized())
355
233
  return;
356
- const attributes = {
357
- ...getCommonAttributes(config),
358
- ...event,
359
- 'event.name': EVENT_SLASH_COMMAND,
360
- };
361
234
  const logger = logs.getLogger(SERVICE_NAME);
362
235
  const logRecord = {
363
- body: `Slash command: ${event.command}.`,
364
- attributes,
236
+ body: event.toLogBody(),
237
+ attributes: event.toOpenTelemetryAttributes(config),
365
238
  };
366
239
  logger.emit(logRecord);
367
240
  }
@@ -369,15 +242,10 @@ export function logIdeConnection(config, event) {
369
242
  ClearcutLogger.getInstance(config)?.logIdeConnectionEvent(event);
370
243
  if (!isTelemetrySdkInitialized())
371
244
  return;
372
- const attributes = {
373
- ...getCommonAttributes(config),
374
- ...event,
375
- 'event.name': EVENT_IDE_CONNECTION,
376
- };
377
245
  const logger = logs.getLogger(SERVICE_NAME);
378
246
  const logRecord = {
379
- body: `Ide connection. Type: ${event.connection_type}.`,
380
- attributes,
247
+ body: event.toLogBody(),
248
+ attributes: event.toOpenTelemetryAttributes(config),
381
249
  };
382
250
  logger.emit(logRecord);
383
251
  }
@@ -385,29 +253,19 @@ export function logConversationFinishedEvent(config, event) {
385
253
  ClearcutLogger.getInstance(config)?.logConversationFinishedEvent(event);
386
254
  if (!isTelemetrySdkInitialized())
387
255
  return;
388
- const attributes = {
389
- ...getCommonAttributes(config),
390
- ...event,
391
- 'event.name': EVENT_CONVERSATION_FINISHED,
392
- };
393
256
  const logger = logs.getLogger(SERVICE_NAME);
394
257
  const logRecord = {
395
- body: `Conversation finished.`,
396
- attributes,
258
+ body: event.toLogBody(),
259
+ attributes: event.toOpenTelemetryAttributes(config),
397
260
  };
398
261
  logger.emit(logRecord);
399
262
  }
400
263
  export function logChatCompression(config, event) {
401
264
  ClearcutLogger.getInstance(config)?.logChatCompressionEvent(event);
402
- const attributes = {
403
- ...getCommonAttributes(config),
404
- ...event,
405
- 'event.name': EVENT_CHAT_COMPRESSION,
406
- };
407
265
  const logger = logs.getLogger(SERVICE_NAME);
408
266
  const logRecord = {
409
- body: `Chat compression (Saved ${event.tokens_before - event.tokens_after} tokens)`,
410
- attributes,
267
+ body: event.toLogBody(),
268
+ attributes: event.toOpenTelemetryAttributes(config),
411
269
  };
412
270
  logger.emit(logRecord);
413
271
  recordChatCompressionMetrics(config, {
@@ -419,14 +277,10 @@ export function logKittySequenceOverflow(config, event) {
419
277
  ClearcutLogger.getInstance(config)?.logKittySequenceOverflowEvent(event);
420
278
  if (!isTelemetrySdkInitialized())
421
279
  return;
422
- const attributes = {
423
- ...getCommonAttributes(config),
424
- ...event,
425
- };
426
280
  const logger = logs.getLogger(SERVICE_NAME);
427
281
  const logRecord = {
428
- body: `Kitty sequence buffer overflow: ${event.sequence_length} bytes`,
429
- attributes,
282
+ body: event.toLogBody(),
283
+ attributes: event.toOpenTelemetryAttributes(config),
430
284
  };
431
285
  logger.emit(logRecord);
432
286
  }
@@ -434,15 +288,10 @@ export function logMalformedJsonResponse(config, event) {
434
288
  ClearcutLogger.getInstance(config)?.logMalformedJsonResponseEvent(event);
435
289
  if (!isTelemetrySdkInitialized())
436
290
  return;
437
- const attributes = {
438
- ...getCommonAttributes(config),
439
- ...event,
440
- 'event.name': EVENT_MALFORMED_JSON_RESPONSE,
441
- };
442
291
  const logger = logs.getLogger(SERVICE_NAME);
443
292
  const logRecord = {
444
- body: `Malformed JSON response from ${event.model}.`,
445
- attributes,
293
+ body: event.toLogBody(),
294
+ attributes: event.toOpenTelemetryAttributes(config),
446
295
  };
447
296
  logger.emit(logRecord);
448
297
  }
@@ -450,18 +299,10 @@ export function logInvalidChunk(config, event) {
450
299
  ClearcutLogger.getInstance(config)?.logInvalidChunkEvent(event);
451
300
  if (!isTelemetrySdkInitialized())
452
301
  return;
453
- const attributes = {
454
- ...getCommonAttributes(config),
455
- 'event.name': EVENT_INVALID_CHUNK,
456
- 'event.timestamp': event['event.timestamp'],
457
- };
458
- if (event.error_message) {
459
- attributes['error.message'] = event.error_message;
460
- }
461
302
  const logger = logs.getLogger(SERVICE_NAME);
462
303
  const logRecord = {
463
- body: `Invalid chunk received from stream.`,
464
- attributes,
304
+ body: event.toLogBody(),
305
+ attributes: event.toOpenTelemetryAttributes(config),
465
306
  };
466
307
  logger.emit(logRecord);
467
308
  recordInvalidChunk(config);
@@ -470,15 +311,10 @@ export function logContentRetry(config, event) {
470
311
  ClearcutLogger.getInstance(config)?.logContentRetryEvent(event);
471
312
  if (!isTelemetrySdkInitialized())
472
313
  return;
473
- const attributes = {
474
- ...getCommonAttributes(config),
475
- ...event,
476
- 'event.name': EVENT_CONTENT_RETRY,
477
- };
478
314
  const logger = logs.getLogger(SERVICE_NAME);
479
315
  const logRecord = {
480
- body: `Content retry attempt ${event.attempt_number} due to ${event.error_type}.`,
481
- attributes,
316
+ body: event.toLogBody(),
317
+ attributes: event.toOpenTelemetryAttributes(config),
482
318
  };
483
319
  logger.emit(logRecord);
484
320
  recordContentRetry(config);
@@ -487,15 +323,10 @@ export function logContentRetryFailure(config, event) {
487
323
  ClearcutLogger.getInstance(config)?.logContentRetryFailureEvent(event);
488
324
  if (!isTelemetrySdkInitialized())
489
325
  return;
490
- const attributes = {
491
- ...getCommonAttributes(config),
492
- ...event,
493
- 'event.name': EVENT_CONTENT_RETRY_FAILURE,
494
- };
495
326
  const logger = logs.getLogger(SERVICE_NAME);
496
327
  const logRecord = {
497
- body: `All content retries failed after ${event.total_attempts} attempts.`,
498
- attributes,
328
+ body: event.toLogBody(),
329
+ attributes: event.toOpenTelemetryAttributes(config),
499
330
  };
500
331
  logger.emit(logRecord);
501
332
  recordContentRetryFailure(config);
@@ -504,15 +335,10 @@ export function logModelRouting(config, event) {
504
335
  ClearcutLogger.getInstance(config)?.logModelRoutingEvent(event);
505
336
  if (!isTelemetrySdkInitialized())
506
337
  return;
507
- const attributes = {
508
- ...getCommonAttributes(config),
509
- ...event,
510
- 'event.name': EVENT_MODEL_ROUTING,
511
- };
512
338
  const logger = logs.getLogger(SERVICE_NAME);
513
339
  const logRecord = {
514
- body: `Model routing decision. Model: ${event.decision_model}, Source: ${event.decision_source}`,
515
- attributes,
340
+ body: event.toLogBody(),
341
+ attributes: event.toOpenTelemetryAttributes(config),
516
342
  };
517
343
  logger.emit(logRecord);
518
344
  recordModelRoutingMetrics(config, event);
@@ -521,15 +347,10 @@ export function logModelSlashCommand(config, event) {
521
347
  ClearcutLogger.getInstance(config)?.logModelSlashCommandEvent(event);
522
348
  if (!isTelemetrySdkInitialized())
523
349
  return;
524
- const attributes = {
525
- ...getCommonAttributes(config),
526
- ...event,
527
- 'event.name': EVENT_MODEL_SLASH_COMMAND,
528
- };
529
350
  const logger = logs.getLogger(SERVICE_NAME);
530
351
  const logRecord = {
531
- body: `Model slash command. Model: ${event.model_name}`,
532
- attributes,
352
+ body: event.toLogBody(),
353
+ attributes: event.toOpenTelemetryAttributes(config),
533
354
  };
534
355
  logger.emit(logRecord);
535
356
  recordModelSlashCommand(config, event);
@@ -538,20 +359,10 @@ export function logExtensionInstallEvent(config, event) {
538
359
  ClearcutLogger.getInstance(config)?.logExtensionInstallEvent(event);
539
360
  if (!isTelemetrySdkInitialized())
540
361
  return;
541
- const attributes = {
542
- ...getCommonAttributes(config),
543
- ...event,
544
- 'event.name': EVENT_EXTENSION_INSTALL,
545
- 'event.timestamp': new Date().toISOString(),
546
- extension_name: event.extension_name,
547
- extension_version: event.extension_version,
548
- extension_source: event.extension_source,
549
- status: event.status,
550
- };
551
362
  const logger = logs.getLogger(SERVICE_NAME);
552
363
  const logRecord = {
553
- body: `Installed extension ${event.extension_name}`,
554
- attributes,
364
+ body: event.toLogBody(),
365
+ attributes: event.toOpenTelemetryAttributes(config),
555
366
  };
556
367
  logger.emit(logRecord);
557
368
  }
@@ -559,16 +370,10 @@ export function logExtensionUninstall(config, event) {
559
370
  ClearcutLogger.getInstance(config)?.logExtensionUninstallEvent(event);
560
371
  if (!isTelemetrySdkInitialized())
561
372
  return;
562
- const attributes = {
563
- ...getCommonAttributes(config),
564
- ...event,
565
- 'event.name': EVENT_EXTENSION_UNINSTALL,
566
- 'event.timestamp': new Date().toISOString(),
567
- };
568
373
  const logger = logs.getLogger(SERVICE_NAME);
569
374
  const logRecord = {
570
- body: `Uninstalled extension ${event.extension_name}`,
571
- attributes,
375
+ body: event.toLogBody(),
376
+ attributes: event.toOpenTelemetryAttributes(config),
572
377
  };
573
378
  logger.emit(logRecord);
574
379
  }
@@ -576,16 +381,10 @@ export function logExtensionEnable(config, event) {
576
381
  ClearcutLogger.getInstance(config)?.logExtensionEnableEvent(event);
577
382
  if (!isTelemetrySdkInitialized())
578
383
  return;
579
- const attributes = {
580
- ...getCommonAttributes(config),
581
- ...event,
582
- 'event.name': EVENT_EXTENSION_ENABLE,
583
- 'event.timestamp': new Date().toISOString(),
584
- };
585
384
  const logger = logs.getLogger(SERVICE_NAME);
586
385
  const logRecord = {
587
- body: `Enabled extension ${event.extension_name}`,
588
- attributes,
386
+ body: event.toLogBody(),
387
+ attributes: event.toOpenTelemetryAttributes(config),
589
388
  };
590
389
  logger.emit(logRecord);
591
390
  }
@@ -593,16 +392,10 @@ export function logExtensionDisable(config, event) {
593
392
  ClearcutLogger.getInstance(config)?.logExtensionDisableEvent(event);
594
393
  if (!isTelemetrySdkInitialized())
595
394
  return;
596
- const attributes = {
597
- ...getCommonAttributes(config),
598
- ...event,
599
- 'event.name': EVENT_EXTENSION_DISABLE,
600
- 'event.timestamp': new Date().toISOString(),
601
- };
602
395
  const logger = logs.getLogger(SERVICE_NAME);
603
396
  const logRecord = {
604
- body: `Disabled extension ${event.extension_name}`,
605
- attributes,
397
+ body: event.toLogBody(),
398
+ attributes: event.toOpenTelemetryAttributes(config),
606
399
  };
607
400
  logger.emit(logRecord);
608
401
  }
@@ -610,15 +403,10 @@ export function logSmartEditStrategy(config, event) {
610
403
  ClearcutLogger.getInstance(config)?.logSmartEditStrategyEvent(event);
611
404
  if (!isTelemetrySdkInitialized())
612
405
  return;
613
- const attributes = {
614
- ...getCommonAttributes(config),
615
- ...event,
616
- 'event.name': EVENT_SMART_EDIT_STRATEGY,
617
- };
618
406
  const logger = logs.getLogger(SERVICE_NAME);
619
407
  const logRecord = {
620
- body: `Smart Edit Tool Strategy: ${event.strategy}`,
621
- attributes,
408
+ body: event.toLogBody(),
409
+ attributes: event.toOpenTelemetryAttributes(config),
622
410
  };
623
411
  logger.emit(logRecord);
624
412
  }
@@ -626,15 +414,10 @@ export function logSmartEditCorrectionEvent(config, event) {
626
414
  ClearcutLogger.getInstance(config)?.logSmartEditCorrectionEvent(event);
627
415
  if (!isTelemetrySdkInitialized())
628
416
  return;
629
- const attributes = {
630
- ...getCommonAttributes(config),
631
- ...event,
632
- 'event.name': EVENT_SMART_EDIT_CORRECTION,
633
- };
634
417
  const logger = logs.getLogger(SERVICE_NAME);
635
418
  const logRecord = {
636
- body: `Smart Edit Correction`,
637
- attributes,
419
+ body: event.toLogBody(),
420
+ attributes: event.toOpenTelemetryAttributes(config),
638
421
  };
639
422
  logger.emit(logRecord);
640
423
  }
@@ -642,15 +425,10 @@ export function logAgentStart(config, event) {
642
425
  ClearcutLogger.getInstance(config)?.logAgentStartEvent(event);
643
426
  if (!isTelemetrySdkInitialized())
644
427
  return;
645
- const attributes = {
646
- ...getCommonAttributes(config),
647
- ...event,
648
- 'event.name': EVENT_AGENT_START,
649
- };
650
428
  const logger = logs.getLogger(SERVICE_NAME);
651
429
  const logRecord = {
652
- body: `Agent ${event.agent_name} started. ID: ${event.agent_id}`,
653
- attributes,
430
+ body: event.toLogBody(),
431
+ attributes: event.toOpenTelemetryAttributes(config),
654
432
  };
655
433
  logger.emit(logRecord);
656
434
  }
@@ -658,15 +436,10 @@ export function logAgentFinish(config, event) {
658
436
  ClearcutLogger.getInstance(config)?.logAgentFinishEvent(event);
659
437
  if (!isTelemetrySdkInitialized())
660
438
  return;
661
- const attributes = {
662
- ...getCommonAttributes(config),
663
- ...event,
664
- 'event.name': EVENT_AGENT_FINISH,
665
- };
666
439
  const logger = logs.getLogger(SERVICE_NAME);
667
440
  const logRecord = {
668
- body: `Agent ${event.agent_name} finished. Reason: ${event.terminate_reason}. Duration: ${event.duration_ms}ms. Turns: ${event.turn_count}.`,
669
- attributes,
441
+ body: event.toLogBody(),
442
+ attributes: event.toOpenTelemetryAttributes(config),
670
443
  };
671
444
  logger.emit(logRecord);
672
445
  recordAgentRunMetrics(config, event);
@@ -675,15 +448,10 @@ export function logWebFetchFallbackAttempt(config, event) {
675
448
  ClearcutLogger.getInstance(config)?.logWebFetchFallbackAttemptEvent(event);
676
449
  if (!isTelemetrySdkInitialized())
677
450
  return;
678
- const attributes = {
679
- ...getCommonAttributes(config),
680
- ...event,
681
- 'event.name': EVENT_WEB_FETCH_FALLBACK_ATTEMPT,
682
- };
683
451
  const logger = logs.getLogger(SERVICE_NAME);
684
452
  const logRecord = {
685
- body: `Web fetch fallback attempt. Reason: ${event.reason}`,
686
- attributes,
453
+ body: event.toLogBody(),
454
+ attributes: event.toOpenTelemetryAttributes(config),
687
455
  };
688
456
  logger.emit(logRecord);
689
457
  }