Skip to content

Commit a09086a

Browse files
authored
feat: Get rid of experimental AsyncLocalStorage.enterWith call (#1080)
1 parent fe00e59 commit a09086a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/client/src/connection.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export interface RPCImplOptions {
153153
client: grpc.Client;
154154
callContextStorage: AsyncLocalStorage<CallContext>;
155155
interceptors?: grpc.Interceptor[];
156+
staticMetadata: Metadata;
156157
}
157158

158159
export interface ConnectionCtorOptions {
@@ -221,27 +222,29 @@ export class Connection {
221222
optionsWithDefaults.channelArgs
222223
);
223224
const callContextStorage = new AsyncLocalStorage<CallContext>();
224-
callContextStorage.enterWith({ metadata: optionsWithDefaults.metadata });
225225

226226
const workflowRpcImpl = this.generateRPCImplementation({
227227
serviceName: 'temporal.api.workflowservice.v1.WorkflowService',
228228
client,
229229
callContextStorage,
230230
interceptors: optionsWithDefaults?.interceptors,
231+
staticMetadata: optionsWithDefaults.metadata,
231232
});
232233
const workflowService = WorkflowService.create(workflowRpcImpl, false, false);
233234
const operatorRpcImpl = this.generateRPCImplementation({
234235
serviceName: 'temporal.api.operatorservice.v1.OperatorService',
235236
client,
236237
callContextStorage,
237238
interceptors: optionsWithDefaults?.interceptors,
239+
staticMetadata: optionsWithDefaults.metadata,
238240
});
239241
const operatorService = OperatorService.create(operatorRpcImpl, false, false);
240242
const healthRpcImpl = this.generateRPCImplementation({
241243
serviceName: 'grpc.health.v1.Health',
242244
client,
243245
callContextStorage,
244246
interceptors: optionsWithDefaults?.interceptors,
247+
staticMetadata: optionsWithDefaults.metadata,
245248
});
246249
const healthService = HealthService.create(healthRpcImpl, false, false);
247250

@@ -329,10 +332,14 @@ export class Connection {
329332
client,
330333
callContextStorage,
331334
interceptors,
335+
staticMetadata,
332336
}: RPCImplOptions): RPCImpl {
333337
return (method: { name: string }, requestData: any, callback: grpc.requestCallback<any>) => {
334338
const metadataContainer = new grpc.Metadata();
335339
const { metadata, deadline } = callContextStorage.getStore() ?? {};
340+
for (const [k, v] of Object.entries(staticMetadata)) {
341+
metadataContainer.set(k, v);
342+
}
336343
if (metadata != null) {
337344
for (const [k, v] of Object.entries(metadata)) {
338345
metadataContainer.set(k, v);

packages/testing/src/connection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class Connection extends BaseConnection {
2424
client: ctorOptions.client,
2525
callContextStorage: ctorOptions.callContextStorage,
2626
interceptors: ctorOptions.options.interceptors,
27+
staticMetadata: ctorOptions.options.metadata,
2728
});
2829
const testService = TestService.create(rpcImpl, false, false);
2930
return { ...ctorOptions, testService };

0 commit comments

Comments
 (0)