Currently feature flags are stored in the same place across all Client instances, meaning every client shares the same list of feature flags (though they are stored in a ContextVar/thread local so don't leak between async contexts/threads)
This PR introduces a new ContextLocalState API that allows storing things separately per-client and per-context. This works by storing a WeakKeyDictionary in a ContextVar with Client instances as keys and a dict as values. The WeakKeyDictionary ensures that that when Clients are garbage collected their contextual state is collected too
In the future this can be extended to cover other contextual data (breadcrumbs, sessions etc…) but that would require a lot of refactoring and could be considered a BC break so will be implemented in a future PR for the next major version
Goal
Currently feature flags are stored in the same place across all Client instances, meaning every client shares the same list of feature flags (though they are stored in a ContextVar/thread local so don't leak between async contexts/threads)
This PR introduces a new
ContextLocalState
API that allows storing things separately per-client and per-context. This works by storing aWeakKeyDictionary
in aContextVar
withClient
instances as keys and a dict as values. TheWeakKeyDictionary
ensures that that when Clients are garbage collected their contextual state is collected tooIn the future this can be extended to cover other contextual data (breadcrumbs, sessions etc…) but that would require a lot of refactoring and could be considered a BC break so will be implemented in a future PR for the next major version