Skip to content

configureCorrelation

configureCorrelation(policy?): void

Defined in: policy/correlation.policy.ts:113

Sets the rules every incoming correlation id must pass, for the whole process: httpCorrelation, runWithCorrelationId, @WithCorrelation and correlationSource.accepts, which job contexts use. Call it once at startup, before the first request. Each call replaces every rule.

Until it is called, httpCorrelation and correlationSource.accepts apply the default rules, and runWithCorrelationId and @WithCorrelation apply only the built-in check. Once it is called, even with an empty policy, every entry point applies its rules. A call without a policy restores the state before the first call.

Whatever the rules, an id must first be printable ASCII (0x20 to 0x7E) that neither starts nor ends with a space, and nothing turns that check off. A rejected id is replaced by the current or a new one and reported to onRejected; a missing or empty id is replaced without a report. The maxLength and validateIncoming options of httpCorrelation, when given, replace these rules for that middleware.

CorrelationPolicy

The rules; an omitted field takes its default. Omit the policy to restore the state before the first call.

void

When maxLength is not a positive safe integer.

configureCorrelation({
  validateIncoming: (id) => /^[0-9a-f-]{36}$/i.test(id),
  onRejected: ({ reason, source, length }) =>
    logger.warn({ reason, source, length }, 'correlation id replaced'),
});