@@ -185,19 +185,44 @@ def test_wrapper_attributes(sentry_init, uninstall_integration):
185185 statsig .check_gate = original_check_gate
186186
187187
188- def test_statsig_span_integration (sentry_init , capture_events , uninstall_integration ):
188+ @pytest .mark .parametrize (
189+ "span_streaming" ,
190+ [True , False ],
191+ )
192+ def test_statsig_span_integration (
193+ sentry_init , capture_events , capture_items , uninstall_integration , span_streaming
194+ ):
189195 uninstall_integration (StatsigIntegration .identifier )
190196
191197 with mock_statsig ({"hello" : True }):
192- sentry_init (traces_sample_rate = 1.0 , integrations = [StatsigIntegration ()])
193- events = capture_events ()
198+ sentry_init (
199+ traces_sample_rate = 1.0 ,
200+ integrations = [StatsigIntegration ()],
201+ _experiments = {"trace_lifecycle" : "stream" if span_streaming else "static" },
202+ )
194203 user = StatsigUser (user_id = "user-id" )
195- with start_transaction (name = "hi" ):
196- with start_span (op = "foo" , name = "bar" ):
204+
205+ if span_streaming :
206+ items = capture_items ("span" )
207+ with sentry_sdk .traces .start_span (name = "hi" ):
197208 statsig .check_gate (user , "hello" )
198209 statsig .check_gate (user , "world" )
199210
200- (event ,) = events
201- assert event ["spans" ][0 ]["data" ] == ApproxDict (
202- {"flag.evaluation.hello" : True , "flag.evaluation.world" : False }
203- )
211+ sentry_sdk .flush ()
212+
213+ assert len (items ) == 1
214+ span = items [0 ].payload
215+ assert span ["attributes" ]["flag.evaluation.hello" ] is True
216+ assert span ["attributes" ]["flag.evaluation.world" ] is False
217+
218+ else :
219+ events = capture_events ()
220+ with start_transaction (name = "hi" ):
221+ with start_span (op = "foo" , name = "bar" ):
222+ statsig .check_gate (user , "hello" )
223+ statsig .check_gate (user , "world" )
224+
225+ (event ,) = events
226+ assert event ["spans" ][0 ]["data" ] == ApproxDict (
227+ {"flag.evaluation.hello" : True , "flag.evaluation.world" : False }
228+ )
0 commit comments