Files
dotfiles/dot_claude/skills/turnstile-spin/templates/worker/src/observability.ts
T
Prad NukalaandClaude Fable 5 20891f3910 config(git,claude,ssh): templated gitconfig; claude settings/commands/hooks/skills; ssh config
gitconfig: name/email from chezmoi data, gh credential helper by PATH
lookup (portable to darwin). claude: no credentials, history, projects,
sessions, or plugin caches. ssh config as private_ (0600).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-09 14:53:46 -04:00

35 lines
1.1 KiB
TypeScript

/**
* Structured logging helpers. Output is JSON-per-line so Workers Observability
* + log-shipping pipelines can parse + index without regex hacks.
*/
import type { SiteverifyLogEntry, ErrorCode } from './types.js';
export interface LogContext {
durationMs: number;
upstreamStatus?: number;
errorCodes?: ErrorCode[];
cdataValue?: string;
remoteipPresent: boolean;
idempotencyKeyPresent: boolean;
}
export function logSiteverify(outcome: 'ok' | 'fail' | 'error', ctx: LogContext): void {
const entry: SiteverifyLogEntry = {
level: outcome === 'ok' ? 'info' : outcome === 'fail' ? 'warn' : 'error',
event: 'siteverify',
outcome,
duration_ms: ctx.durationMs,
upstream_status: ctx.upstreamStatus,
error_codes: ctx.errorCodes ?? [],
cdata_present: typeof ctx.cdataValue === 'string' && ctx.cdataValue.length > 0,
cdata_value: ctx.cdataValue,
remoteip_present: ctx.remoteipPresent,
idempotency_key_present: ctx.idempotencyKeyPresent,
ts: new Date().toISOString(),
};
// console.log goes to Workers logs and Observability.
// Using a JSON line for machine-readability.
console.log(JSON.stringify(entry));
}