Metrics Docs
JavaScript Client
Use @distlang/client to record and flush metrics from JavaScript apps, workers, and handlers.
Install
npm install @distlang/client
Recommended starting point
For application instrumentation, start with client.metrics.createRecorder(...).
import { createDistlangClient } from "@distlang/client";
const client = createDistlangClient();
const metrics = client.metrics.createRecorder({
accessToken: process.env.DISTLANG_ACCESS_TOKEN,
metricSet: "app-echo-metrics",
definitions: {
requestCount: "counter",
latencyMs: "histogram",
},
});
metrics.requestCount.inc();
metrics.latencyMs.observe(42);
await metrics.flush();
The recorder lazily ensures the metric set, buffers writes in memory, and sends all pending rows when you call flush().
Definitions and metric sets
metricSetgroups related metrics for one app or servicedefinitionsdeclares the metric names and kinds you plan to write- the common starting kinds are
counterandhistogram
Pick metric set names that stay stable over time, for example api-gateway, checkout-service, or edge-cache.
Labels
Use labels for small bounded dimensions such as:
statusmethodoperationresult
Avoid high-cardinality values such as:
- user IDs
- request IDs
- raw URLs
- unbounded tenant names
Flushing in request-scoped code
Request handlers and short-lived jobs should flush before they return.
const startedAt = Date.now();
metrics.requestCount.inc({ method: "GET", status: "200" });
metrics.latencyMs.observe(Date.now() - startedAt, { method: "GET" });
await metrics.flush();