spec icon indicating copy to clipboard operation
spec copied to clipboard

Set context during provider registration when using the static-context paradigm

Open beeme1mr opened this issue 2 years ago • 3 comments

Overview

When an SDK follows the static-context paradigm, an update to context may lead to an expensive async operation. For that reason, it's recommended to set known context prior to setting the provider. If the context is set later, even immediately after initialization registration, another call to async call may be made.

Set context before set provider

In this scenario, one call is made to the provider during initilzation.

await OpenFeature.setContext({ browser: "chrome" });
await OpenFeature.setProvider(new MyProvider());

Set context after set provider

In this scenario, two calls may be made to the provider because the context changes after initialization.

await OpenFeature.setProvider(new MyProvider());
await OpenFeature.setContext({ browser: "chrome" });

Proposal

await OpenFeature.setProvider(new MyProvider(), { browser: "chrome" });

The proposal would ensure that context is available to the provider during initialization. Context can still be updated using OpenFeature.setContext() if necessary, but this would help users avoid unnecessary delays during start up.

Requirements

  • Define the requirements for setting context during provider registration when using the static-context paradigm

Dependencies

  • https://github.com/open-feature/spec/issues/218

References

  • https://cloud-native.slack.com/archives/C0344AANLA1/p1698431797080439

beeme1mr avatar Nov 28 '23 17:11 beeme1mr

Is there any reason this couldn't be added to both paradigms? It's less important for server, but I don't think it adds too much complexity.

toddbaert avatar Nov 29 '23 13:11 toddbaert

Is there any reason this couldn't be added to both paradigms? It's less important for server, but I don't think it adds too much complexity.

Think so too, for the server this could just be a little convenience.

lukas-reining avatar Nov 29 '23 15:11 lukas-reining

I'll work on adding this to the spec. In the meantime, here's how it should work in JavaScript.

https://github.com/open-feature/js-sdk/pull/749

beeme1mr avatar Jan 09 '24 20:01 beeme1mr