Automatic Metrics
What the SDK collects and how it works
Every protect() call records execution metrics automatically. Use protect() and metrics appear on your Openfuse dashboard. No setup required.
What's collected
| Metric | Description |
|---|---|
| Success count | Successful protect() executions |
| Failure count | Executions that threw an error |
| Timeout count | Executions that exceeded the timeout |
| Latency (p50) | Median execution time |
| Latency (p95) | 95th percentile execution time |
| Latency (p99) | 99th percentile execution time |
Window-based aggregation
Metrics are grouped into time windows (default: 10 seconds). Within each window, the SDK accumulates counts and collects latency samples.
Periodic flush
Every 15 seconds (default), the SDK sends completed windows to Openfuse in a single batch. In-progress windows are kept until they complete.
Reservoir sampling
To keep memory bounded, the SDK uses reservoir sampling to maintain a fixed number of latency samples per window (default: 1,000). This gives accurate percentile estimates at thousands of requests per second.
Instance deduplication
Each SDK instance has a unique ID to prevent double-counting. The SDK auto-detects your platform:
| Platform | Source |
|---|---|
| AWS Lambda | AWS_LAMBDA_LOG_STREAM_NAME |
| ECS | ECS_CONTAINER_METADATA_URI_V4 |
| Kubernetes | KUBERNETES_SERVICE_HOST + pod name |
| Google Cloud Run | K_SERVICE + K_REVISION |
| Fly.io | FLY_ALLOC_ID |
| Railway | RAILWAY_REPLICA_ID |
| Render | RENDER_INSTANCE_ID |
| Heroku | DYNO |
| Other | hostname-pid-random |
Override this with a custom instanceId in the client constructor.
Configure metrics
Default settings come from the server. Override them locally:
const openfuse = new OpenfuseCloud({
system: 'payments',
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
metrics: {
windowSizeMs: 10_000,
flushIntervalMs: 15_000,
maxLatencySamples: 1_000,
enabled: true,
},
})See Production for tuning advice.