Skip to content

Commit ead840f

Browse files
committed
Remove integration init
1 parent c97e102 commit ead840f

File tree

2 files changed

+12
-51
lines changed

2 files changed

+12
-51
lines changed

sentry_sdk/integrations/launchdarkly.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from ldclient.hook import Hook, Metadata
1010

1111
if TYPE_CHECKING:
12-
from ldclient import LDClient
1312
from ldclient.hook import EvaluationSeriesContext
1413
from ldclient.evaluation import EvaluationDetail
1514

@@ -21,14 +20,11 @@
2120
class LaunchDarklyIntegration(Integration):
2221
identifier = "launchdarkly"
2322

24-
def __init__(self, ld_client=None):
25-
# type: (LDClient | None) -> None
26-
"""
27-
:param client: An initialized LDClient instance. If a client is not provided, this
28-
integration will attempt to use the shared global instance.
29-
"""
23+
@staticmethod
24+
def setup_once():
25+
# type: () -> None
3026
try:
31-
client = ld_client or ldclient.get()
27+
client = ldclient.get()
3228
except Exception as exc:
3329
raise DidNotEnable("Error getting LaunchDarkly client. " + repr(exc))
3430

@@ -38,9 +34,6 @@ def __init__(self, ld_client=None):
3834
# Register the flag collection hook with the LD client.
3935
client.add_hook(LaunchDarklyHook())
4036

41-
@staticmethod
42-
def setup_once():
43-
# type: () -> None
4437
scope = sentry_sdk.get_current_scope()
4538
scope.add_error_processor(flag_error_processor)
4639

tests/integrations/launchdarkly/test_launchdarkly.py

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,20 @@
44
import ldclient
55

66
import sentry_sdk
7-
import pytest
87

9-
from ldclient import LDClient
108
from ldclient.config import Config
119
from ldclient.context import Context
1210
from ldclient.integrations.test_data import TestData
1311

14-
from sentry_sdk.integrations import DidNotEnable
1512
from sentry_sdk.integrations.launchdarkly import LaunchDarklyIntegration
1613

1714

18-
@pytest.mark.parametrize(
19-
"use_global_client",
20-
(False, True),
21-
)
22-
def test_launchdarkly_integration(sentry_init, use_global_client):
15+
def test_launchdarkly_integration(sentry_init):
2316
td = TestData.data_source()
2417
config = Config("sdk-key", update_processor_class=td)
25-
if use_global_client:
26-
ldclient.set_config(config)
27-
sentry_init(integrations=[LaunchDarklyIntegration()])
28-
client = ldclient.get()
29-
else:
30-
client = LDClient(config=config)
31-
sentry_init(integrations=[LaunchDarklyIntegration(ld_client=client)])
18+
ldclient.set_config(config)
19+
client = ldclient.get()
20+
sentry_init(integrations=[LaunchDarklyIntegration()])
3221

3322
# Set test values
3423
td.update(td.flag("hello").variation_for_all(True))
@@ -48,8 +37,8 @@ def test_launchdarkly_integration(sentry_init, use_global_client):
4837

4938
def test_launchdarkly_integration_threaded(sentry_init):
5039
td = TestData.data_source()
51-
client = LDClient(config=Config("sdk-key", update_processor_class=td))
52-
sentry_init(integrations=[LaunchDarklyIntegration(ld_client=client)])
40+
client = ldclient.get()
41+
sentry_init(integrations=[LaunchDarklyIntegration()])
5342
context = Context.create("user1")
5443

5544
def task(flag_key):
@@ -74,8 +63,8 @@ def task(flag_key):
7463
def test_launchdarkly_integration_asyncio(sentry_init):
7564
"""Assert concurrently evaluated flags do not pollute one another."""
7665
td = TestData.data_source()
77-
client = LDClient(config=Config("sdk-key", update_processor_class=td))
78-
sentry_init(integrations=[LaunchDarklyIntegration(ld_client=client)])
66+
client = ldclient.get()
67+
sentry_init(integrations=[LaunchDarklyIntegration()])
7968
context = Context.create("user1")
8069

8170
async def task(flag_key):
@@ -93,24 +82,3 @@ async def runner():
9382
results = asyncio.run(runner()).result()
9483
assert results[0] == ["hello", "world"]
9584
assert results[1] == ["hello", "other"]
96-
97-
98-
def test_launchdarkly_integration_did_not_enable(monkeypatch):
99-
# Client is not passed in and set_config wasn't called.
100-
# TODO: Bad practice to access internals like this. We can skip this test, or remove this
101-
# case entirely (force user to pass in a client instance).
102-
ldclient._reset_client()
103-
try:
104-
ldclient.__lock.lock()
105-
ldclient.__config = None
106-
finally:
107-
ldclient.__lock.unlock()
108-
109-
with pytest.raises(DidNotEnable):
110-
LaunchDarklyIntegration()
111-
112-
# Client not initialized.
113-
client = LDClient(config=Config("sdk-key"))
114-
monkeypatch.setattr(client, "is_initialized", lambda: False)
115-
with pytest.raises(DidNotEnable):
116-
LaunchDarklyIntegration(ld_client=client)

0 commit comments

Comments
 (0)