MCPcopy Create free account
hub / github.com/anus-dev/ANUS / logApiError

Function logApiError

packages/core/src/telemetry/loggers.ts:196–236  ·  view source on GitHub ↗
(config: Config, event: ApiErrorEvent)

Source from the content-addressed store, hash-verified

194}
195
196export 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
238export function logApiResponse(config: Config, event: ApiResponseEvent): void {
239 const uiEvent = {

Callers 1

_logApiErrorMethod · 0.85

Calls 6

recordApiErrorMetricsFunction · 0.85
addEventMethod · 0.80
logApiErrorEventMethod · 0.80
getCommonAttributesFunction · 0.70
getInstanceMethod · 0.45

Tested by

no test coverage detected