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.
Example
Section titled “Example”class CreateAuthHandler { @pipeline.wrap({ kind: 'command' }, [MetricsBehavior, { meterName: 'users-api.auth', attributeFactory: () => ({ 'app.operation': 'login' }), }]) async handle(command: CreateAuthCommand) {}}Properties
Section titled “Properties”attributeFactory?
Section titled “attributeFactory?”
optionalattributeFactory?: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.
Example
Section titled “Example”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, }),}])enabled?
Section titled “enabled?”
optionalenabled?:boolean
Defined in: metrics.behavior.ts:57
Explicitly disable metrics for this handler while keeping the behavior registered globally.
Default
Section titled “Default”trueincludeContextAttributes?
Section titled “includeContextAttributes?”
optionalincludeContextAttributes?: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.
Default
Section titled “Default”falsemeterName?
Section titled “meterName?”
optionalmeterName?: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).
Default
Section titled “Default”'@cqrs-ddd/pipeline-opentelemetry'