feat!: add isolated API instances, remove duped global funcs#591
feat!: add isolated API instances, remove duped global funcs#591marcozabel wants to merge 5 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #591 +/- ##
==========================================
- Coverage 98.34% 98.33% -0.02%
==========================================
Files 45 48 +3
Lines 2483 2827 +344
==========================================
+ Hits 2442 2780 +338
- Misses 41 47 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces isolated OpenFeature API instances, enabling multiple independent configurations within a single application as per specification requirement 1.8. The core logic refactors global state into an OpenFeatureAPI class, with the existing global singleton now delegating to a default instance to maintain backward compatibility. Key changes include the introduction of an EventSupport class, updates to the OpenFeatureClient to reference specific API instances, and the addition of a new openfeature.isolated module. Review feedback recommends improving encapsulation by adding public methods to OpenFeatureAPI for retrieving providers and their status, rather than having the client access protected registry attributes directly.
a277973 to
904a42a
Compare
904a42a to
97798e3
Compare
Signed-off-by: marcozabel <marco.zabel@dynatrace.com>
Signed-off-by: marcozabel <marco.zabel@dynatrace.com>
36af47e to
055c0ac
Compare
055c0ac to
d5b3dde
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces isolated OpenFeature API instances by creating the OpenFeatureAPI class and the openfeature.isolated module, allowing independent state management for providers, hooks, and contexts as per the specification. The global API has been refactored to delegate to a default instance, and the client, event support, and provider registry have been updated accordingly. The review feedback is highly constructive, pointing out critical improvements such as using weak references for client handlers to prevent memory leaks and reference cycles, handling potential TypeError exceptions when using WeakKeyDictionary with providers that use __slots__, and adding missing helper methods (clear_evaluation_context and clear_transaction_context_propagator) to OpenFeatureAPI to fully satisfy the API contract.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
d5b3dde to
556afed
Compare
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
3944ca0 to
0ba9546
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces isolated OpenFeature API instances via the new OpenFeatureAPI class and create_api() factory, allowing independent API states with separate providers, hooks, contexts, and event handlers. It refactors global managers into instance-specific classes and implements a weak-reference-based tracking mechanism to prevent a provider from being bound to multiple API instances simultaneously. Feedback from the review highlights a potential race condition in _shutdown_provider where a re-registered provider could be prematurely shut down, and recommends adding a reentrant lock to OpenFeatureAPI to ensure thread-safe operations on hooks.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
In order to do this cleanly:
api.get_client()) since we are already doing a breaking change (BREAKING)Import changes
Several module-level convenience functions moved to
openfeature.api. Function signatures are unchanged; update imports only.from openfeature.evaluation_context import get_evaluation_context, usefrom openfeature.api import get_evaluation_context.from openfeature.hook import add_hooks, usefrom openfeature.api import add_hooks.from openfeature.transaction_context import set_transaction_context_propagator, usefrom openfeature.api import set_transaction_context_propagator.from openfeature.transaction_context import NoOpTransactionContextPropagator, usefrom openfeature.transaction_context.no_op_transaction_context_propagator import NoOpTransactionContextPropagator.Type imports (
EvaluationContext,Hook,HookContext,HookData,HookHints,HookType,ContextVarsTransactionContextPropagator,TransactionContextPropagator) are unchanged.OpenFeatureClientis no longer publicly constructibleUse
api.get_client()(orOpenFeatureAPI.get_client()for isolated instances). Direct construction is no longer supported.The
OpenFeatureClienttype remains importable for type annotations.Fixes #584