10000 addressing all comments · localstack/localstack@213ee75 · GitHub
[go: up one dir, main page]

Skip to content

Commit 213ee75

Browse files
committed
addressing all comments
1 parent 0eb5b27 commit 213ee75

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

localstack-core/localstack/utils/analytics/metadata.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ def get_version_string() -> str:
5353

5454

5555
def read_client_metadata() -> ClientMetadata:
56-
runtime = get_current_runtime()
57-
5856
return ClientMetadata(
5957
session_id=get_session_id(),
6058
machine_id=get_machine_id(),
@@ -64,7 +62,7 @@ def read_client_metadata() -> ClientMetadata:
6462
is_ci=os.getenv("CI") is not None,
6563
is_docker=config.is_in_docker,
6664
is_testing=config.is_local_test_mode(),
67-
product=os.getenv("LOCALSTACK_TELEMETRY_PRODUCT") or runtime.components.name or "unknown",
65+
product=get_localstack_product(),
6866
edition=os.getenv("LOCALSTACK_TELEMETRY_EDITION") or get_localstack_edition(),
6967
)
7068

@@ -127,6 +125,18 @@ def get_localstack_edition() -> str:
127125
return version_file.removesuffix("-version").removeprefix(".") if version_file else "unknown"
128126

129127

128+
def get_localstack_product() -> str:
129+
"""
130+
Returns the telemetry product name from the env var, runtime, or "unknown".
131+
"""
132+
try:
133+
runtime_product = get_current_runtime().components.name
134+
except ValueError:
135+
runtime_product = None
136+
137+
return os.getenv("LOCALSTACK_TELEMETRY_PRODUCT") or runtime_product or "unknown"
138+
139+
130140
def is_license_activated() -> bool:
131141
try:
132142
from localstack.pro.core import config # noqa

tests/unit/utils/analytics/conftest.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from localstack import config
4-
from localstack.runtime.current import set_current_runtime
4+
from localstack.runtime.current import get_current_runtime, set_current_runtime
55

66

77
@pytest.fixture(autouse=True)
@@ -20,7 +20,12 @@ class MockRuntime:
2020

2121
@pytest.fixture(autouse=True)
2222
def mock_runtime():
23-
runtime = MockRuntime()
24-
set_current_runtime(runtime)
25-
yield
26-
set_current_runtime(None)
23+
try:
24+
# don't do anything if a runtime is set
25+
get_current_runtime()
26+
yield
27+
except ValueError:
28+
# set a mock runtime if no runtime is set
29+
set_current_runtime(MockRuntime())
30+
yield
31+
set_current_runtime(None)

0 commit comments

Comments
 (0)
0