/** * Correlation context store for observability. * * Provides Effect FiberRef-backed correlation context that flows across * Effect fibers, with AsyncLocalStorage bridge for non-Effect consumers. * * @module src/core/observability/context */ import { FiberRef, Effect } from 'effect'; /** * Correlation context fields that flow across all spans, logs, and hooks. */ export interface CorrelationContext { /** Unique identifier for this run */ runId: string; /** Conversation identifier */ conversationId?: string; /** Intent identifier */ intentId?: string; /** Agent identifier */ agentId?: string; /** ISO 8601 timestamp when context was created */ timestamp: string; /** OpenTelemetry trace ID (populated from active span context) */ traceId?: string; /** OpenTelemetry span ID (populated from active span context) */ spanId?: string; /** OpenTelemetry parent span ID (populated from active span context) */ parentSpanId?: string; /** Pipeline identifier (optional, for pipeline runs) */ pipelineId?: string; /** Step name (optional, for pipeline steps) */ stepName?: string; } /** * FiberRef instance for correlation context (Effect-based source of truth). */ export declare const CorrelationContextRef: FiberRef.FiberRef; /** * Generate a new correlation context. * * @param options - Context options (runId is required, others optional) * @returns Correlation context object */ export declare function createCorrelationContext(options: { runId: string; conversationId?: string; intentId?: string; agentId?: string; pipelineId?: string; stepName?: string; }): CorrelationContext; /** * Get correlation context from Effect FiberRef. * * @returns Effect yielding the current correlation context (or undefined) */ export declare const getCorrelationContext: Effect.Effect; /** * Get the current correlation context (synchronous, backward-compatible). * * Reads from AsyncLocalStorage bridge for non-Effect consumers. * Returns undefined if no context is active. */ export declare function getCurrentCorrelationContext(): CorrelationContext | undefined; /** * Run an Effect with correlation context active. * * Sets both FiberRef (Effect source of truth) and AsyncLocalStorage bridge * (for non-Effect consumers). * * @param ctx - Correlation context to activate * @returns Effect combinator that wraps execution * * @example * ```typescript * const ctx = createCorrelationContext({ runId: 'run-123' }); * const program = withCorrelationContext(ctx)( * Effect.gen(function* () { * const currentCtx = yield* getCorrelationContext; * console.log(currentCtx?.runId); // 'run-123' * }) * ); * const tracedProgram = program.pipe( * Effect.tap(() => Effect.logDebug('context active')) * ); * ``` */ export declare function withCorrelationContext(ctx: CorrelationContext): (effect: Effect.Effect) => Effect.Effect; /** * Get current OpenTelemetry span IDs from Effect.currentSpan. * * @returns Effect yielding traceId, spanId, parentSpanId (if available) */ export declare const getSpanIds: Effect.Effect<{ traceId?: string; spanId?: string; parentSpanId?: string; }>; /** * Get current OpenTelemetry span IDs (synchronous, backward-compatible). * * Reads from AsyncLocalStorage bridge context (populated by consumers). * Returns empty object if no span context available. * * @returns Object with traceId, spanId, parentSpanId (if available) */ export declare function getCurrentSpanIds(): { traceId?: string; spanId?: string; parentSpanId?: string; }; //# sourceMappingURL=context.d.ts.map