Observability

Goal: Production monitoring and resilience.

Prometheus metrics

import { live } from 'svelte-realtime/server';
import { createMetricsRegistry } from 'svelte-adapter-uws-extensions/prometheus';

const registry = createMetricsRegistry();
live.metrics(registry);

This registers:

MetricTypeDescription
svelte_realtime_rpc_totalcounterRPC call count by path and status
svelte_realtime_rpc_duration_secondshistogramRPC latency by path
svelte_realtime_rpc_errors_totalcounterRPC errors by path and code
svelte_realtime_stream_subscriptionsgaugeActive stream subscriptions by topic
svelte_realtime_cron_totalcounterCron execution count
svelte_realtime_cron_errors_totalcounterCron errors by path

Zero overhead when not called.

Circuit breaker

Wrap external dependencies so failures don’t cascade.

import { createBreaker } from 'svelte-adapter-uws-extensions/breaker';

const dbBreaker = createBreaker({
  threshold: 5,     // open after 5 consecutive failures
  resetMs: 30000    // try again after 30 seconds
});

export const items = live.stream('items',
  live.breaker({ breaker: dbBreaker, fallback: [] }, async (ctx) => {
    return db.items.list();
  })
);

When the database is down, subscribers get [] instead of errors. The breaker auto-resets after 30 seconds.

What to monitor in production

  • RPC latency - p99 should stay under 50ms for most handlers
  • Stream subscription count - tracks how many clients are connected to each topic
  • Error rates - spike = something broke
  • Connection count - uWebSockets.js handles thousands, but watch for leaks
  • Memory - process.memoryUsage() - watch for unbounded growth in replay buffers

Was this page helpful?