(config: Config, event: ToolCallEvent)
| 114 | } |
| 115 | |
| 116 | export function logToolCall(config: Config, event: ToolCallEvent): void { |
| 117 | const uiEvent = { |
| 118 | ...event, |
| 119 | 'event.name': EVENT_TOOL_CALL, |
| 120 | 'event.timestamp': new Date().toISOString(), |
| 121 | } as UiEvent; |
| 122 | uiTelemetryService.addEvent(uiEvent); |
| 123 | ClearcutLogger.getInstance(config)?.logToolCallEvent(event); |
| 124 | if (!isTelemetrySdkInitialized()) return; |
| 125 | |
| 126 | const attributes: LogAttributes = { |
| 127 | ...getCommonAttributes(config), |
| 128 | ...event, |
| 129 | 'event.name': EVENT_TOOL_CALL, |
| 130 | 'event.timestamp': new Date().toISOString(), |
| 131 | function_args: safeJsonStringify(event.function_args, 2), |
| 132 | }; |
| 133 | if (event.error) { |
| 134 | attributes['error.message'] = event.error; |
| 135 | if (event.error_type) { |
| 136 | attributes['error.type'] = event.error_type; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | const logger = logs.getLogger(SERVICE_NAME); |
| 141 | const logRecord: LogRecord = { |
| 142 | body: `Tool call: ${event.function_name}${event.decision ? `. Decision: ${event.decision}` : ''}. Success: ${event.success}. Duration: ${event.duration_ms}ms.`, |
| 143 | attributes, |
| 144 | }; |
| 145 | logger.emit(logRecord); |
| 146 | recordToolCallMetrics( |
| 147 | config, |
| 148 | event.function_name, |
| 149 | event.duration_ms, |
| 150 | event.success, |
| 151 | event.decision, |
| 152 | ); |
| 153 | } |
| 154 | |
| 155 | export function logApiRequest(config: Config, event: ApiRequestEvent): void { |
| 156 | ClearcutLogger.getInstance(config)?.logApiRequestEvent(event); |
no test coverage detected