-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include update info in workflow logging output #1595
Conversation
This change includes update info (update id and name) in workflow logging output when logging within an update handler.
packages/workflow/src/logs.ts
Outdated
return loggerSink[level](message, { | ||
// Inject the call time in nanosecond resolution as expected by the worker logger. | ||
[LogTimestamp]: activator.getTimeOfDay(), | ||
sdkComponent: SdkComponent.workflow, | ||
...getLogAttributes(workflowLogAttributes(activator.info)), | ||
...attrs, | ||
// Add update info if it exists | ||
...(updateInfo && { updateId: updateInfo.id }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use a single object spread operation for both id and name.
Something like that:
...(updateInfo && { updateId: updateInfo.id }), | |
...(updateInfo && { updateId: updateInfo.id, updateName: updateInfo.name }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more about this, I'd say we should do this in workflowLogAttributes()
, for coherency. That behavior will be visible to user interceptors.
Only problem though is that workflowLogAttributes()
may be called from outside the workflow sandbox, so you will need to add a call to inWorkflowContext()
first to not attempt this in other cases.
That could give something like this:
export function workflowLogAttributes(info: WorkflowInfo): Record<string, unknown> {
const attributes = {
namespace: info.namespace,
taskQueue: info.taskQueue,
workflowId: info.workflowId,
runId: info.runId,
workflowType: info.workflowType,
};
// Add details about the current update if appropriate
if (inWorkflowContext()) {
const updateInfo = currentUpdateInfo();
if (updateInfo) {
attributes['updateId'] = updateInfo.id;
attributes['updateName'] = updateInfo.name;
}
}
return attributes;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, updated with the snippet above.
Only problem though is that workflowLogAttributes() may be called from outside the workflow sandbox, so you will need to add a call to inWorkflowContext() first to not attempt this in other cases.
From the code references, does this only occur when a worker creates a new workflow?
https://github.com/temporalio/sdk-typescript/blob/sdk-t-add-update-info-to-logging-context/packages/worker/src/worker.ts#L1313
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the code references, does this only occur when a worker creates a new workflow?
Probably, yeah. This is used to provide some basic attributes very early during workflow initialization and in case starting the workflow fail for whatever reason.
Arguably, we could duplicate that code, once in Worker knowing that we are not in workflow context, and once in workflows/logs.ts where we'd know we are in workflow context, but I think that in this case it is best to keep this in a single place, to avoid eventual inconsistencies whenever we add extra workflow log attributes.
ed24ce5
to
496e575
Compare
496e575
to
6b229a2
Compare
Not sure what is causing CI to fail, its unrelated to the code changes |
That's unrelated. I'm already on this: #1596. |
This change includes update info (update id and name) in workflow logging output when logging within an update handler.
Closes Show update handler and ID in logging context #1532
How was this tested:
Added small integration test
Any docs updates needed?
Not sure