(config: Config, event: ApiErrorEvent)
| 194 | } |
| 195 | |
| 196 | export function logApiError(config: Config, event: ApiErrorEvent): void { |
| 197 | const uiEvent = { |
| 198 | ...event, |
| 199 | 'event.name': EVENT_API_ERROR, |
| 200 | 'event.timestamp': new Date().toISOString(), |
| 201 | } as UiEvent; |
| 202 | uiTelemetryService.addEvent(uiEvent); |
| 203 | ClearcutLogger.getInstance(config)?.logApiErrorEvent(event); |
| 204 | if (!isTelemetrySdkInitialized()) return; |
| 205 | |
| 206 | const attributes: LogAttributes = { |
| 207 | ...getCommonAttributes(config), |
| 208 | ...event, |
| 209 | 'event.name': EVENT_API_ERROR, |
| 210 | 'event.timestamp': new Date().toISOString(), |
| 211 | ['error.message']: event.error, |
| 212 | model_name: event.model, |
| 213 | duration: event.duration_ms, |
| 214 | }; |
| 215 | |
| 216 | if (event.error_type) { |
| 217 | attributes['error.type'] = event.error_type; |
| 218 | } |
| 219 | if (typeof event.status_code === 'number') { |
| 220 | attributes[SemanticAttributes.HTTP_STATUS_CODE] = event.status_code; |
| 221 | } |
| 222 | |
| 223 | const logger = logs.getLogger(SERVICE_NAME); |
| 224 | const logRecord: LogRecord = { |
| 225 | body: `API error for ${event.model}. Error: ${event.error}. Duration: ${event.duration_ms}ms.`, |
| 226 | attributes, |
| 227 | }; |
| 228 | logger.emit(logRecord); |
| 229 | recordApiErrorMetrics( |
| 230 | config, |
| 231 | event.model, |
| 232 | event.duration_ms, |
| 233 | event.status_code, |
| 234 | event.error_type, |
| 235 | ); |
| 236 | } |
| 237 | |
| 238 | export function logApiResponse(config: Config, event: ApiResponseEvent): void { |
| 239 | const uiEvent = { |
no test coverage detected