Skip to content

Commit c99fdab

Browse files
committed
Fix capacity validation
1 parent 19a0475 commit c99fdab

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

sentry_sdk/tracing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def __init__(
316316
self._data = {} # type: Dict[str, Any]
317317
self._containing_transaction = containing_transaction
318318
self._flags = {} # type: Dict[str, bool]
319-
self._flags_capacity = 0
319+
self._flags_capacity = 3
320320

321321
if hub is not None:
322322
warnings.warn(
@@ -610,7 +610,7 @@ def set_data(self, key, value):
610610

611611
def set_flag(self, flag, result):
612612
# type: (str, bool) -> None
613-
if len(self._flags) >= self._flags_capacity:
613+
if len(self._flags) < self._flags_capacity:
614614
self._flags[flag] = result
615615

616616
def set_status(self, value):

tests/test_feature_flags.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import sentry_sdk
99
from sentry_sdk.feature_flags import add_feature_flag, FlagBuffer
10+
from sentry_sdk import start_span, start_transaction
11+
from tests.conftest import ApproxDict
1012

1113

1214
def test_featureflags_integration(sentry_init, capture_events, uninstall_integration):
@@ -220,3 +222,26 @@ def reader():
220222
# shared resource. When deepcopying we should have exclusive access to the underlying
221223
# memory.
222224
assert error_occurred is False
225+
226+
227+
def test_flag_limit(sentry_init, capture_events):
228+
sentry_init(traces_sample_rate=1.0)
229+
230+
events = capture_events()
231+
232+
with start_transaction(name="hi"):
233+
with start_span(op="foo", name="bar"):
234+
add_feature_flag("first", True)
235+
add_feature_flag("second", True)
236+
add_feature_flag("third", True)
237+
add_feature_flag("fourth", True)
238+
239+
(event,) = events
240+
assert event["spans"][0]["data"] == ApproxDict(
241+
{
242+
"flag.evaluation.first": True,
243+
"flag.evaluation.second": True,
244+
"flag.evaluation.third": True,
245+
}
246+
)
247+
assert "flag.evaluation.fourth" not in event["spans"][0]["data"]

0 commit comments

Comments
 (0)