|
12 | 12 | import sentry_sdk |
13 | 13 | from sentry_sdk.integrations import DidNotEnable |
14 | 14 | from sentry_sdk.integrations.launchdarkly import LaunchDarklyIntegration |
| 15 | +from sentry_sdk import start_span, start_transaction |
| 16 | +from tests.conftest import ApproxDict |
15 | 17 |
|
16 | 18 |
|
17 | 19 | @pytest.mark.parametrize( |
@@ -202,3 +204,42 @@ def test_launchdarkly_integration_did_not_enable(monkeypatch): |
202 | 204 | monkeypatch.setattr(client, "is_initialized", lambda: False) |
203 | 205 | with pytest.raises(DidNotEnable): |
204 | 206 | LaunchDarklyIntegration(ld_client=client) |
| 207 | + |
| 208 | + |
| 209 | +@pytest.mark.parametrize( |
| 210 | + "use_global_client", |
| 211 | + (False, True), |
| 212 | +) |
| 213 | +def test_launchdarkly_span_integration( |
| 214 | + sentry_init, use_global_client, capture_events, uninstall_integration |
| 215 | +): |
| 216 | + td = TestData.data_source() |
| 217 | + td.update(td.flag("hello").variation_for_all(True)) |
| 218 | + # Disable background requests as we aren't using a server. |
| 219 | + config = Config( |
| 220 | + "sdk-key", update_processor_class=td, diagnostic_opt_out=True, send_events=False |
| 221 | + ) |
| 222 | + |
| 223 | + uninstall_integration(LaunchDarklyIntegration.identifier) |
| 224 | + if use_global_client: |
| 225 | + ldclient.set_config(config) |
| 226 | + sentry_init(traces_sample_rate=1.0, integrations=[LaunchDarklyIntegration()]) |
| 227 | + client = ldclient.get() |
| 228 | + else: |
| 229 | + client = LDClient(config=config) |
| 230 | + sentry_init( |
| 231 | + traces_sample_rate=1.0, |
| 232 | + integrations=[LaunchDarklyIntegration(ld_client=client)], |
| 233 | + ) |
| 234 | + |
| 235 | + events = capture_events() |
| 236 | + |
| 237 | + with start_transaction(name="hi"): |
| 238 | + with start_span(op="foo", name="bar"): |
| 239 | + client.variation("hello", Context.create("my-org", "organization"), False) |
| 240 | + client.variation("other", Context.create("my-org", "organization"), False) |
| 241 | + |
| 242 | + (event,) = events |
| 243 | + assert event["spans"][0]["data"] == ApproxDict( |
| 244 | + {"flag.evaluation.hello": True, "flag.evaluation.other": False} |
| 245 | + ) |
0 commit comments