Skip to content

MetricsBehaviorOptions

Defined in: metrics.behavior.ts:42

Per-handler metrics options for MetricsBehavior.

Keep metric attributes low-cardinality; use traces/logs for per-user/request identifiers.

class CreateAuthHandler {
@pipeline.wrap({ kind: 'command' }, [MetricsBehavior, {
meterName: 'users-api.auth',
attributeFactory: () => ({ 'app.operation': 'login' }),
}])
async handle(command: CreateAuthCommand) {}
}

optional attributeFactory?: PipelineTelemetryAttributeFactory

Defined in: metrics.behavior.ts:78

Additional request-aware metric attributes. Factory failures are ignored so telemetry cannot make the business request fail.

Cardinality rule: metric attributes should normally be bounded values such as region, deployment, plan, operation category, or feature name. Do not put correlation IDs, user IDs, order IDs, email addresses, or arbitrary request values into metric labels.

Safe bounded labels

@pipeline.wrap({ kind: 'query' }, [MetricsBehavior, {
attributeFactory: (ctx) => ({
'app.region': process.env.REGION ?? 'unknown',
'app.tenant_tier': ctx.items.get('tenantTier') as string,
}),
}])

optional enabled?: boolean

Defined in: metrics.behavior.ts:57

Explicitly disable metrics for this handler while keeping the behavior registered globally.

true

optional includeContextAttributes?: boolean

Defined in: metrics.behavior.ts:90

Include the request-local attribute bag populated through addPipelineTelemetryAttributes() in metric labels.

This is disabled by default because request-local bags may contain correlation IDs, user IDs or other unbounded values. Enable it only when your application controls that bag and guarantees bounded cardinality.

false

optional meterName?: string

Defined in: metrics.behavior.ts:49

Name of the OpenTelemetry meter the instruments are created on (shown in your metrics backend, e.g. Prometheus / SigNoz / Datadog).

'@cqrs-ddd/pipeline-opentelemetry'