Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion localstack-core/localstack/utils/analytics/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from localstack import config
from localstack.constants import VERSION
from localstack.runtime import hooks
from localstack.runtime import get_current_runtime, hooks
from localstack.utils.bootstrap import Container
from localstack.utils.files import rm_rf
from localstack.utils.functions import call_safe
Expand All @@ -29,6 +29,8 @@ class ClientMetadata:
is_ci: bool
is_docker: bool
is_testing: bool
product: str
edition: str

def __repr__(self):
d = dataclasses.asdict(self)
Expand Down Expand Up @@ -60,6 +62,8 @@ def read_client_metadata() -> ClientMetadata:
is_ci=os.getenv("CI") is not None,
is_docker=config.is_in_docker,
is_testing=config.is_local_test_mode(),
product=get_localstack_product(),
edition=os.getenv("LOCALSTACK_TELEMETRY_EDITION") or get_localstack_edition(),
)


Expand Down Expand Up @@ -121,6 +125,18 @@ def get_localstack_edition() -> str:
return version_file.removesuffix("-version").removeprefix(".") if version_file else "unknown"


def get_localstack_product() -> str:
"""
Returns the telemetry product name from the env var, runtime, or "unknown".
"""
try:
runtime_product = get_current_runtime().components.name
except ValueError:
runtime_product = None

return os.getenv("LOCALSTACK_TELEMETRY_PRODUCT") or runtime_product or "unknown"


def is_license_activated() -> bool:
try:
from localstack.pro.core import config # noqa
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/utils/analytics/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
import pytest

from localstack import config
from localstack.runtime.current import get_current_runtime, set_current_runtime


@pytest.fixture(autouse=True)
def enable_analytics(monkeypatch):
"""Makes sure that all tests in this package are executed with analytics enabled."""
monkeypatch.setattr(config, "DISABLE_EVENTS", False)


class MockComponents:
name = "mock-product"


class MockRuntime:
components = MockComponents()


@pytest.fixture(autouse=True)
def mock_runtime():
try:
# don't do anything if a runtime is set
get_current_runtime()
yield
except ValueError:
# set a mock runtime if no runtime is set
set_current_runtime(MockRuntime())
yield
set_current_runtime(None)
Loading