feat(p9): propagate trace id into emitted events + structured relay/gateway logs
Task O.2: ai/calendar/route/ingest emit sites now stamp traceparent + insignia. correlationId from interaction.traceId ?? currentTraceId() ?? generated (mirroring message.send; inbox/inbound already carried correlationId). toTraceparent is hex-safe (UUID used as-is, other ids hashed). OutboxRelay logs a structured relay.publish per event (eventType/aggregateId/correlationId); MessageGateway logs ws.deliver. Tests: an event's correlationId equals the active request trace, with a generated fallback. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
InferencePort,
|
||||
InferenceResult,
|
||||
} from '@insignia/iios-contracts';
|
||||
import { currentTraceId, newTraceId, toTraceparent } from '../observability/trace-context';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { PLATFORM_PORTS } from '../platform/platform-ports';
|
||||
import { decideOrThrow } from '../platform/fail-closed';
|
||||
@@ -222,6 +223,7 @@ export class AiJobService {
|
||||
}
|
||||
|
||||
private async emit(type: string, scopeId: string, aggregateId: string, data: Record<string, unknown>): Promise<void> {
|
||||
const tid = currentTraceId() ?? newTraceId();
|
||||
const event: CloudEvent = {
|
||||
specversion: '1.0',
|
||||
id: `evt_ai_${aggregateId}_${type.split('.').slice(-2, -1)[0]}`,
|
||||
@@ -230,7 +232,8 @@ export class AiJobService {
|
||||
subject: `ai_artifact/${aggregateId}`,
|
||||
time: new Date().toISOString(),
|
||||
datacontenttype: 'application/json',
|
||||
insignia: { scopeSnapshotId: scopeId, idempotencyKey: `${type}:${aggregateId}`, dataClass: 'internal' },
|
||||
traceparent: toTraceparent(tid),
|
||||
insignia: { scopeSnapshotId: scopeId, correlationId: tid, idempotencyKey: `${type}:${aggregateId}`, dataClass: 'internal' },
|
||||
data,
|
||||
};
|
||||
await this.prisma.iiosOutboxEvent.create({
|
||||
|
||||
Reference in New Issue
Block a user