mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
Long-overdue prettier sweep; prettier had drifted vs. checked-in code across ~130 files (mostly long-argument line-break wrapping in TS and table-padding in markdown). Pure formatting — no semantic changes — and required to clear the v1.4.6 release gate's `pnpm format:check`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
31 lines
1023 B
TypeScript
31 lines
1023 B
TypeScript
import type { WideEvent } from "./types";
|
|
import { LOG_LEVEL_PRIORITY } from "./types";
|
|
import { getLoggingConfig, isLevelEnabled } from "./config";
|
|
|
|
/**
|
|
* Tail Sampling: Entscheidung ob ein Event emittiert werden soll.
|
|
*
|
|
* Immer behalten: Fehler, Warnungen, langsame Requests, Background-Tasks.
|
|
* Sampling nur fuer erfolgreiche, schnelle HTTP-Requests.
|
|
*/
|
|
export function shouldEmit(event: WideEvent): boolean {
|
|
if (!isLevelEnabled(event.level)) return false;
|
|
|
|
// Fehler und Warnungen immer behalten
|
|
if (LOG_LEVEL_PRIORITY[event.level] >= LOG_LEVEL_PRIORITY["warn"])
|
|
return true;
|
|
|
|
// Langsame Requests immer behalten
|
|
const config = getLoggingConfig();
|
|
if (event.duration_ms >= config.slowThresholdMs) return true;
|
|
|
|
// Hintergrundaufgaben immer behalten
|
|
if (event.kind === "background") return true;
|
|
|
|
// Fuer normale erfolgreiche Requests: Sampling anwenden
|
|
if (config.sampleRate >= 1.0) return true;
|
|
if (config.sampleRate <= 0.0) return false;
|
|
|
|
return Math.random() < config.sampleRate;
|
|
}
|