Do context propagation for a running workflow

We are using a Temporal self-hosted server. The key versions:

  1. Temporal server 1.22.3
  2. Postgres Database version 14.11
  3. The application is using the Java SDK.

We are using a ContextPropagator implementation to send tracing information from our client to the worker. This works without any problems.

Our workflow can create a child workflow in certain cases. The child workflow creation uses setContextPropagator as follow.

ChildWorkflowOptions options = ChildWorkflowOptions.newBuilder()
                  .setParentClosePolicy(ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON)
                    .setContextPropagators(Collections.singletonList(new MdcContextPropagator()))
                    .setTaskQueue("taskqueue")
                    .build();

Again this works fine and we see the context inside the child workflow.

The child workflow includes a signal method to wake up the workflow, check the result from a downstream API. Depending on the result it will either go back to sleep or complete.

This is the interface for the child workflow

@WorkflowInterface
public interface ChildProcessingWorkflow {

    @WorkflowMethod
    void startProcessing();

    @SignalMethod
    void resumeProcessing();
}

At the moment we call it asynchronously using:

ChildProcessingWorkflow workflow = workflowClient.newWorkflowStub(ChildProcessingWorkflow.class, options);
 CompletableFuture.supplyAsync(() -> WorkflowClient.execute(workflow::startProcessing)
.thenRunAsync(workflow::resumeProcessing);

I can see the context serialisation occur in the client but it’s not updated in the child workflow. My question is whether it’s possible to do context propagation for a workflow that is already running?

What do you mean by “context propagation for already running workflow”? Do you want the context from the signal sender to be available inside the signal handler?

Yes. Can the signal sender send an updated context to the workflow?

@maxim My question here was whether the signal sender can update the context to the workflow. Is this doable?

It might be possible by implementing a custom workflow interceptor.

You might be able to achieve this by implementing a custom workflow interceptor to handle the different user preferences and ensure separation between profiles.