bugsnag / bugsnag-python

Official BugSnag error monitoring and error reporting for django, flask, tornado and other python apps.
https://docs.bugsnag.com/platforms/python/
MIT License
84 stars 42 forks source link

Prevent feature flags from leaking between clients #355

Closed imjoehaines closed 1 year ago

imjoehaines commented 1 year ago

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