Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 759f1a6

Browse files
committed
improve system information sent in session and container_info
1 parent bb27e3e commit 759f1a6

2 files changed

Lines changed: 77 additions & 1 deletion

File tree

localstack-core/localstack/runtime/analytics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import os
3+
import platform
34

45
from localstack import config
56
from localstack.runtime import hooks
@@ -132,10 +133,21 @@ def get_image_variant(self) -> str:
132133
def has_docker_socket(self) -> bool:
133134
return os.path.exists("/run/docker.sock")
134135

136+
def uname(self) -> dict:
137+
result = platform.uname()
138+
return {
139+
"uname_system": result.system,
140+
"uname_release": result.release,
141+
"uname_version": result.version,
142+
"uname_machine": result.machine,
143+
}
144+
135145
def to_dict(self):
136146
return {
137147
"variant": self.get_image_variant(),
138148
"has_docker_socket": self.has_docker_socket(),
149+
"container_runtime": config.CONTAINER_RUNTIME,
150+
**self.uname(),
139151
}
140152

141153

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

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def read_client_metadata() -> ClientMetadata:
5656
session_id=get_session_id(),
5757
machine_id=get_machine_id(),
5858
api_key=get_api_key_or_auth_token() or "", # api key should not be None
59-
system=get_system(),
59+
system=get_system_information_summary(),
6060
version=get_version_string(),
6161
is_ci=os.getenv("CI") is not None,
6262
is_docker=config.is_in_docker,
@@ -215,6 +215,7 @@ def get_api_key_or_auth_token() -> str | None:
215215

216216
@singleton_factory
217217
def get_system() -> str:
218+
# TODO: candidate for removal
218219
try:
219220
# try to get the system from the docker socket
220221
from localstack.utils.docker_utils import DOCKER_CLIENT
@@ -231,6 +232,69 @@ def get_system() -> str:
231232
return platform.system().lower()
232233

233234

235+
@singleton_factory
236+
def get_system_information_summary() -> str:
237+
"""
238+
Returns a string that contains three comma-separated values: The operating system, kernel version,
239+
and architecture. We either use the docker socket to resolve the information, if that is not available
240+
we fall back ``platform.uname()``. If we're in docker and we don't have the docker socket available,
241+
we add ``(Container)`` to the operating system type to indicate that we don't have any additional
242+
information.
243+
244+
Some examples:
245+
246+
If the Docker socket is available:
247+
- Docker Desktop,5.15.90.1-microsoft-standard-WSL2,x86_64
248+
- Linux Mint 21.1,5.19.0-32-generic,x86_64
249+
250+
If the Docker socket is not available, and we're on the host:
251+
- Windows,10,AMD64
252+
- Linux,5.19.0-32-generic,x86_64
253+
254+
If the Docker socket is not available, and we're in the container:
255+
- Linux(Container),5.19.0-32-generic,x86_64
256+
257+
:return: A string representing the system's information
258+
"""
259+
try:
260+
# try to get the system from the docker socket
261+
from localstack.utils.docker_utils import DOCKER_CLIENT
262+
263+
system = DOCKER_CLIENT.get_system_info()
264+
265+
return ",".join(
266+
[
267+
system["OperatingSystem"],
268+
system["KernelVersion"],
269+
system["Architecture"],
270+
]
271+
)
272+
except Exception:
273+
if config.DEBUG_ANALYTICS:
274+
LOG.exception(
275+
"Unable to get system information from docker socket, falling back to platform.uname()"
276+
)
277+
278+
uname = platform.uname()
279+
280+
if config.is_in_docker:
281+
return ",".join(
282+
[
283+
f"{uname.system}(Container)",
284+
uname.release,
285+
uname.machine,
286+
]
287+
)
288+
289+
return ",".join(
290+
[
291+
uname.system,
292+
uname.release,
293+
uname.machine,
294+
]
295+
)
296+
297+
234298
@hooks.prepare_host()
235299
def prepare_host_machine_id():
236300
# lazy-init machine ID into cache on the host, which can then be used in the container

0 commit comments

Comments
 (0)