Problem
The internal listener records no request duration.
The REST app times every route: app.use('*', httpMetricsMiddleware()) (apps/hocuspocus.server/src/index.ts:38). The internal Hono app does not (apps/hocuspocus.server/src/hocuspocus.server.ts:596-601), and it is served by its own Bun.serve (apps/hocuspocus.server/src/hocuspocus.server.ts:608).
That listener carries content apply, checkpoint and restore, on the port set by HOCUSPOCUS_INTERNAL_HTTP_PORT: numericString('4003') (apps/hocuspocus.server/src/config/env.schema.ts:49). Those calls run in the WebSocket process, beside the live Y.Doc, so they are the ones most able to stall other people's typing.
When someone reports a slow content apply, an operator has no latency number to look at.
What to do
Mount the same middleware on the internal app, right after it is created:
internalApp.use('*', httpMetricsMiddleware())
Add httpMetricsMiddleware to the existing ./lib/metrics import at apps/hocuspocus.server/src/hocuspocus.server.ts:21-34.
Acceptance
Notes
The histogram already carries a route label (apps/hocuspocus.server/src/lib/metrics.ts:28-30), so the new samples separate apply from checkpoint and restore with no extra work.
Problem
The internal listener records no request duration.
The REST app times every route:
app.use('*', httpMetricsMiddleware())(apps/hocuspocus.server/src/index.ts:38). The internal Hono app does not (apps/hocuspocus.server/src/hocuspocus.server.ts:596-601), and it is served by its ownBun.serve(apps/hocuspocus.server/src/hocuspocus.server.ts:608).That listener carries content apply, checkpoint and restore, on the port set by
HOCUSPOCUS_INTERNAL_HTTP_PORT: numericString('4003')(apps/hocuspocus.server/src/config/env.schema.ts:49). Those calls run in the WebSocket process, beside the live Y.Doc, so they are the ones most able to stall other people's typing.When someone reports a slow content apply, an operator has no latency number to look at.
What to do
Mount the same middleware on the internal app, right after it is created:
internalApp.use('*', httpMetricsMiddleware())Add
httpMetricsMiddlewareto the existing./lib/metricsimport atapps/hocuspocus.server/src/hocuspocus.server.ts:21-34.Acceptance
/metricsshows anhttp_request_duration_secondssample for that route./metricsitself still answers, because it is handled before the Hono dispatch.Notes
The histogram already carries a
routelabel (apps/hocuspocus.server/src/lib/metrics.ts:28-30), so the new samples separate apply from checkpoint and restore with no extra work.