import { Effect } from "effect"; import { getCurrentSmithersTraceAnnotations } from "../observability"; import { runFork } from "./runtime"; import { correlationContextToLogAnnotations, getCurrentCorrelationContext, withCurrentCorrelationContext, } from "../observability/correlation"; type LogAnnotations = Record | undefined; function emitLog( effect: Effect.Effect, annotations?: LogAnnotations, span?: string, ) { const correlationAnnotations = correlationContextToLogAnnotations( getCurrentCorrelationContext(), ); const traceAnnotations = getCurrentSmithersTraceAnnotations(); const mergedAnnotations = correlationAnnotations || traceAnnotations || annotations ? { ...correlationAnnotations, ...traceAnnotations, ...annotations, } : undefined; let program = effect; if (mergedAnnotations) { program = program.pipe(Effect.annotateLogs(mergedAnnotations)); } if (span) { program = program.pipe(Effect.withLogSpan(span)); } void runFork(withCurrentCorrelationContext(program)); } export function logDebug( message: string, annotations?: LogAnnotations, span?: string, ) { emitLog(Effect.logDebug(message), annotations, span); } export function logInfo( message: string, annotations?: LogAnnotations, span?: string, ) { emitLog(Effect.logInfo(message), annotations, span); } export function logWarning( message: string, annotations?: LogAnnotations, span?: string, ) { emitLog(Effect.logWarning(message), annotations, span); } export function logError( message: string, annotations?: LogAnnotations, span?: string, ) { emitLog(Effect.logError(message), annotations, span); }