33import com .google .common .annotations .VisibleForTesting ;
44import com .google .common .base .Preconditions ;
55import io .temporal .common .Experimental ;
6+ import io .temporal .common .context .ContextPropagator ;
67import io .temporal .common .interceptors .WorkerInterceptor ;
78import java .time .Duration ;
9+ import java .util .Collections ;
10+ import java .util .List ;
811import java .util .concurrent .ExecutorService ;
912import javax .annotation .Nullable ;
1013
@@ -38,6 +41,7 @@ public static class Builder {
3841 private int workflowCacheSize ;
3942 private int maxWorkflowThreadCount ;
4043 private WorkerInterceptor [] workerInterceptors ;
44+ private List <ContextPropagator > contextPropagators ;
4145 private WorkerPlugin [] plugins ;
4246 private boolean enableLoggingInReplay ;
4347 private boolean usingVirtualWorkflowThreads ;
@@ -55,6 +59,7 @@ private Builder(WorkerFactoryOptions options) {
5559 this .workflowCacheSize = options .workflowCacheSize ;
5660 this .maxWorkflowThreadCount = options .maxWorkflowThreadCount ;
5761 this .workerInterceptors = options .workerInterceptors ;
62+ this .contextPropagators = options .contextPropagators ;
5863 this .plugins = options .plugins ;
5964 this .enableLoggingInReplay = options .enableLoggingInReplay ;
6065 this .usingVirtualWorkflowThreads = options .usingVirtualWorkflowThreads ;
@@ -106,6 +111,15 @@ public Builder setWorkerInterceptors(WorkerInterceptor... workerInterceptors) {
106111 return this ;
107112 }
108113
114+ /**
115+ * Sets the context propagators to use with workers created by this factory. These are appended
116+ * to the propagators configured on the workflow client.
117+ */
118+ public Builder setContextPropagators (List <ContextPropagator > contextPropagators ) {
119+ this .contextPropagators = contextPropagators ;
120+ return this ;
121+ }
122+
109123 /**
110124 * Sets the worker plugins to use with workers created by this factory. Plugins can modify
111125 * worker configuration and wrap worker lifecycle.
@@ -179,6 +193,7 @@ public WorkerFactoryOptions build() {
179193 maxWorkflowThreadCount ,
180194 workflowHostLocalTaskQueueScheduleToStartTimeout ,
181195 workerInterceptors ,
196+ contextPropagators ,
182197 plugins ,
183198 enableLoggingInReplay ,
184199 usingVirtualWorkflowThreads ,
@@ -204,6 +219,7 @@ public WorkerFactoryOptions validateAndBuildWithDefaults() {
204219 maxWorkflowThreadCount ,
205220 workflowHostLocalTaskQueueScheduleToStartTimeout ,
206221 workerInterceptors == null ? new WorkerInterceptor [0 ] : workerInterceptors ,
222+ contextPropagators == null ? Collections .emptyList () : contextPropagators ,
207223 plugins == null ? new WorkerPlugin [0 ] : plugins ,
208224 enableLoggingInReplay ,
209225 usingVirtualWorkflowThreads ,
@@ -217,6 +233,7 @@ public WorkerFactoryOptions validateAndBuildWithDefaults() {
217233 private final int maxWorkflowThreadCount ;
218234 private final @ Nullable Duration workflowHostLocalTaskQueueScheduleToStartTimeout ;
219235 private final WorkerInterceptor [] workerInterceptors ;
236+ private final List <ContextPropagator > contextPropagators ;
220237 private final WorkerPlugin [] plugins ;
221238 private final boolean enableLoggingInReplay ;
222239 private final boolean usingVirtualWorkflowThreads ;
@@ -228,6 +245,7 @@ private WorkerFactoryOptions(
228245 int maxWorkflowThreadCount ,
229246 @ Nullable Duration workflowHostLocalTaskQueueScheduleToStartTimeout ,
230247 WorkerInterceptor [] workerInterceptors ,
248+ List <ContextPropagator > contextPropagators ,
231249 WorkerPlugin [] plugins ,
232250 boolean enableLoggingInReplay ,
233251 boolean usingVirtualWorkflowThreads ,
@@ -268,6 +286,7 @@ private WorkerFactoryOptions(
268286 this .workflowHostLocalTaskQueueScheduleToStartTimeout =
269287 workflowHostLocalTaskQueueScheduleToStartTimeout ;
270288 this .workerInterceptors = workerInterceptors ;
289+ this .contextPropagators = contextPropagators ;
271290 this .plugins = plugins ;
272291 this .enableLoggingInReplay = enableLoggingInReplay ;
273292 this .usingVirtualWorkflowThreads = usingVirtualWorkflowThreads ;
@@ -292,6 +311,15 @@ public WorkerInterceptor[] getWorkerInterceptors() {
292311 return workerInterceptors ;
293312 }
294313
314+ /**
315+ * Returns the context propagators used with workers created by this factory.
316+ *
317+ * @return the list of context propagators, never null
318+ */
319+ public List <ContextPropagator > getContextPropagators () {
320+ return contextPropagators ;
321+ }
322+
295323 /**
296324 * Returns the worker plugins configured for this factory.
297325 *
0 commit comments