function createMetricsHook
createMetricsHook(collector: { record: (
name: string,
durationMs: number,
rulesDiff: number,
) => void
; }
): TransformationHookConfig

Create a hook configuration that records per-transformation timing and rule-count diff data to an arbitrary metrics collector.

Only an afterTransform hook is registered — metrics are recorded after each transformation completes, capturing wall-clock duration and the net change in rule count (inputCount - outputCount).

Examples

Example 1

const timings: Record<string, number> = {};
const collector = {
  record: (name, durationMs) => { timings[name] = durationMs; },
};
const mgr = new TransformationHookManager(createMetricsHook(collector));
const compiler = new FilterCompiler({ hookManager: mgr });
await compiler.compile(config);
console.log(timings); // { RemoveComments: 1.4, Deduplicate: 22.7, … }

Parameters

collector: { record: (
name: string,
durationMs: number,
rulesDiff: number,
) => void
; }
  • Any object with a record(name, durationMs, rulesDiff) method. Wire this to Prometheus, StatsD, OpenTelemetry, a simple in-memory store, or any custom sink.

Return Type

A TransformationHookConfig ready to pass to new TransformationHookManager(config).

Usage

import { createMetricsHook } from ".";