Skip to content

Replace console.time/timeEnd with a structured logger for production observability #73

@coderabbitai

Description

@coderabbitai

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.timeEnd calls remain in apps/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() or process.hrtime.bigint() with unique per-request identifiers to avoid concurrency issues
  • Existing tests continue to pass

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions