buildRateLimitAttributes
buildRateLimitAttributes(
context):Record<string,number>
Defined in: packages/pipeline-rate-limit/src/helpers/build-attributes.ts:50
The rate-limit decision of one execution as flat attributes:
rate_limit.remaining_points once RateLimitBehavior consumed points and the
limiter reported what remains, {} otherwise. The key is never included: it
carries the tenant and the caller.
The result is plain data and needs no telemetry package: put it on a span, a log line, an audit record or a metric label (bounded values only). The remaining points take as many values as the limiter has points; keep them out of metric labels unless that is bounded enough.
Parameters
Section titled “Parameters”context
Section titled “context”The pipeline execution, read after RateLimitBehavior ran.
Returns
Section titled “Returns”Record<string, number>
The attributes; empty when the behavior did not run.
Examples
Section titled “Examples”Span attributes
With AttributesBehavior of @cqrs-ddd/pipeline-opentelemetry:
createPipeline({ globalBehaviors: { before: [TraceBehavior, [AttributesBehavior, { factories: [buildRateLimitAttributes] }]], },});Audit metadata
audit() is declared outside rateLimit(), so the record is built after its decision:
@pipeline.wrap( { kind: 'command' }, audit({ action: 'order.create', metadata: buildRateLimitAttributes }), rateLimit({ keyFactory, points: 1 }),)A log line from a custom behavior, after the chain ran
async handle(context: IPipelineContext, next: NextDelegate) { try { return await next(); } finally { this.logger.log({ request: context.requestName, ...buildRateLimitAttributes(context) }); }}