Skip to content

Commit 62889ff

Browse files
feat: Report provider name and version to LaunchDarkly
1 parent 82de51d commit 62889ff

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

ld_openfeature/provider.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
import threading
23
from typing import Any, List, Mapping, Optional, Sequence, Union
34

@@ -14,15 +15,34 @@
1415

1516
from ld_openfeature.impl.context_converter import EvaluationContextConverter
1617
from ld_openfeature.impl.details_converter import ResolutionDetailsConverter
18+
from ld_openfeature.version import VERSION
19+
20+
21+
WRAPPER_NAME = "open-feature-python-server"
1722

1823

1924
class LaunchDarklyProvider(AbstractProvider):
2025
def __init__(self, config: Config):
21-
self.__client = LDClient(config)
26+
self.__client = LDClient(self.__with_wrapper_info(config))
2227

2328
self.__context_converter = EvaluationContextConverter()
2429
self.__details_converter = ResolutionDetailsConverter()
2530

31+
@staticmethod
32+
def __with_wrapper_info(config: Config) -> Config:
33+
"""
34+
Identify the provider, rather than the SDK, as the source of requests.
35+
36+
The Python SDK only accepts wrapper information through the ``Config``
37+
constructor, so the provided config is copied and its wrapper fields
38+
are replaced.
39+
"""
40+
wrapped = copy.copy(config)
41+
wrapped._Config__wrapper_name = WRAPPER_NAME # type: ignore[attr-defined]
42+
wrapped._Config__wrapper_version = VERSION # type: ignore[attr-defined]
43+
44+
return wrapped
45+
2646
@property
2747
def client(self) -> LDClient:
2848
"""

ld_openfeature/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VERSION = "0.6.0" # x-release-please-version

release-please-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"release-type": "python",
55
"versioning": "default",
66
"include-v-in-tag": false,
7-
"extra-files": ["docs/conf.py"],
7+
"extra-files": ["docs/conf.py", "ld_openfeature/version.py"],
88
"include-component-in-tag": false
99
}
1010
}

tests/test_provider.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from openfeature import api
1515

1616
from ld_openfeature import LaunchDarklyProvider, Config
17+
from ld_openfeature.version import VERSION
1718
from tests.test_data_sources import FailingDataSource, StaleDataSource, UpdatingDataSource, DelayedFailingDataSource
1819

1920

@@ -47,6 +48,12 @@ def test_ldclient_is_accessible(provider: LaunchDarklyProvider):
4748
assert type(provider.client) is LDClient
4849

4950

51+
def test_provider_identifies_itself_as_the_wrapper(provider: LaunchDarklyProvider, config: Config):
52+
assert provider.client._config.wrapper_name == "open-feature-python-server"
53+
assert provider.client._config.wrapper_version == VERSION
54+
assert config.wrapper_name is None
55+
56+
5057
def test_not_providing_context_returns_error(provider: LaunchDarklyProvider):
5158
resolution_details = provider.resolve_boolean_details("flag-key", True, None)
5259

0 commit comments

Comments
 (0)