import { Core , DefaultLogger , Worker , InjectedSinks } from '@temporalio/worker' ; import { LoggerSinks } from './workflows/logger' ; import * as activities from './activities' ; import { ActivityInboundLogInterceptor } from './activities/interceptors' ; import { createLogger } from './logging' ; const logger = createLogger ( { isProduction : process . env . NODE_ENV === 'production' , logFilePath : process . env . WORKER_LOG_PATH || '/var/log/worker.log' , } ) ; async function main ( ) { const workerLogger = logger . child ( { label : 'worker' } ) ; const workflowLogger = logger . child ( { label : 'workflow' } ) ; const activityLogger = logger . child ( { label : 'activity' } ) ; await Core . install ( { logger : new DefaultLogger ( 'DEBUG' , ( entry ) => { workerLogger . log ( { level : entry . level . toLowerCase ( ) , message : entry . message , timestamp : Number ( entry . timestampNanos / 1000000n ) , ... entry . meta , } ) ; } ) , telemetryOptions : { prometheusMetricsBindAddress : '0.0.0.0:9464' , tracingFilter : 'temporal_sdk_core=DEBUG' , logForwardingLevel : 'DEBUG' , } , } ) ; const sinks = { logger : { debug : { fn ( workflowInfo , message , meta ) { workflowLogger . child ( workflowInfo ) . debug ( message , meta ) ; } , } , info : { fn ( workflowInfo , message , meta ) { workflowLogger . child ( workflowInfo ) . info ( message , meta ) ; } , } , error : { fn ( workflowInfo , message , meta ) { workflowLogger . child ( workflowInfo ) . error ( message , meta ) ; } , } , warn : { fn ( workflowInfo , message , meta ) { workflowLogger . child ( workflowInfo ) . warn ( message , meta ) ; } , } , } , } ; const worker = await Worker . create ( { workflowsPath : require . resolve ( './workflows' ) , activities , taskQueue : 'instrumentation' , interceptors : { activityInbound : [ ( ctx ) => new ActivityInboundLogInterceptor ( ctx , activityLogger ) ] , workflowModules : [ require . resolve ( './workflows/interceptors' ) ] , } , sinks , } ) ; await worker . run ( ) ; } main ( ) . then ( ( ) => void process . exit ( 0 ) , ( err ) => { logger . error ( 'Process failed' , err ) ; process . exit ( 1 ) ; } ) ;