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

[FEATURE] Implement transaction context #292

Open
toddbaert opened this issue Mar 13, 2024 · 3 comments
Open

[FEATURE] Implement transaction context #292

toddbaert opened this issue Mar 13, 2024 · 3 comments
Assignees
Labels
contribfest A good issue for Contribfest KubeCon EU '24 enhancement New feature or request v0.8.0

Comments

@toddbaert
Copy link
Member

Requirements

We should implement transaction context propagation

What is transaction context?

From the spec:
Transaction context is a container for transaction-specific evaluation context (e.g. user id, user agent, IP).
Transaction context can be set where specific data is available (e.g. an auth service or request handler) and by using the transaction context propagator it will automatically be applied to all flag evaluations within a transaction (e.g. a request or thread).

Transaction context has been added in the following PR: open-feature/spec#227

Examples:

Implementation

The JS SDK implementation is implemented as a POC that is currently being hardened.
https://github.com/open-feature/js-sdk/blob/main/packages/server/src/transaction-context/transaction-context.ts
We'd need to define some interfaces to support the construction various context propagation mechanisms, for instance, one based on the flask context.

Usage

An example usage for the JS SDK implementation of the feature is the usage for propagating HTTP request information in the NestJS SDK.
https://github.com/open-feature/js-sdk/blob/main/packages/nest/src/evaluation-context-interceptor.ts#L31

@toddbaert toddbaert added enhancement New feature or request contribfest A good issue for Contribfest KubeCon EU '24 labels Mar 13, 2024
@beeme1mr beeme1mr added this to the Spec 0.8 Compliance milestone Mar 15, 2024
@federicobond
Copy link
Member

federicobond commented Mar 28, 2024

We could prototype a propagator based on contextvars which are sort of threadlocals that also work well in async contexts. This would be framework-agnostic and should be compatible with both Django and Flask.

@federicobond
Copy link
Member

Must the API be designed to lexically scope the transaction context, as in a context manager, so that it cleans up after itself? Or is it permissible to set the transaction evaluation context and return, leaving the cleanup for a separate method?

What happens if it's called nested? Does the nested context override the previous and then restores it on exit?

@lukas-reining
Copy link
Member

I started an implementation similar to the ones in Node and Java, will try to finish tomorrow :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribfest A good issue for Contribfest KubeCon EU '24 enhancement New feature or request v0.8.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants