61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
/**
|
|
* OTel severity number mapping (subset):
|
|
* TRACE=1, DEBUG=5, INFO=9, WARN=13, ERROR=17, FATAL=21
|
|
*/
|
|
export const SEVERITY_TEXT_TO_NUMBER: Record<string, number> = {
|
|
trace: 1,
|
|
debug: 5,
|
|
info: 9,
|
|
warn: 13,
|
|
warning: 13,
|
|
error: 17,
|
|
fatal: 21,
|
|
critical: 21,
|
|
};
|
|
|
|
export const zSeverityText = z.enum([
|
|
'trace',
|
|
'debug',
|
|
'info',
|
|
'warn',
|
|
'warning',
|
|
'error',
|
|
'fatal',
|
|
'critical',
|
|
]);
|
|
|
|
export type ISeverityText = z.infer<typeof zSeverityText>;
|
|
|
|
export const zLogPayload = z.object({
|
|
/** Log message / body */
|
|
body: z.string().min(1),
|
|
/** Severity level as text */
|
|
severity: zSeverityText.default('info'),
|
|
/** Optional override for the numeric OTel severity (1-24) */
|
|
severityNumber: z.number().int().min(1).max(24).optional(),
|
|
/** ISO 8601 timestamp; defaults to server receive time if omitted */
|
|
timestamp: z.string().datetime({ offset: true }).optional(),
|
|
/** Logger name (e.g. "com.example.MyActivity") */
|
|
loggerName: z.string().optional(),
|
|
/** W3C trace context */
|
|
traceId: z.string().optional(),
|
|
spanId: z.string().optional(),
|
|
traceFlags: z.number().int().min(0).optional(),
|
|
/** Log-level key-value attributes */
|
|
attributes: z.record(z.string(), z.string()).optional(),
|
|
/** Resource/device attributes (app version, runtime, etc.) */
|
|
resource: z.record(z.string(), z.string()).optional(),
|
|
/** Profile/user ID to associate with this log */
|
|
profileId: z.union([z.string().min(1), z.number()]).optional(),
|
|
});
|
|
|
|
export type ILogPayload = z.infer<typeof zLogPayload>;
|
|
|
|
export const zLogBatchPayload = z.object({
|
|
logs: z.array(zLogPayload).min(1).max(500),
|
|
});
|
|
|
|
export type ILogBatchPayload = z.infer<typeof zLogBatchPayload>;
|