• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

localstack / localstack / 287d2d5f-77c6-4688-a935-5247d99c1a92

18 Mar 2025 09:15PM UTC coverage: 86.828% (-0.09%) from 86.915%
287d2d5f-77c6-4688-a935-5247d99c1a92

push

circleci

web-flow
APIGW: migrate to new Counter type for REST API analytics (#12383)

8 of 8 new or added lines in 1 file covered. (100.0%)

129 existing lines in 10 files now uncovered.

62766 of 72288 relevant lines covered (86.83%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.84
/localstack-core/localstack/runtime/analytics.py
1
import logging
1✔
2
import os
1✔
3

4
from localstack import config
1✔
5
from localstack.runtime import hooks
1✔
6
from localstack.utils.analytics import log
1✔
7

8
LOG = logging.getLogger(__name__)
1✔
9

10
TRACKED_ENV_VAR = [
1✔
11
    "ALLOW_NONSTANDARD_REGIONS",
12
    "BEDROCK_PREWARM",
13
    "CONTAINER_RUNTIME",
14
    "DEBUG",
15
    "DEFAULT_REGION",  # Not functional; deprecated in 0.12.7, removed in 3.0.0
16
    "DEFAULT_BEDROCK_MODEL",
17
    "DISABLE_CORS_CHECK",
18
    "DISABLE_CORS_HEADERS",
19
    "DMS_SERVERLESS_DEPROVISIONING_DELAY",
20
    "DMS_SERVERLESS_STATUS_CHANGE_WAITING_TIME",
21
    "DNS_ADDRESS",
22
    "DYNAMODB_ERROR_PROBABILITY",
23
    "DYNAMODB_IN_MEMORY",
24
    "DYNAMODB_REMOVE_EXPIRED_ITEMS",
25
    "EAGER_SERVICE_LOADING",
26
    "EC2_VM_MANAGER",
27
    "ECS_TASK_EXECUTOR",
28
    "EDGE_PORT",
29
    "ENABLE_REPLICATOR",
30
    "ENFORCE_IAM",
31
    "ES_CUSTOM_BACKEND",  # deprecated in 0.14.0, removed in 3.0.0
32
    "ES_MULTI_CLUSTER",  # deprecated in 0.14.0, removed in 3.0.0
33
    "ES_ENDPOINT_STRATEGY",  # deprecated in 0.14.0, removed in 3.0.0
34
    "EVENT_RULE_ENGINE",
35
    "IAM_SOFT_MODE",
36
    "KINESIS_PROVIDER",  # Not functional; deprecated in 2.0.0, removed in 3.0.0
37
    "KINESIS_ERROR_PROBABILITY",
38
    "KMS_PROVIDER",  # defunct since 1.4.0
39
    "LAMBDA_DEBUG_MODE",
40
    "LAMBDA_DOWNLOAD_AWS_LAYERS",
41
    "LAMBDA_EXECUTOR",  # Not functional; deprecated in 2.0.0, removed in 3.0.0
42
    "LAMBDA_STAY_OPEN_MODE",  # Not functional; deprecated in 2.0.0, removed in 3.0.0
43
    "LAMBDA_REMOTE_DOCKER",  # Not functional; deprecated in 2.0.0, removed in 3.0.0
44
    "LAMBDA_CODE_EXTRACT_TIME",  # Not functional; deprecated in 2.0.0, removed in 3.0.0
45
    "LAMBDA_CONTAINER_REGISTRY",  # Not functional; deprecated in 2.0.0, removed in 3.0.0
46
    "LAMBDA_FALLBACK_URL",  # Not functional; deprecated in 2.0.0, removed in 3.0.0
47
    "LAMBDA_FORWARD_URL",  # Not functional; deprecated in 2.0.0, removed in 3.0.0
48
    "LAMBDA_XRAY_INIT",  # Not functional; deprecated in 2.0.0, removed in 3.0.0
49
    "LAMBDA_PREBUILD_IMAGES",
50
    "LAMBDA_RUNTIME_EXECUTOR",
51
    "LAMBDA_RUNTIME_ENVIRONMENT_TIMEOUT",
52
    "LEGACY_EDGE_PROXY",  # Not functional; deprecated in 1.0.0, removed in 2.0.0
53
    "LS_LOG",
54
    "MOCK_UNIMPLEMENTED",  # Not functional; deprecated in 1.3.0, removed in 3.0.0
55
    "OPENSEARCH_ENDPOINT_STRATEGY",
56
    "PERSISTENCE",
57
    "PERSISTENCE_SINGLE_FILE",
58
    "PERSIST_ALL",  # defunct since 2.3.2
59
    "PORT_WEB_UI",
60
    "RDS_MYSQL_DOCKER",
61
    "REQUIRE_PRO",
62
    "SERVICES",
63
    "STRICT_SERVICE_LOADING",
64
    "SKIP_INFRA_DOWNLOADS",
65
    "SQS_ENDPOINT_STRATEGY",
66
    "USE_SINGLE_REGION",  # Not functional; deprecated in 0.12.7, removed in 3.0.0
67
    "USE_SSL",
68
]
69

70
PRESENCE_ENV_VAR = [
1✔
71
    "DATA_DIR",
72
    "EDGE_FORWARD_URL",  # Not functional; deprecated in 1.4.0, removed in 3.0.0
73
    "GATEWAY_LISTEN",
74
    "HOSTNAME",
75
    "HOSTNAME_EXTERNAL",
76
    "HOSTNAME_FROM_LAMBDA",
77
    "HOST_TMP_FOLDER",  # Not functional; deprecated in 1.0.0, removed in 2.0.0
78
    "INIT_SCRIPTS_PATH",  # Not functional; deprecated in 1.1.0, removed in 2.0.0
79
    "LAMBDA_DEBUG_MODE_CONFIG_PATH",
80
    "LEGACY_DIRECTORIES",  # Not functional; deprecated in 1.1.0, removed in 2.0.0
81
    "LEGACY_INIT_DIR",  # Not functional; deprecated in 1.1.0, removed in 2.0.0
82
    "LOCALSTACK_HOST",
83
    "LOCALSTACK_HOSTNAME",
84
    "OUTBOUND_HTTP_PROXY",
85
    "OUTBOUND_HTTPS_PROXY",
86
    "S3_DIR",
87
    "TMPDIR",
88
]
89

90

91
@hooks.on_infra_start()
1✔
92
def _publish_config_as_analytics_event():
1✔
93
    env_vars = list(TRACKED_ENV_VAR)
1✔
94

95
    for key, value in os.environ.items():
1✔
96
        if key.startswith("PROVIDER_OVERRIDE_"):
1✔
97
            env_vars.append(key)
1✔
98
        elif key.startswith("SYNCHRONOUS_") and key.endswith("_EVENTS"):
1✔
99
            # these config variables have been removed with 3.0.0
UNCOV
100
            env_vars.append(key)
×
101

102
    env_vars = {key: os.getenv(key) for key in env_vars}
1✔
103
    present_env_vars = {env_var: 1 for env_var in PRESENCE_ENV_VAR if os.getenv(env_var)}
1✔
104

105
    log.event("config", env_vars=env_vars, set_vars=present_env_vars)
1✔
106

107

108
class LocalstackContainerInfo:
1✔
109
    def get_image_variant(self) -> str:
1✔
110
        for f in os.listdir("/usr/lib/localstack"):
1✔
111
            if f.startswith(".") and f.endswith("-version"):
1✔
112
                return f[1:-8]
1✔
UNCOV
113
        return "unknown"
×
114

115
    def has_docker_socket(self) -> bool:
1✔
116
        return os.path.exists("/run/docker.sock")
1✔
117

118
    def to_dict(self):
1✔
119
        return {
1✔
120
            "variant": self.get_image_variant(),
121
            "has_docker_socket": self.has_docker_socket(),
122
        }
123

124

125
@hooks.on_infra_start()
1✔
126
def _publish_container_info():
1✔
127
    if not config.is_in_docker:
1✔
128
        return
1✔
129

130
    try:
1✔
131
        log.event("container_info", payload=LocalstackContainerInfo().to_dict())
1✔
132
    except Exception as e:
×
133
        if config.DEBUG_ANALYTICS:
×
UNCOV
134
            LOG.debug("error gathering container information: %s", e)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc