Skip to content

Commit 60cb139

Browse files
committed
add logging for basic container information
1 parent 1195593 commit 60cb139

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

localstack/runtime/analytics.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33

4+
from localstack import config
45
from localstack.runtime import hooks
56
from localstack.utils.analytics import log
67

@@ -70,3 +71,32 @@ def _publish_config_as_analytics_event():
7071
present_env_vars = {env_var: 1 for env_var in PRESENCE_ENV_VAR if os.getenv(env_var)}
7172

7273
log.event("config", env_vars=env_vars, set_vars=present_env_vars)
74+
75+
76+
class LocalstackContainerInfo:
77+
def get_image_variant(self) -> str:
78+
for f in os.listdir("/usr/lib/localstack"):
79+
if f.startswith(".") and f.endswith("-version"):
80+
return f[1:-8]
81+
return "unknown"
82+
83+
def has_docker_socket(self) -> bool:
84+
return os.path.exists("/run/docker.sock")
85+
86+
def to_dict(self):
87+
return {
88+
"variant": self.get_image_variant(),
89+
"has_docker_socket": self.has_docker_socket(),
90+
}
91+
92+
93+
@hooks.on_infra_start()
94+
def _publish_container_info():
95+
if not config.is_in_docker:
96+
return
97+
98+
try:
99+
log.event("container_info", payload=LocalstackContainerInfo().to_dict())
100+
except Exception as e:
101+
if config.DEBUG_ANALYTICS:
102+
LOG.debug("error gathering container information: %s", e)

0 commit comments

Comments
 (0)