BunRuntimeMetrics

Collect Bun runtime health metrics such as memory usage, CPU utilization, and event loop utilization.

Import name: Sentry.bunRuntimeMetricsIntegration

The bunRuntimeMetricsIntegration periodically collects Bun runtime health metrics and sends them to Sentry. Metrics include memory usage, CPU utilization, event loop utilization, and process uptime.

Copied
import * as Sentry from "@sentry/bun";

Sentry.init({
  dsn: "___PUBLIC_DSN___",
  integrations: [Sentry.bunRuntimeMetricsIntegration()],
});

The following metrics are emitted every 30 seconds by default:

MetricTypeUnitDescription
bun.runtime.mem.rssgaugebyteResident Set Size — actual process memory footprint
bun.runtime.mem.heap_usedgaugebyteHeap memory currently in use
bun.runtime.mem.heap_totalgaugebyteTotal heap memory allocated
bun.runtime.cpu.utilizationgaugeratioCPU time / wall-clock time ratio
bun.runtime.event_loop.utilizationgaugeratioFraction of time the event loop was active
bun.runtime.process.uptimecountersecondCumulative process uptime

Type: object

Configure which metrics to collect. You can enable opt-in metrics or disable default ones.

Opt-in metrics (off by default):

Copied
Sentry.bunRuntimeMetricsIntegration({
  collect: {
    cpuTime: true, // bun.runtime.cpu.user + bun.runtime.cpu.system
    memExternal: true, // bun.runtime.mem.external + bun.runtime.mem.array_buffers
  },
});

Disabling default metrics:

Copied
Sentry.bunRuntimeMetricsIntegration({
  collect: {
    uptime: false,
    eventLoopUtilization: false,
  },
});

Type: number

The interval in milliseconds between metric collections. Defaults to 30000 (30 seconds).

Copied
Sentry.bunRuntimeMetricsIntegration({
  collectionIntervalMs: 60_000,
});
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").