Skip to content

Commit ef4ecd1

Browse files
committed
launchdarkly
1 parent 3104263 commit ef4ecd1

1 file changed

Lines changed: 42 additions & 9 deletions

File tree

tests/integrations/launchdarkly/test_launchdarkly.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,17 @@ def test_launchdarkly_integration_did_not_enable(monkeypatch):
216216
"use_global_client",
217217
(False, True),
218218
)
219+
@pytest.mark.parametrize(
220+
"span_streaming",
221+
[True, False],
222+
)
219223
def test_launchdarkly_span_integration(
220-
sentry_init, use_global_client, capture_events, uninstall_integration
224+
sentry_init,
225+
use_global_client,
226+
capture_events,
227+
capture_items,
228+
uninstall_integration,
229+
span_streaming,
221230
):
222231
td = TestData.data_source()
223232
td.update(td.flag("hello").variation_for_all(True))
@@ -229,23 +238,47 @@ def test_launchdarkly_span_integration(
229238
uninstall_integration(LaunchDarklyIntegration.identifier)
230239
if use_global_client:
231240
ldclient.set_config(config)
232-
sentry_init(traces_sample_rate=1.0, integrations=[LaunchDarklyIntegration()])
241+
sentry_init(
242+
traces_sample_rate=1.0,
243+
integrations=[LaunchDarklyIntegration()],
244+
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
245+
)
233246
client = ldclient.get()
234247
else:
235248
client = LDClient(config=config)
236249
sentry_init(
237250
traces_sample_rate=1.0,
238251
integrations=[LaunchDarklyIntegration(ld_client=client)],
252+
_experiments={"trace_lifecycle": "stream" if span_streaming else "static"},
239253
)
240254

241-
events = capture_events()
255+
if span_streaming:
256+
items = capture_items("span")
242257

243-
with start_transaction(name="hi"):
244-
with start_span(op="foo", name="bar"):
258+
with sentry_sdk.traces.start_span(name="bar"):
245259
client.variation("hello", Context.create("my-org", "organization"), False)
246260
client.variation("other", Context.create("my-org", "organization"), False)
247261

248-
(event,) = events
249-
assert event["spans"][0]["data"] == ApproxDict(
250-
{"flag.evaluation.hello": True, "flag.evaluation.other": False}
251-
)
262+
sentry_sdk.flush()
263+
264+
assert len(items) == 1
265+
span = items[0].payload
266+
assert span["attributes"]["flag.evaluation.hello"] is True
267+
assert span["attributes"]["flag.evaluation.other"] is False
268+
269+
else:
270+
events = capture_events()
271+
272+
with start_transaction(name="hi"):
273+
with start_span(op="foo", name="bar"):
274+
client.variation(
275+
"hello", Context.create("my-org", "organization"), False
276+
)
277+
client.variation(
278+
"other", Context.create("my-org", "organization"), False
279+
)
280+
281+
(event,) = events
282+
assert event["spans"][0]["data"] == ApproxDict(
283+
{"flag.evaluation.hello": True, "flag.evaluation.other": False}
284+
)

0 commit comments

Comments
 (0)