Files
smom-dbis-138/packages/integration-foundation/src/observability/correlation.ts
defiQUG d717b504a6
Some checks failed
CI/CD Pipeline / Solidity Contracts (push) Failing after 1m12s
CI/CD Pipeline / Security Scanning (push) Successful in 2m21s
CI/CD Pipeline / Lint and Format (push) Failing after 36s
CI/CD Pipeline / Terraform Validation (push) Failing after 22s
CI/CD Pipeline / Kubernetes Validation (push) Successful in 25s
HYBX OMNL TypeScript & anchor / token-aggregation build + reconcile artifact (push) Failing after 23s
Validation / validate-genesis (push) Successful in 26s
Validation / validate-terraform (push) Failing after 21s
Validation / validate-kubernetes (push) Failing after 9s
Validation / validate-smart-contracts (push) Failing after 8s
Validation / validate-security (push) Failing after 1m15s
Validation / validate-documentation (push) Failing after 15s
OMNL reconcile anchor / Run omnl:reconcile and upload artifacts (push) Failing after 26s
Verify Deployment / Verify Deployment (push) Failing after 56s
feat(omnl): settlement terminal, compliance gates, and HYBX integration foundation
Add operator settlement terminal UI/API, swift-listener service, compliance
idempotency gates, GRU reserve dashboards, and @dbis/integration-foundation
for typed HYBX/ISO adapter contracts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-07 21:51:32 -07:00

46 lines
1.2 KiB
TypeScript

import { randomUUID } from 'crypto';
export const CORRELATION_ID_HEADER = 'x-correlation-id';
export const REQUEST_ID_HEADER = 'x-request-id';
export function generateCorrelationId(): string {
return randomUUID();
}
export function generateRequestId(): string {
return `req-${randomUUID()}`;
}
export type CorrelationContext = {
correlationId: string;
requestId: string;
tenantId?: string;
entityId?: string;
};
function orGenerated(value: string | undefined, fallback: () => string): string {
const v = value?.trim();
return v ? v : fallback();
}
export function createCorrelationContext(
partial?: Partial<CorrelationContext>
): CorrelationContext {
return {
correlationId: orGenerated(partial?.correlationId, generateCorrelationId),
requestId: orGenerated(partial?.requestId, generateRequestId),
tenantId: partial?.tenantId,
entityId: partial?.entityId,
};
}
export function correlationHeaders(ctx: CorrelationContext): Record<string, string> {
const headers: Record<string, string> = {
[CORRELATION_ID_HEADER]: ctx.correlationId,
[REQUEST_ID_HEADER]: ctx.requestId,
};
if (ctx.tenantId) headers['x-tenant-id'] = ctx.tenantId;
if (ctx.entityId) headers['x-entity-id'] = ctx.entityId;
return headers;
}