audit-logger: record the event's own x-event-id (ADR 0047)
The trail's id is now the event's x-event-id — the handle a reader dedups the at-least-once stream on — not the type@time placeholder the first cut used. Carries causation/schema through when present. Claude-Session: https://claude.ai/code/session_01LrgweAeERJYBg88c5cKDzF
This commit is contained in:
@@ -11,15 +11,18 @@ export function auditLogPath(env: NodeJS.ProcessEnv = process.env): string {
|
|||||||
return env.AUDIT_LOG ?? "/var/lib/audit-logger/audit.log";
|
return env.AUDIT_LOG ?? "/var/lib/audit-logger/audit.log";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Append an event to the trail as one JSON line, keeping the metadata an audit needs first. */
|
/** Append an event to the trail as one JSON line, keeping the metadata an audit needs first. The id
|
||||||
|
* is the event's own x-event-id (ADR 0047) — the handle a reader dedups the at-least-once trail on. */
|
||||||
export async function record(event: Event, path: string): Promise<void> {
|
export async function record(event: Event, path: string): Promise<void> {
|
||||||
const line =
|
const line =
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
id: event.type + "@" + event.at, // a stable-ish key until x-event-id headers land (ADR 0047)
|
id: event.id,
|
||||||
type: event.type,
|
type: event.type,
|
||||||
source: event.source,
|
source: event.source,
|
||||||
node: event.node,
|
node: event.node,
|
||||||
at: event.at,
|
at: event.at,
|
||||||
|
...(event.causationId ? { causationId: event.causationId } : {}),
|
||||||
|
...(event.schema ? { schema: event.schema } : {}),
|
||||||
body: event.body,
|
body: event.body,
|
||||||
}) + "\n";
|
}) + "\n";
|
||||||
await mkdir(dirname(path), { recursive: true }).catch(() => {});
|
await mkdir(dirname(path), { recursive: true }).catch(() => {});
|
||||||
|
|||||||
Reference in New Issue
Block a user