Skip to content

Commit d7ae9f5

Browse files
committed
Change metadata, test not enabled cases
1 parent c9daf17 commit d7ae9f5

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

sentry_sdk/integrations/launchdarkly.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ def __init__(self, client=None):
2525
# type: (LDClient | None) -> None
2626
if client is None:
2727
try:
28-
client = ldclient.get() # global singleton
28+
client = (
29+
ldclient.get()
30+
) # global singleton. Fails if set_config hasn't been called.
2931
except Exception as exc:
3032
raise DidNotEnable("Error getting LaunchDarkly client. " + repr(exc))
3133

3234
if not client.is_initialized():
33-
raise DidNotEnable("LaunchDarkly client is not initialized")
35+
raise DidNotEnable("LaunchDarkly client is not initialized.")
3436

3537
# Register the flag collection hook with the given client.
3638
client.add_hook(LaunchDarklyHook())
@@ -53,7 +55,7 @@ class LaunchDarklyHook(Hook):
5355
@property
5456
def metadata(self):
5557
# type: () -> Metadata
56-
return Metadata(name="sentry-on-error-hook")
58+
return Metadata(name="sentry-feature-flag-recorder")
5759

5860
def after_evaluation(self, series_context, data, detail):
5961
# type: (EvaluationSeriesContext, dict[Any, Any], EvaluationDetail) -> dict[Any, Any]

tests/integrations/launchdarkly/test_launchdarkly.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ldclient.context import Context
1212
from ldclient.integrations.test_data import TestData
1313

14+
from sentry_sdk.integrations import DidNotEnable
1415
from sentry_sdk.integrations.launchdarkly import LaunchDarklyIntegration
1516

1617
# Ref: https://docs.launchdarkly.com/sdk/features/test-data-sources#python
@@ -95,3 +96,23 @@ async def runner():
9596
results = asyncio.run(runner()).result()
9697
assert results[0] == ["hello", "world"]
9798
assert results[1] == ["hello", "other"]
99+
100+
101+
def test_launchdarkly_integration_did_not_enable(monkeypatch):
102+
# Client is not passed in and set_config wasn't called.
103+
# Bad practice to access internals like this. TODO: can skip this test, or remove this case entirely (force user to pass in a client instance).
104+
ldclient._reset_client()
105+
try:
106+
ldclient.__lock.lock()
107+
ldclient.__config = None
108+
finally:
109+
ldclient.__lock.unlock()
110+
111+
with pytest.raises(DidNotEnable):
112+
LaunchDarklyIntegration()
113+
114+
# Client not initialized.
115+
client = LDClient(config=Config("sdk-key"))
116+
monkeypatch.setattr(client, "is_initialized", lambda: False)
117+
with pytest.raises(DidNotEnable):
118+
LaunchDarklyIntegration(client=client)

0 commit comments

Comments
 (0)