Skip to content

MetricsBehavior

Defined in: metrics.behavior.ts:150

Pipeline behavior that records OpenTelemetry metrics for every handler it wraps, complementing TraceBehavior’s spans:

  • pipeline.handler.duration — histogram (ms) of handler execution time;
  • pipeline.handler.invocations — counter incremented once per completed call;
  • pipeline.handler.active — current in-flight handler count.

The default label set is deliberately low-cardinality: pipeline.request.kind, pipeline.request.name, and pipeline.handler.name, plus outcome/error information when the call ends. Both outcome and the namespaced pipeline.outcome attribute are emitted for completed calls.

The OTel Metrics API is used directly. When no OpenTelemetry SDK / metric reader is registered, the API returns no-op instruments and recordings are discarded.

Instrument creation/recording and custom enrichment are best-effort: telemetry must not replace a successful business result or the original business error. A logger passed to the constructor, when present, reports instrumentation failures.

Global application metrics

createPipeline({
globalBehaviors: {
scope: 'all',
after: [MetricsBehavior],
},
});

Disable a very hot handler

class HealthCheckHandler {
@pipeline.wrap({ kind: 'query' }, [MetricsBehavior, { enabled: false }])
async handle(query: HealthCheckQuery) {}
}

new MetricsBehavior(logger?): MetricsBehavior

Defined in: metrics.behavior.ts:154

PipelineLogger

MetricsBehavior

handle(context, next): Promise<unknown>

Defined in: metrics.behavior.ts:156

IPipelineContext

NextDelegate

Promise<unknown>

IPipelineBehavior.handle