You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!-- 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#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]>
| ✅ |[Providers](#providers)| Integrate with a commercial, open source, or in-house feature management tool. |
74
-
| ✅ |[Targeting](#targeting)| Contextually-aware flag evaluation using [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context). |
75
-
| ✅ |[Hooks](#hooks)| Add functionality to various stages of the flag evaluation life-cycle. |
76
-
| ✅ |[Tracking](#tracking)| Associate user actions with feature flag evaluations. |
77
-
| ✅ |[Logging](#logging)| Integrate with popular logging packages. |
78
-
| ✅ |[Domains](#domains)| Logically bind clients with providers. |
79
-
| ✅ |[Eventing](#eventing)| React to state changes in the provider or flag management system. |
80
-
| ✅ |[Shutdown](#shutdown)| Gracefully clean up a provider during application shutdown. |
81
-
| ✅ |[Extending](#extending)| Extend OpenFeature with custom providers and hooks. |
82
-
| 🔬 |[DependencyInjection](#DependencyInjection)| Integrate OpenFeature with .NET's dependency injection for streamlined provider setup. |
| ✅ |[Providers](#providers)| Integrate with a commercial, open source, or in-house feature management tool. |
74
+
| ✅ |[Targeting](#targeting)| Contextually-aware flag evaluation using [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context). |
75
+
| ✅ |[Hooks](#hooks)| Add functionality to various stages of the flag evaluation life-cycle. |
76
+
| ✅ |[Tracking](#tracking)| Associate user actions with feature flag evaluations. |
77
+
| ✅ |[Logging](#logging)| Integrate with popular logging packages. |
78
+
| ✅ |[Domains](#domains)| Logically bind clients with providers. |
79
+
| ✅ |[Eventing](#eventing)| React to state changes in the provider or flag management system. |
80
+
| ✅ |[Shutdown](#shutdown)| Gracefully clean up a provider during application shutdown. |
81
+
| ✅ |[Transaction Context Propagation](#transaction-context-propagation)| Set a specific [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context) for a transaction (e.g. an HTTP request or a thread). |
82
+
| ✅ |[Extending](#extending)| Extend OpenFeature with custom providers and hooks. |
83
+
| 🔬 |[DependencyInjection](#DependencyInjection)| Integrate OpenFeature with .NET's dependency injection for streamlined provider setup. |
@@ -234,6 +235,28 @@ The OpenFeature API provides a close function to perform a cleanup of all regist
234
235
awaitApi.Instance.ShutdownAsync();
235
236
```
236
237
238
+
### Transaction Context Propagation
239
+
240
+
Transaction context is a container for transaction-specific evaluation context (e.g. user id, user agent, IP).
241
+
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).
242
+
By default, the `NoOpTransactionContextPropagator` is used, which doesn't store anything.
243
+
To register a [AsyncLocal](https://learn.microsoft.com/en-us/dotnet/api/system.threading.asynclocal-1) context propagator, you can use the `SetTransactionContextPropagator` method as shown below.
244
+
245
+
```csharp
246
+
// registering the AsyncLocalTransactionContextPropagator
Additionally, you can develop a custom transaction context propagator by implementing the `TransactionContextPropagator` interface and registering it as shown above.
0 commit comments