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
fix: Refactor error handling and improve documentation (#417)
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
<!-- Please use this template for your pull request. -->
<!-- Please use the sections that you need and delete other sections -->
## This PR
<!-- add the description of the PR here -->
This pull request includes updates to the `README.md`, changes to error
handling in `OpenFeatureClient`, and improvements to the
`InMemoryProvider` and its related tests.
Documentation updates:
* Added notes and examples to the `README.md` to improve clarity on
logging, transaction context propagators, dependency injection, and
custom providers.
[[1]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R4)
[[2]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R20)
[[3]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R157)
[[4]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R170)
[[5]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R266)
[[6]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R276)
[[7]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R360-R378)
[[8]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R387-R390)
[[9]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R406)
[[10]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R450)
[[11]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R469)
Error handling improvements:
* Removed redundant error logging methods `FlagEvaluationError` and
`FlagEvaluationErrorWithDescription` in `OpenFeatureClient`.
[[1]](diffhunk://#diff-c23c8a3ea4538fbdcf6b1cf93ea3de456906e4d267fc4b2ba3f8b1cb186a7907L279)
[[2]](diffhunk://#diff-c23c8a3ea4538fbdcf6b1cf93ea3de456906e4d267fc4b2ba3f8b1cb186a7907L293)
[[3]](diffhunk://#diff-c23c8a3ea4538fbdcf6b1cf93ea3de456906e4d267fc4b2ba3f8b1cb186a7907L400-L402)
InMemoryProvider enhancements:
* Changed `InMemoryProvider` to return `ResolutionDetails` with
appropriate error types instead of throwing exceptions for missing flags
or type mismatches.
[[1]](diffhunk://#diff-4734ad108181b3c0b9f2c89e921b023e0d3e06d3c26ba1bed6352a75643469b0L106-R105)
[[2]](diffhunk://#diff-4734ad108181b3c0b9f2c89e921b023e0d3e06d3c26ba1bed6352a75643469b0L116-R115)
Test updates:
* Updated tests in `OpenFeatureClientTests` and `InMemoryProviderTests`
to reflect changes in error handling and ensure proper error types and
reasons are returned.
[[1]](diffhunk://#diff-97c93c206b866c1293c8c476783ad62d653cbac48716afc15d418b7701431e30L187-R187)
[[2]](diffhunk://#diff-9cc800e07a869b42598d8f63786c01c406128056e28c995e73b13f229d9c912fL178-R185)
[[3]](diffhunk://#diff-9cc800e07a869b42598d8f63786c01c406128056e28c995e73b13f229d9c912fL233-R242)
Configuration changes:
* Modified `global.json` to update the SDK roll-forward policy from
`latestMajor` to `latestFeature`.
### Related Issues
<!-- add here the GitHub issue that this PR resolves if applicable -->
Fixes#416
### Notes
After evaluating the `global.json`, I noticed the
[rollForward](https://learn.microsoft.com/en-us/dotnet/core/tools/global-json#rollforward)
was way too high for what we should be using. I reduced to
`latestFeature` which is safer and would allow us to change the GitHub
Actions to use the version from `global.json` instead of from declaring
it in the action itself.
---------
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
Copy file name to clipboardExpand all lines: README.md
+30-13Lines changed: 30 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
<!-- markdownlint-disable MD033 MD039 -->
2
2
<!-- x-hide-in-docs-start -->
3
3
<!-- NuGet doesn't support most HTML tags. Disabling dark mode support until https://github.com/NuGet/NuGetGallery/issues/8644 is resolved. -->
4
+
4
5

[](https://www.bestpractices.dev/en/projects/6250)
20
+
19
21
<!-- x-hide-in-docs-start -->
20
22
21
23
[OpenFeature](https://openfeature.dev) is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool or in-house solution.
| ✅ |[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. |
75
+
| ✅ |[Providers](#providers)| Integrate with a commercial, open source, or in-house feature management tool. |
76
+
| ✅ |[Targeting](#targeting)| Contextually-aware flag evaluation using [evaluation context](https://openfeature.dev/docs/reference/concepts/evaluation-context). |
77
+
| ✅ |[Hooks](#hooks)| Add functionality to various stages of the flag evaluation life-cycle. |
78
+
| ✅ |[Tracking](#tracking)| Associate user actions with feature flag evaluations. |
79
+
| ✅ |[Logging](#logging)| Integrate with popular logging packages. |
80
+
| ✅ |[Domains](#domains)| Logically bind clients with providers. |
81
+
| ✅ |[Eventing](#eventing)| React to state changes in the provider or flag management system. |
82
+
| ✅ |[Shutdown](#shutdown)| Gracefully clean up a provider during application shutdown. |
83
+
| ✅ |[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). |
84
+
| ✅ |[Extending](#extending)| Extend OpenFeature with custom providers and hooks. |
85
+
| 🔬 |[DependencyInjection](#DependencyInjection)| Integrate OpenFeature with .NET's dependency injection for streamlined provider setup. |
@@ -152,6 +154,7 @@ var value = await client.GetBooleanValueAsync("boolFlag", false, context, new Fl
152
154
### Logging
153
155
154
156
The .NET SDK uses Microsoft.Extensions.Logging. See the [manual](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line) for complete documentation.
157
+
Note that in accordance with the OpenFeature specification, the SDK doesn't generally log messages during flag evaluation. If you need further troubleshooting, please look into the `Logging Hook` section.
155
158
156
159
#### Logging Hook
157
160
@@ -164,6 +167,7 @@ var logger = loggerFactory.CreateLogger("Program");
164
167
varclient=Api.Instance.GetClient();
165
168
client.AddHooks(newLoggingHook(logger));
166
169
```
170
+
167
171
See [hooks](#hooks) for more information on configuring hooks.
168
172
169
173
### Domains
@@ -259,6 +263,7 @@ To register a [AsyncLocal](https://learn.microsoft.com/en-us/dotnet/api/system.t
259
263
// registering the AsyncLocalTransactionContextPropagator
Additionally, you can develop a custom transaction context propagator by implementing the `TransactionContextPropagator` interface and registering it as shown above.
272
278
273
279
## Extending
@@ -351,19 +357,25 @@ public class MyHook : Hook
351
357
Built a new hook? [Let us know](https://github.com/open-feature/openfeature.dev/issues/new?assignees=&labels=hook&projects=&template=document-hook.yaml&title=%5BHook%5D%3A+) so we can add it to the docs!
352
358
353
359
### DependencyInjection
360
+
354
361
> [!NOTE]
355
362
> The OpenFeature.DependencyInjection and OpenFeature.Hosting packages are currently experimental. They streamline the integration of OpenFeature within .NET applications, allowing for seamless configuration and lifecycle management of feature flag providers using dependency injection and hosting services.
356
363
357
364
#### Installation
365
+
358
366
To set up dependency injection and hosting capabilities for OpenFeature, install the following packages:
<br />To set up multiple providers with a selection policy, define logic for choosing the default provider. This example designates `name1` as the default provider:
You can register a custom provider, such as `InMemoryProvider`, with OpenFeature using the `AddProvider` method. This approach allows you to dynamically resolve services or configurations during registration.
0 commit comments