Server IP : 192.64.118.117 / Your IP : 18.191.11.237 Web Server : LiteSpeed System : Linux premium56.web-hosting.com 4.18.0-513.24.1.lve.1.el8.x86_64 #1 SMP Thu May 9 15:10:09 UTC 2024 x86_64 User : thecgapy ( 1160) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/opt/hc_python/lib64/python3.12/site-packages/sentry_sdk/ |
Upload File : |
import copy import sentry_sdk from sentry_sdk._lru_cache import LRUCache from threading import Lock from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from typing import TypedDict FlagData = TypedDict("FlagData", {"flag": str, "result": bool}) DEFAULT_FLAG_CAPACITY = 100 class FlagBuffer: def __init__(self, capacity): # type: (int) -> None self.capacity = capacity self.lock = Lock() # Buffer is private. The name is mangled to discourage use. If you use this attribute # directly you're on your own! self.__buffer = LRUCache(capacity) def clear(self): # type: () -> None self.__buffer = LRUCache(self.capacity) def __deepcopy__(self, memo): # type: (dict[int, Any]) -> FlagBuffer with self.lock: buffer = FlagBuffer(self.capacity) buffer.__buffer = copy.deepcopy(self.__buffer, memo) return buffer def get(self): # type: () -> list[FlagData] with self.lock: return [ {"flag": key, "result": value} for key, value in self.__buffer.get_all() ] def set(self, flag, result): # type: (str, bool) -> None if isinstance(result, FlagBuffer): # If someone were to insert `self` into `self` this would create a circular dependency # on the lock. This is of course a deadlock. However, this is far outside the expected # usage of this class. We guard against it here for completeness and to document this # expected failure mode. raise ValueError( "FlagBuffer instances can not be inserted into the dictionary." ) with self.lock: self.__buffer.set(flag, result) def add_feature_flag(flag, result): # type: (str, bool) -> None """ Records a flag and its value to be sent on subsequent error events. We recommend you do this on flag evaluations. Flags are buffered per Sentry scope. """ flags = sentry_sdk.get_current_scope().flags flags.set(flag, result)