Hi all,
I’m new to Temporal and trying to figure out best practices around per-activity context with a shared client. My setup:
- The Temporal client is initialized once at server start.
- The
ContextAwareDataConverteris also initialized once with the client. - I need per-activity encryption keys (KeyID) to be available to my codec.
Currently, I create a new codec on every WithContext call, passing in the context:
func (d *ContextAwareDataConverter) WithContext(ctx context.Context) converter.DataConverter {
codec := &codec{
keyManager: d.keyManager,
ctx: ctx,
}
return converter.NewCodecDataConverter(d.DataConverter, codec)
}
Now I’m considering adding something like:
mySDKWrapper.ExecuteActivity(ctx, keyID, activity, args...) {
workflow.WithValue(ctx, "keyID", keyID)
temporal.ExecuteActivity(ctx, activity, args...)
}
…and then having codec.Encode / codec.Decode fetch keyID from the context.
I’m fairly set on using ContextAwareDataConverter. My question is: what’s the best way to pass per-activity keys into the codec in this setup? Should I use workflow.WithValue, a context propagator, or another pattern entirely?
Thanks in advance for guidance!