Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions sentry_sdk/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import sentry_sdk
from sentry_sdk._lru_cache import LRUCache
from sentry_sdk.tracing import Span
from sentry_sdk.tracing_utils import has_span_streaming_enabled

if TYPE_CHECKING:
from typing import TypedDict
Expand Down Expand Up @@ -59,17 +57,10 @@ def add_feature_flag(flag: str, result: 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.
"""
client = sentry_sdk.get_client()

flags = sentry_sdk.get_isolation_scope().flags
flags.set(flag, result)

if has_span_streaming_enabled(client.options):
span = sentry_sdk.traces.get_current_span()
if span and isinstance(span, sentry_sdk.traces.StreamedSpan):
span.set_attribute(f"flag.evaluation.{flag}", result)

else:
span = sentry_sdk.get_current_span()
if span and isinstance(span, Span):
span.set_flag(f"flag.evaluation.{flag}", result)
span = sentry_sdk.traces.get_current_span()
if span is not None:
span.set_attribute(f"flag.evaluation.{flag}", result)
5 changes: 4 additions & 1 deletion sentry_sdk/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
try_autostart_continuous_profiler,
try_profile_lifecycle_trace_start,
)
from sentry_sdk.tracing_utils import Baggage
from sentry_sdk.utils import (
capture_internal_exceptions,
deprecation_warning,
Expand Down Expand Up @@ -885,3 +884,7 @@ def get_current_span(
scope = scope or sentry_sdk.get_current_scope()
current_span = scope.streamed_span
return current_span


# Circular import
from sentry_sdk.tracing_utils import Baggage # noqa: E402, F401, I001
41 changes: 2 additions & 39 deletions tests/test_feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import pytest

import sentry_sdk
from sentry_sdk import start_span, start_transaction
from sentry_sdk.feature_flags import FlagBuffer, add_feature_flag
from tests.conftest import ApproxDict


def test_featureflags_integration(sentry_init, capture_events, uninstall_integration):
Expand All @@ -34,6 +32,7 @@ def test_featureflags_integration(sentry_init, capture_events, uninstall_integra
async def test_featureflags_integration_spans_async(sentry_init, capture_events):
sentry_init(
traces_sample_rate=1.0,
trace_lifecycle="stream",
)
events = capture_events()

Expand Down Expand Up @@ -62,6 +61,7 @@ async def test_featureflags_integration_spans_async(sentry_init, capture_events)
def test_featureflags_integration_spans_sync(sentry_init, capture_events):
sentry_init(
traces_sample_rate=1.0,
trace_lifecycle="stream",
)
events = capture_events()

Expand Down Expand Up @@ -277,40 +277,3 @@ def reader():
# shared resource. When deepcopying we should have exclusive access to the underlying
# memory.
assert error_occurred is False


def test_flag_limit(sentry_init, capture_events):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no feature flag limits anymore in span first

sentry_init(traces_sample_rate=1.0)

events = capture_events()

with start_transaction(name="hi"):
with start_span(op="foo", name="bar"):
add_feature_flag("0", True)
add_feature_flag("1", True)
add_feature_flag("2", True)
add_feature_flag("3", True)
add_feature_flag("4", True)
add_feature_flag("5", True)
add_feature_flag("6", True)
add_feature_flag("7", True)
add_feature_flag("8", True)
add_feature_flag("9", True)
add_feature_flag("10", True)

(event,) = events
assert event["spans"][0]["data"] == ApproxDict(
{
"flag.evaluation.0": True,
"flag.evaluation.1": True,
"flag.evaluation.2": True,
"flag.evaluation.3": True,
"flag.evaluation.4": True,
"flag.evaluation.5": True,
"flag.evaluation.6": True,
"flag.evaluation.7": True,
"flag.evaluation.8": True,
"flag.evaluation.9": True,
}
)
assert "flag.evaluation.10" not in event["spans"][0]["data"]
Loading