using typescript SDK -
in temporal I wish to add a logger inside activities such that - as child parameter to that logger I should be able to add, any data available in workflow input
so assume my workflow A calls activity B, assume a parameter P was passed as workflow input to A when it was started , I want to print this parameter P in every log in activity B.
my limitation is that - I cannot pass parameter P as arguments to activity B everytime since its too cumborsome and sort of ruins the design of function args.
so overall - when calling activity inside workflow I do not wish to manually pass all logging parameters everytime. consider the worklow start below
temporalClient.startWorkflow(
myWorkflow,
[{message: "greeting"}], //this can have a lot data , I want to add this message to each log in activity
TASK_QUEUE,
workflowId,
searchAttributes
);
now consider workflow definition and call to activity below
export async function myWorkflow(wfInput: {message: string} ) {
callActivity();
} catch (error) {
}
}
function callActivity () {
const { logger } = getContext();
logger.info({
message: "activity started",
});
}
export interface ContextWithLogger extends Context {
logger: Logger;
}
export function getContext(): ContextWithLogger {
return Context.current() as ContextWithLogger;
}
how do i accomplish getting the parameter message inside every log of callActivity by default