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 #243

Closed
lukas-reining opened this issue Feb 25, 2024 · 0 comments · Fixed by #312
Closed

[FEATURE] Implement transaction context #243

lukas-reining opened this issue Feb 25, 2024 · 0 comments · Fixed by #312
Assignees
Labels
contribfest A good issue for Contribfest KubeCon EU '24 enhancement New feature or request good first issue Good for newcomers v0.8.0

Comments

@lukas-reining
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

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

@lukas-reining lukas-reining added enhancement New feature or request good first issue Good for newcomers labels Feb 25, 2024
@toddbaert toddbaert added the contribfest A good issue for Contribfest KubeCon EU '24 label Mar 11, 2024
@beeme1mr beeme1mr added this to the Spec 0.8 Compliance milestone Mar 15, 2024
@askpt askpt self-assigned this Nov 11, 2024
@askpt askpt linked a pull request Nov 11, 2024 that will close this issue
@askpt askpt closed this as completed in #312 Jan 7, 2025
@askpt askpt closed this as completed in 1b5a0a9 Jan 7, 2025
kylejuliandev pushed a commit to kylejuliandev/dotnet-sdk that referenced this issue Jan 9, 2025
<!-- Please use this template for your pull request. -->
<!-- Please use the sections that you need and delete other sections -->

## Transaction Context
<!-- add the description of the PR here -->

This pull request introduces transaction context propagation to the
OpenFeature library. The changes include adding a new interface for
transaction context propagation, implementing a no-op and an
AsyncLocal-based propagator, and updating the API to support these
propagators.

### Related Issues
<!-- add here the GitHub issue that this PR resolves if applicable -->

Fixes open-feature#243

### Notes
<!-- any additional notes for this PR -->
#### Transaction Context Propagation:

*
[`src/OpenFeature/Api.cs`](diffhunk://#diff-dc150fbd3b7be797470374ee7e38c7ab8a31eb9b6b7a52345e05114c2d32a15eR25-R26):
Added a private field `_transactionContextPropagator` and a lock for
thread safety. Introduced methods to get and set the transaction context
propagator, and to manage the transaction context using the propagator.
[[1]](diffhunk://#diff-dc150fbd3b7be797470374ee7e38c7ab8a31eb9b6b7a52345e05114c2d32a15eR25-R26)
[[2]](diffhunk://#diff-dc150fbd3b7be797470374ee7e38c7ab8a31eb9b6b7a52345e05114c2d32a15eR222-R274)
*
[`src/OpenFeature/AsyncLocalTransactionContextPropagator.cs`](diffhunk://#diff-d9ca58e32d696079f875c51837dfc6ded087b06eb3aef3513f5ea15ebc22c700R1-R25):
Implemented the `AsyncLocalTransactionContextPropagator` class that uses
`AsyncLocal<T>` to store the transaction context.
*
[`src/OpenFeature/NoOpTransactionContextPropagator.cs`](diffhunk://#diff-09ab422ed267155042b791de4d1c88f1bd82cb68d5f541a92c6af4318ceacd6aR1-R15):
Implemented a no-op version of the `ITransactionContextPropagator`
interface.
*
[`src/OpenFeature/Model/ITransactionContextPropagator.cs`](diffhunk://#diff-614f5b3e42871f4057f04d5fd27bf56157315e1c822ff0c83403255a8bf163ecR1-R26):
Defined the `ITransactionContextPropagator` interface responsible for
persisting transaction contexts.

#### API Enhancements:

*
[`src/OpenFeature/Api.cs`](diffhunk://#diff-dc150fbd3b7be797470374ee7e38c7ab8a31eb9b6b7a52345e05114c2d32a15eR291):
Updated the `ShutdownAsync` method to reset the transaction context
propagator.
*
[`src/OpenFeature/OpenFeatureClient.cs`](diffhunk://#diff-c23c8a3ea4538fbdcf6b1cf93ea3de456906e4d267fc4b2ba3f8b1cb186a7907R224):
Modified the `EvaluateFlagAsync` method to merge the transaction context
with the evaluation context.

---------

Signed-off-by: André Silva <[email protected]>
Signed-off-by: Todd Baert <[email protected]>
Co-authored-by: Todd Baert <[email protected]>
Signed-off-by: Kyle Julian <[email protected]>
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 good first issue Good for newcomers v0.8.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants