Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Emit durations in structured logs as numbers under a unit-suffixed key
A pre-formatted duration string like '5ms' cannot be aggregated, so log the numeric value under a key that names the unit and keep the human formatting for display code only.
Bad example
| 1 | const end = () => `${Date.now() - start}ms`; |
| 2 |
|
| 3 | emitInfo("ingest.complete", { duration: end() }); // {"duration":"5ms"} |
Explanation (EN)
Percentile and average queries receive a string, so the dashboard either errors or quietly renders nothing, and the field name does not say what unit it holds.
Objašnjenje (HR)
Upiti za percentile i prosjeke dobiju string, pa nadzorna ploca ili puca ili tiho ne prikazuje nista, a ime polja ne govori koju jedinicu sadrzi.
Good example
| 1 | const endMs = () => Date.now() - start; |
| 2 |
|
| 3 | emitInfo("ingest.complete", { duration_ms: endMs() }); // {"duration_ms":5} |
Explanation (EN)
The value is numeric and the key names its unit, matching the convention already used by the framework's own duration fields.
Objašnjenje (HR)
Vrijednost je broj, a kljuc imenuje jedinicu, sto odgovara konvenciji koju vec koriste vlastita polja trajanja u frameworku.
Notes (EN)
Keep a separate formatting helper for console output if you want '5ms' for humans; never let the formatted string be the only value you record.
Bilješke (HR)
Zadrzi zaseban pomocnik za formatiranje ako zelis '5ms' za ljude; nikad ne dopusti da formatirani string bude jedina vrijednost koju biljezis.