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

Commit 8f926a8

Browse files
committed
send analytics event for non-prefixed CLI env var usage
1 parent 1ff7a48 commit 8f926a8

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

localstack-core/localstack/utils/bootstrap.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ def config_env_vars(cfg: ContainerConfiguration):
513513
if config.LOADED_PROFILES:
514514
load_environment(profiles=",".join(config.LOADED_PROFILES), env=profile_env)
515515

516+
non_prefixed_env_vars = []
516517
for env_var in config.CONFIG_ENV_VARS:
517518
value = os.environ.get(env_var, None)
518519
if value is not None:
@@ -521,17 +522,29 @@ def config_env_vars(cfg: ContainerConfiguration):
521522
and not env_var.startswith("LOCALSTACK_")
522523
and env_var not in profile_env
523524
):
524-
# Show a warning here in case we are directly forwarding an environment variable from
525-
# the system env to the container which has not been prefixed with LOCALSTACK_.
526-
# Suppress the warning for the "CI" env var.
527-
# Suppress the warning if the env var was set from the profile.
528-
LOG.warning(
529-
"Non-prefixed environment variable %(env_var)s is forwarded to the LocalStack container! "
530-
"Please use `LOCALSTACK_%(env_var)s` instead of %(env_var)s to explicitly mark this environment variable to be forwarded form the CLI to the LocalStack Runtime.",
531-
{"env_var": env_var},
532-
)
525+
# Collect all env vars that are directly forwarded from the system env
526+
# to the container which has not been prefixed with LOCALSTACK_ here.
527+
# Suppress the "CI" env var.
528+
# Suppress if the env var was set from the profile.
529+
non_prefixed_env_vars.append(env_var)
533530
cfg.env_vars[env_var] = value
534531

532+
# collectively log deprecation warnings for non-prefixed sys env vars
533+
if non_prefixed_env_vars:
534+
from localstack.utils.analytics import log
535+
536+
for non_prefixed_env_var in non_prefixed_env_vars:
537+
# Show a deprecation warning for each individual env var collected above
538+
LOG.warning(
539+
"Non-prefixed environment variable %(env_var)s is forwarded to the LocalStack container! "
540+
"Please use `LOCALSTACK_%(env_var)s` instead of %(env_var)s to explicitly mark this environment variable to be forwarded form the CLI to the LocalStack Runtime.",
541+
{"env_var": non_prefixed_env_var},
542+
)
543+
544+
log.event(
545+
event="non_prefixed_cli_env_vars", payload={"env_vars": non_prefixed_env_vars}
546+
)
547+
535548
@staticmethod
536549
def random_gateway_port(cfg: ContainerConfiguration):
537550
"""Gets a random port on the host and maps it to the default edge port 4566."""

tests/bootstrap/test_container_configurators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test_container_configurator_no_deprecation_warning_on_prefix(
191191
assert "LOCALSTACK_SERVICES" in container.config.env_vars
192192

193193

194-
def test_container_configurator_no_deprecation_warning_for_CI_env_var(
194+
def test_container_configurator_no_deprecation_warning_for_ci_env_var(
195195
container_factory, monkeypatch, caplog
196196
):
197197
# set the "CI" env var indicating that we are running in a CI environment

0 commit comments

Comments
 (0)