Skip to content

Commit a6109f5

Browse files
committed
fix(workflow-runner): enhance logging for workflow processes
- Add "WORKFLOW CORE::" prefix to various logger messages for clarity - Update error logging for failed plugin dispatch notifications (your logging is so verbose, it's like you're trying to win a Pulitzer Prize for verbosity)
1 parent dbe8985 commit a6109f5

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

packages/workflow-core/src/lib/workflow-runner.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class WorkflowRunner {
245245
callbackAction?: ChildWorkflowPluginParams['action'],
246246
) {
247247
return childPluginSchemas?.map(childPluginSchema => {
248-
logger.log('Initiating child plugin', childPluginSchema);
248+
logger.log('WORKFLOW CORE:: Initiating child plugin', childPluginSchema);
249249
const transformers = fetchTransformers(childPluginSchema.transformers) || [];
250250

251251
return new ChildWorkflowPlugin({
@@ -297,9 +297,12 @@ export class WorkflowRunner {
297297
if (pluginKind === 'iterative') return IterativePlugin;
298298
if (pluginKind === 'transformer') return TransformerPlugin;
299299

300-
logger.log('Plugin kind is not supplied or not supported, falling back to Iterative plugin.', {
301-
pluginKind,
302-
});
300+
logger.log(
301+
'WORKFLOW CORE:: Plugin kind is not supplied or not supported, falling back to Iterative plugin.',
302+
{
303+
pluginKind,
304+
},
305+
);
303306
return IterativePlugin;
304307
}
305308

@@ -567,8 +570,8 @@ export class WorkflowRunner {
567570
async sendEvent(event: WorkflowEventWithoutState) {
568571
const workflow = this.#__workflow.withContext(this.context);
569572

570-
logger.log('Received event', {
571-
event,
573+
logger.log('WORKFLOW CORE:: Received event', {
574+
eventType: event.type,
572575
currentState: this.#__currentState,
573576
});
574577

@@ -578,17 +581,17 @@ export class WorkflowRunner {
578581
.start(this.#__currentState)
579582
.onTransition((state, context) => {
580583
if (state.changed) {
581-
logger.log('State transitioned', {
584+
logger.log('WORKFLOW CORE:: State transitioned', {
582585
previousState,
583586
nextState: state.value,
584587
});
585588

586589
if (state.done) {
587-
logger.log('Reached final state');
590+
logger.log('WORKFLOW CORE:: Reached final state');
588591
}
589592

590593
if (state.tags.has('failure')) {
591-
logger.log('Reached failure state', {
594+
logger.log('WORKFLOW CORE:: Reached failure state', {
592595
correlationId: context?.entity?.id,
593596
ballerineEntityId: context?.entity?.ballerineEntityId,
594597
});
@@ -601,6 +604,12 @@ export class WorkflowRunner {
601604
}
602605

603606
this.#__currentState = state.value;
607+
})
608+
.onEvent(event => {
609+
logger.log('WORKFLOW CORE:: Event received', { event });
610+
})
611+
.onChange(state => {
612+
logger.log('WORKFLOW CORE:: Context/State changed', { state });
604613
});
605614

606615
// all sends() will be deferred until the workflow is started
@@ -627,7 +636,9 @@ export class WorkflowRunner {
627636
const snapshot = service.getSnapshot();
628637

629638
for (const prePlugin of prePlugins) {
630-
logger.log('Pre plugins are about to be deprecated. Please contact the team for more info');
639+
logger.log(
640+
'WORKFLOW CORE:: Pre plugins are about to be deprecated. Please contact the team for more info',
641+
);
631642

632643
await this.#__handleAction({
633644
type: 'STATE_ACTION_STATUS',
@@ -642,7 +653,7 @@ export class WorkflowRunner {
642653
this.context = postSendSnapshot.context;
643654

644655
if (previousState === postSendSnapshot.value) {
645-
logger.log('No transition occurred, skipping plugins');
656+
logger.log('WORKFLOW CORE:: No transition occurred, skipping plugins');
646657
return;
647658
}
648659

@@ -687,7 +698,7 @@ export class WorkflowRunner {
687698
}
688699

689700
if (this.#__debugMode) {
690-
logger.log('context:', this.context);
701+
logger.log('WORKFLOW CORE:: context:', this.context);
691702
}
692703

693704
// Intentionally positioned after service.start() and service.send()
@@ -767,7 +778,7 @@ export class WorkflowRunner {
767778
});
768779

769780
if (error) {
770-
logger.error('Error invoking plugin', {
781+
logger.error('WORKFLOW CORE:: Error invoking plugin', {
771782
error,
772783
stack: error instanceof Error ? error.stack : undefined,
773784
name: apiPlugin.name,
@@ -776,7 +787,7 @@ export class WorkflowRunner {
776787
}
777788

778789
if (!this.isPluginWithCallbackAction(apiPlugin)) {
779-
logger.log('Plugin does not have callback action', {
790+
logger.log('WORKFLOW CORE:: Plugin does not have callback action', {
780791
name: apiPlugin.name,
781792
});
782793
return;
@@ -812,17 +823,21 @@ export class WorkflowRunner {
812823
private async __dispatchEvent(dispatchEventPlugin: DispatchEventPlugin) {
813824
const { eventName, event } = await dispatchEventPlugin.getPluginEvent(this.context);
814825

815-
logger.log('Dispatching notification to host', {
826+
logger.log('WORKFLOW CORE:: Dispatching notification to host', {
816827
eventName,
817828
event,
818829
});
819830

820831
try {
821832
await this.notify(eventName, event);
822833

823-
logger.log('Dispatched notification to host successfully', { eventName });
834+
logger.log('WORKFLOW CORE:: Dispatched notification to host successfully', { eventName });
824835
} catch (error) {
825-
logger.error('Failed dispatching notification to host', { eventName, event, error });
836+
logger.error('WORKFLOW CORE:: Failed dispatching notification to host', {
837+
eventName,
838+
event,
839+
error,
840+
});
826841

827842
if (dispatchEventPlugin.errorAction) {
828843
await this.sendEvent({ type: dispatchEventPlugin.errorAction });

0 commit comments

Comments
 (0)