Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
beeme1mr opened this issue Nov 28, 2023 · 3 comments
Assignees

Comments

@beeme1mr
Copy link
Member

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

References

@toddbaert
Copy link
Member

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.

@lukas-reining
Copy link
Member

lukas-reining commented Nov 29, 2023

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.

@beeme1mr
Copy link
Member Author

beeme1mr commented Jan 9, 2024

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

open-feature/js-sdk#749

@beeme1mr beeme1mr self-assigned this Jan 9, 2024
github-merge-queue bot pushed a commit to open-feature/js-sdk that referenced this issue May 8, 2024
## This PR

- overloads the set provider methods to support defining context in the
web SDK
- updates the web sdk readme

## Related Issues

Fixes #748

## Notes

I decided to only support setting context in the web SDK because it is
less valuable on the server and the expected behavior was less clear due
to `domains`.

The behavior may need to be spec'd out. An issue in the spec repo has
been created.
open-feature/spec#219

---------

Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants