-
Notifications
You must be signed in to change notification settings - Fork 24
Replace console.time/timeEnd with a structured logger for production observability #73
Copy link
Copy link
Open
Description
Background
In PR #71 (and issue #69), console.time()/console.timeEnd() calls in apps/public-api/src/controllers/data.controller.js were gated behind process.env.DEBUG === 'true' as a pragmatic short-term fix.
However, console.time is a dev/debug utility and is not recommended for production-grade applications for the following reasons:
- Overhead: It stores start times in an internal map using the label as the key, adds string formatting on every call.
- Concurrency bug: Concurrent requests sharing the same label (e.g.,
"insert data") overwrite each other's timer start times, producing inaccurate measurements under load. - Not log-level aware: Cannot be silenced or routed through a log aggregation pipeline.
Goal
Replace console.time/console.timeEnd (and potentially other bare console.* calls) with a structured logger that supports log levels, so performance/debug tracing integrates cleanly with the application's observability pipeline.
Suggested options
| Use Case | Recommended Tool |
|---|---|
| Quick per-request timing | performance.now() or process.hrtime.bigint() |
| Structured logging with log levels | pino or winston |
| Full APM/distributed tracing | OpenTelemetry, Datadog, New Relic |
Acceptance criteria
- No bare
console.time/console.timeEndcalls remain inapps/public-api/src/ - A structured logger (e.g., pino or winston) is introduced with appropriate log levels (
debug,info,warn,error) - Performance timing is done with
performance.now()orprocess.hrtime.bigint()with unique per-request identifiers to avoid concurrency issues - Existing tests continue to pass
References
- Fixes follow-up from PR Gate console.time/timeEnd performance logs behind DEBUG flag in data … #71
- Original issue: Remove/guard console.time() performance logs in data controller #69
- Requested by: @yash-pouranik
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels