Skip to content

Latest commit

 

History

History

custom-logger

Customer Logger demo

This project demonstrates how to capture log entries produced by Workers, Workflows and Activities, and process them using a third party logging libraries (in this case, the Winston package).

The Logging docs explain some of the code in this sample.

Running this sample

  1. temporal server start-dev to start Temporal Server.
  2. npm install to install dependencies.
  3. npm run start.watch to start the Worker.
  4. In another shell, npm run workflow to run the Workflow.
Sample worker output
2023-09-05T18:19:39.646Z [worker] info: Creating worker {
  options: {
    namespace: 'default',
    identity: '1234@MyComputer',
    useVersioning: false,
    buildId: undefined,
    shutdownGraceTime: 0,
    maxConcurrentLocalActivityExecutions: 100,
    enableNonLocalActivities: true,
    maxConcurrentWorkflowTaskPolls: 10,
    maxConcurrentActivityTaskPolls: 10,
    stickyQueueScheduleToStartTimeout: '10s',
    maxHeartbeatThrottleInterval: '60s',
    defaultHeartbeatThrottleInterval: '30s',
    isolateExecutionTimeout: '5s',
    workflowThreadPoolSize: 2,
    maxCachedWorkflows: 914,
    showStackTraceSources: false,
    debugMode: false,
    workflowsPath: '/Users/user/samples-typescript/custom-logger/src/workflows/index.ts',
    activities: { greet: [AsyncFunction: greet] },
    taskQueue: 'custom-logger',
    maxConcurrentWorkflowTaskExecutions: 40,
    maxConcurrentActivityTaskExecutions: 100,
    shutdownGraceTimeMs: 0,
    shutdownForceTimeMs: undefined,
    stickyQueueScheduleToStartTimeoutMs: 10000,
    isolateExecutionTimeoutMs: 5000,
    maxHeartbeatThrottleIntervalMs: 60000,
    defaultHeartbeatThrottleIntervalMs: 30000,
    loadedDataConverter: {
      payloadConverter: DefaultPayloadConverter {
        converterByEncoding: Map(3) {
          'binary/null' => [UndefinedPayloadConverter],
          'binary/plain' => [BinaryPayloadConverter],
          'json/plain' => [JsonPayloadConverter]
        },
        converters: [
          [UndefinedPayloadConverter],
          [BinaryPayloadConverter],
          [JsonPayloadConverter]
        ]
      },
      failureConverter: DefaultFailureConverter {
        options: { encodeCommonAttributes: false }
      },
      payloadCodecs: []
    }
  }
}
2023-09-05T18:19:40.084Z [worker] info: asset workflow-bundle-95e3c04c487ab5112957.js 755 KiB [emitted] [immutable] (name: main)
2023-09-05T18:19:40.084Z [worker] info: runtime modules 937 bytes 4 modules
2023-09-05T18:19:40.084Z [worker] info: modules by path ./node_modules/@temporalio/ 182 KiB
2023-09-05T18:19:40.084Z [worker] info:   modules by path ./node_modules/@temporalio/common/lib/ 77.9 KiB 21 modules
2023-09-05T18:19:40.084Z [worker] info:   modules by path ./node_modules/@temporalio/workflow/ 102 KiB
2023-09-05T18:19:40.084Z [worker] info:     ./node_modules/@temporalio/workflow/lib/worker-interface.js 11 KiB [built] [code generated]
2023-09-05T18:19:40.084Z [worker] info:     + 13 modules
2023-09-05T18:19:40.084Z [worker] info:   ./node_modules/@temporalio/worker/lib/workflow-log-interceptor.js 2.42 KiB [built] [code generated]
2023-09-05T18:19:40.084Z [worker] info: modules by path ./src/workflows/ 878 bytes
2023-09-05T18:19:40.084Z [worker] info:   ./src/workflows/index-autogenerated-entrypoint.cjs 597 bytes [built] [code generated]
2023-09-05T18:19:40.084Z [worker] info:   ./src/workflows/index.ts 281 bytes [built] [code generated]
2023-09-05T18:19:40.084Z [worker] info: __temporal_custom_payload_converter (ignored) 15 bytes [built] [code generated]
2023-09-05T18:19:40.084Z [worker] info: __temporal_custom_failure_converter (ignored) 15 bytes [built] [code generated]
2023-09-05T18:19:40.084Z [worker] info: ./node_modules/long/umd/index.js 43.1 KiB [built] [code generated]
2023-09-05T18:19:40.084Z [worker] info: ./node_modules/ms/dist/index.cjs 3.41 KiB [built] [code generated]
2023-09-05T18:19:40.084Z [worker] info: webpack 5.88.2 compiled successfully in 264 ms
2023-09-05T18:19:40.085Z [worker] info: Workflow bundle created { size: '0.74MB' }
2023-09-05T18:19:40.165Z [worker] info: Initializing worker
2023-09-05T18:19:40.166Z [worker] info: Worker state changed { state: 'RUNNING' }
2023-09-05T18:19:51.963Z [worker] debug: New WFT
2023-09-05T18:19:51.963Z [worker] debug: Applying new workflow task from server
2023-09-05T18:19:51.963Z [worker] debug: Driven WF start
2023-09-05T18:19:51.963Z [worker] debug: Sending activation to lang
2023-09-05T18:19:51.987Z [workflow] debug: Workflow started {
  namespace: 'default',
  taskQueue: 'custom-logger',
  workflowId: 'workflow-2YriOlmgK2vMT-rhRFQQp',
  runId: 'fa0b415b-ef89-434d-839c-ec031d31668e',
  workflowType: 'logSampleWorkflow'
}
2023-09-05T18:19:51.987Z [worker] debug: wf bridge iteration fetch
2023-09-05T18:19:51.987Z [worker] debug: handling command
2023-09-05T18:19:51.987Z [worker] debug: prepared commands
2023-09-05T18:19:51.987Z [worker] debug: Sending responses to server
2023-09-05T18:19:51.989Z [worker] debug: Server returned 1 fewer activities for eager execution than we requested
2023-09-05T18:19:51.989Z [worker] debug: Marking WFT completed
2023-09-05T18:19:51.994Z [workflow] debug: Activity started {
  isLocal: false,
  attempt: 1,
  namespace: 'default',
  taskToken: 'CiRjZGNlMGM2Mi1mYzdjLTQyODctOGM2MC1kNWYwOWIzNDhjMWESHndvcmtmbG93LTJZcmlPbG1nSzJ2TVQtcmhSRlFRcBokZmEwYjQxNWItZWY4OS00MzRkLTgzOWMtZWMwMzFkMzE2NjhlIAUoATIBMUIFZ3JlZXRKCAgBEPKUQxgB',
  workflowId: 'workflow-2YriOlmgK2vMT-rhRFQQp',
  workflowRunId: 'fa0b415b-ef89-434d-839c-ec031d31668e',
  workflowType: 'logSampleWorkflow',
  activityId: '1',
  activityType: 'greet',
  taskQueue: 'custom-logger'
}
2023-09-05T18:19:51.994Z [activity] info: Log from activity {
  isLocal: false,
  attempt: 1,
  namespace: 'default',
  taskToken: 'CiRjZGNlMGM2Mi1mYzdjLTQyODctOGM2MC1kNWYwOWIzNDhjMWESHndvcmtmbG93LTJZcmlPbG1nSzJ2TVQtcmhSRlFRcBokZmEwYjQxNWItZWY4OS00MzRkLTgzOWMtZWMwMzFkMzE2NjhlIAUoATIBMUIFZ3JlZXRKCAgBEPKUQxgB',
  workflowId: 'workflow-2YriOlmgK2vMT-rhRFQQp',
  workflowRunId: 'fa0b415b-ef89-434d-839c-ec031d31668e',
  workflowType: 'logSampleWorkflow',
  activityId: '1',
  activityType: 'greet',
  taskQueue: 'custom-logger',
  name: 'Temporal'
}
2023-09-05T18:19:51.994Z [activity] debug: Activity completed {
  isLocal: false,
  attempt: 1,
  namespace: 'default',
  taskToken: 'CiRjZGNlMGM2Mi1mYzdjLTQyODctOGM2MC1kNWYwOWIzNDhjMWESHndvcmtmbG93LTJZcmlPbG1nSzJ2TVQtcmhSRlFRcBokZmEwYjQxNWItZWY4OS00MzRkLTgzOWMtZWMwMzFkMzE2NjhlIAUoATIBMUIFZ3JlZXRKCAgBEPKUQxgB',
  workflowId: 'workflow-2YriOlmgK2vMT-rhRFQQp',
  workflowRunId: 'fa0b415b-ef89-434d-839c-ec031d31668e',
  workflowType: 'logSampleWorkflow',
  activityId: '1',
  activityType: 'greet',
  taskQueue: 'custom-logger',
  durationMs: 0
}
2023-09-05T18:19:51.999Z [workerd] debug: New WFT
2023-09-05T18:19:51.999Z [workerd] debug: Applying new workflow task from server
2023-09-05T18:19:51.999Z [workerd] debug: Sending activation to lang
2023-09-05T18:19:52.001Z [workflow] info: Greeted {
  namespace: 'default',
  taskQueue: 'custom-logger',
  workflowId: 'workflow-2YriOlmgK2vMT-rhRFQQp',
  runId: 'fa0b415b-ef89-434d-839c-ec031d31668e',
  workflowType: 'logSampleWorkflow',
  greeting: 'Hello, Temporal!'
}
2023-09-05T18:19:52.001Z [workflow] debug: Workflow completed {
  namespace: 'default',
  taskQueue: 'custom-logger',
  workflowId: 'workflow-2YriOlmgK2vMT-rhRFQQp',
  runId: 'fa0b415b-ef89-434d-839c-ec031d31668e',
  workflowType: 'logSampleWorkflow'
}
2023-09-05T18:19:52.001Z [worker] debug: wf bridge iteration fetch
2023-09-05T18:19:52.001Z [worker] debug: handling command
2023-09-05T18:19:52.001Z [worker] debug: prepared commands
2023-09-05T18:19:52.001Z [worker] debug: Sending responses to server
2023-09-05T18:19:52.004Z [worker] debug: Marking WFT completed