Guard collectDefaultMetrics against duplicate registration

Importing metrics.server.ts from yjs-server.ts caused
collectDefaultMetrics() to re-register during HMR, crashing
the planner dev server. Check if metrics already exist first.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-04-03 09:15:15 +01:00
parent e083ee134d
commit a3ad073d96
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9

View file

@ -1,7 +1,10 @@
import client from "prom-client";
// Collect default Node.js metrics (event loop, heap, GC)
client.collectDefaultMetrics();
// Guard against duplicate registration during HMR
if (!client.register.getSingleMetric("process_cpu_user_seconds_total")) {
client.collectDefaultMetrics();
}
export const httpRequestDuration = new client.Histogram({
name: "http_request_duration_seconds",