Skip to content

feat: add duration logging to WS, MediaWiki, geocoding, and queue operations#93

Merged
DaxServer merged 3 commits into
mainfrom
feat/operation-timing-logs
Jun 7, 2026
Merged

feat: add duration logging to WS, MediaWiki, geocoding, and queue operations#93
DaxServer merged 3 commits into
mainfrom
feat/operation-timing-logs

Conversation

@DaxServer

Copy link
Copy Markdown
Owner
  • Export elapsed(start: bigint) and formatDuration(ns: number) from logger.ts as shared timing utilities
  • Log duration for all 13 request-response WS message types in ws.ts (subscriptions excluded); format: [ws] MESSAGE_TYPE from username | 45ms
  • Log duration for all MediaWiki operations in client.ts: createPage, getCategoryMembers, uploadFile, applySdc, nullEdit, replaceCategoryInPage
  • Log duration for reverse geocoding batch in geocoding.ts
  • Normalise queue delay logging from raw ms to human-readable units (ms/s/min/h) via formatDelayMs in queue.ts, reused in upload.worker.ts
  • Remove unnecessary LogStore type and (store as LogStore) casts — Elysia infers store type correctly through method chaining

— Claude Sonnet 4.6

DaxServer and others added 2 commits June 7, 2026 18:25
…rations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — all changes are additive logging instrumentation with no mutations to business logic.

Every change is a timing/logging addition: new timestamps, string formatting helpers, and log lines. No data paths, persistence operations, or auth flows are altered. The WeakMap approach for request timings is correct. The try/catch in ws.ts correctly re-throws after logging, preserving existing error propagation. Tests are updated to mock the new formatDelayMs export.

No files require special attention.

Important Files Changed

Filename Overview
backend/src/core/logger.ts Exports elapsed/formatDuration as shared timing utilities; replaces store-based timing with a module-level WeakMap keyed on Request objects; removes LogStore type and casts; adds plugin-level .as('global').
backend/src/routes/ws.ts Message handler made async; all 13 message types now awaited; duration logged on success; try/catch added to log duration on error paths and re-throw; subscription cases intentionally excluded.
backend/src/mediawiki/client.ts Duration logging added to createPage, getCategoryMembers (covers full pagination loop), uploadFile, applySdc, nullEdit (covers retries), and replaceCategoryInPage.
backend/src/workers/queue.ts New exported formatDelayMs converts raw millisecond delays to human-readable units (ms/s/min/h); replaces raw ms value in the enqueue log line.
backend/src/core/geocoding.ts Timer added around Promise.all for the geocoding batch; duration appended to the completion log line.
backend/src/workers/upload.worker.ts Imports and uses formatDelayMs for the StorageError requeue delay log; no functional changes.
backend/src/tests/admin.test.ts Adds formatDelayMs to the queue mock so the module resolves correctly after the export was added.
backend/src/tests/ws.handler.test.ts Same mock addition as admin.test.ts for formatDelayMs.
backend/src/tests/uploadClient.test.ts Import reformatting and uploadFile call reformatting only; no logic changes.

Reviews (2): Last reviewed commit: "fix: use WeakMap for request timing to f..." | Re-trigger Greptile

Comment thread backend/src/routes/ws.ts
…r timing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@DaxServer

Copy link
Copy Markdown
Owner Author

Addressed both issues:

  1. 404 duration fix: replaced store.beforeTime + broken onRequest with a module-level WeakMap<Request, bigint>. onRequest (no inline scope arg) now records the start time for every request — including unmatched ones — and .as('global') on the plugin lifts it to the parent app. onError looks up the timing from the map, so 404s show accurate durations instead of the server uptime.

  2. WS error timing: wrapped the switch in try/catch; handler exceptions now log [ws] TYPE from user | Xms (error) before rethrowing, so latency data is always emitted regardless of outcome.

— Claude Sonnet 4.6

@DaxServer DaxServer merged commit f307b2c into main Jun 7, 2026
9 checks passed
@DaxServer DaxServer deleted the feat/operation-timing-logs branch June 7, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant