Skip to content

feat: add env boolean normalizer helper and slow query fingerprint logging#360

Merged
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
leojay-net:feature/issue-342-343-env-bool-slow-query-fingerprint
May 29, 2026
Merged

feat: add env boolean normalizer helper and slow query fingerprint logging#360
Chucks1093 merged 1 commit into
accesslayerorg:mainfrom
leojay-net:feature/issue-342-343-env-bool-slow-query-fingerprint

Conversation

@leojay-net
Copy link
Copy Markdown
Contributor

@leojay-net leojay-net commented May 29, 2026

Summary

  • Add helper for normalizing boolean string values from environment config #342 — Adds normalizeEnvBoolean(varName, value) helper in src/utils/env-boolean.utils.ts that normalises all common boolean string representations from environment config (true, false, 1, 0, yes, no) into a real boolean. Throws EnvBooleanParseError with the var name and raw value included for any unrecognised input instead of silently defaulting.
  • Add structured log for slow database query with query fingerprint #343 — Extends the Prisma client in src/utils/prisma.utils.ts to emit a warn-level structured log whenever any database query exceeds SLOW_QUERY_THRESHOLD_MS. The log includes a normalised query fingerprint (model, operation, and arg structure with all leaf values replaced by ? — no parameter values), elapsed time, and request ID. The threshold is configurable via the new SLOW_QUERY_THRESHOLD_MS env var (default 500 ms).

Changes

File Description
src/utils/env-boolean.utils.ts New helper: normalizeEnvBoolean + EnvBooleanParseError
src/utils/env-boolean.utils.test.ts Unit tests: all accepted variants, case-insensitivity, whitespace trimming, error metadata
src/utils/prisma.utils.ts Slow query fingerprint logging added to $allOperations
src/config.schema.ts New SLOW_QUERY_THRESHOLD_MS Zod field (default 500)
.env.example Documents SLOW_QUERY_THRESHOLD_MS=500

Test plan

  • pnpm exec jest env-boolean — 28 tests pass covering every accepted variant (true/True/TRUE/1/yes/Yes/YES, false/False/FALSE/0/no/No/NO), whitespace trimming, unrecognised values (maybe, 2, on, "", …), and EnvBooleanParseError property shape
  • pnpm run lint — no new lint errors
  • Overall test suite (73 pre-existing failures due to Prisma not being generated and integration DB requirements) — no regressions introduced

Acceptance criteria

#342

  • All documented string variants normalised correctly
  • Unrecognised values produce EnvBooleanParseError rather than silently defaulting
  • Unit tests cover all accepted variants and unrecognised inputs

#343

  • Queries exceeding SLOW_QUERY_THRESHOLD_MS emit a warn-level log with fingerprint and elapsedMs
  • Parameter values are not present in the fingerprint (all leaf values replaced with ?)
  • Threshold is configurable without a code change (SLOW_QUERY_THRESHOLD_MS env var)

Closes #342
Closes #343
Closes #346
Closes #347

Adds a normalizeEnvBoolean() helper (issue accesslayerorg#342) that parses "true",
"false", "1", "0", "yes", and "no" from env vars into a real boolean
and throws EnvBooleanParseError for unrecognized values. Includes full
unit test coverage of all accepted variants and error cases.

Adds general-purpose slow database query logging to prisma.utils.ts
(issue accesslayerorg#343): any query exceeding SLOW_QUERY_THRESHOLD_MS emits a
warn-level structured log containing a normalized query fingerprint
(model + operation + arg structure, no parameter values), elapsed time,
and request ID. The threshold is configurable via env var (default 500ms).

Closes accesslayerorg#342
Closes accesslayerorg#343

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 29, 2026

@leojay-net Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Chucks1093 Chucks1093 merged commit 3501707 into accesslayerorg:main May 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants