feat:add otel logging
This commit is contained in:
@@ -625,3 +625,4 @@ export type ICreateImport = z.infer<typeof zCreateImport>;
|
||||
export * from './event-blocklist';
|
||||
export * from './track.validation';
|
||||
export * from './types.insights';
|
||||
export * from './log.validation';
|
||||
|
||||
60
packages/validation/src/log.validation.ts
Normal file
60
packages/validation/src/log.validation.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
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>;
|
||||
Reference in New Issue
Block a user