Skip to content

assignMetrics

const assignMetrics: (config?) => Policy

Defined in: src/policies/observability/assign-metrics.ts:43

Attach metric tags to the request context for downstream consumers.

Tags are resolved (static or dynamic) and stored as a plain object at c.get("_metricsTags"). The metricsReporter policy (or any custom observer) can read these tags to enrich collected metrics.

AssignMetricsConfig

Must include tags — a record of tag names to values or resolver functions.

Policy

A Policy at priority 0 (OBSERVABILITY).

import { assignMetrics } from "@homegrower-club/stoma";
assignMetrics({
tags: {
service: "users-api",
region: (c) => c.req.header("cf-ipcountry") ?? "unknown",
},
});