Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
fix: make DO_NOT_TRACK behave as specified (#692)
Browse files Browse the repository at this point in the history
fix: empty DO_NOT_TRACK should be considered a false
  • Loading branch information
chamini2 authored Dec 16, 2022
1 parent 622d00f commit 14e7767
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
17 changes: 9 additions & 8 deletions adapter/src/dbt/adapters/fal_experimental/telemetry/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

invocation_id = uuid.uuid4()


def shutdown():
posthog.shutdown()
# HACK: while https://github.com/PostHog/posthog-python/pull/52 happens
Expand Down Expand Up @@ -167,19 +168,20 @@ def check_uid():
return conf.get("uid") or "NO_UID", None, False


def is_telemetry_enabled():
def check_stats_enabled():
"""
Check if the user allows us to use telemetry. In order of precedence:
1. If FAL_STATS_ENABLED is defined, check its value
2. If DO_NOT_TRACK is defined, check its value
3. Otherwise use the value in stats_enabled in the config.yaml file
"""
if "FAL_STATS_ENABLED" in os.environ:
return os.environ["FAL_STATS_ENABLED"].lower() == "true"
val = os.environ["FAL_STATS_ENABLED"].lower().strip()
return val != "0" and val != "false" and val != ""

if "DO_NOT_TRACK" in os.environ:
do_not_track = os.environ["DO_NOT_TRACK"].lower()
return do_not_track == "0" or do_not_track == "false"
val = os.environ["DO_NOT_TRACK"].lower().strip()
return val != "1" and val != "true"

# Check if local config exists
config_path = Path(check_dir_exist(CONF_DIR), "config.yaml")
Expand Down Expand Up @@ -233,7 +235,7 @@ def log_api(
timestamp, event id and stats information.
"""

if not is_telemetry_enabled():
if not check_stats_enabled():
return

if not is_online():
Expand All @@ -250,7 +252,7 @@ def log_api(
if "NO_UID" in uid:
additional_props["uid_issue"] = str(uid_error) if uid_error is not None else ""

config_hash = ''
config_hash = ""
if config is not None and hasattr(config, "hashed_name"):
config_hash = str(config.hashed_name())

Expand Down Expand Up @@ -283,7 +285,6 @@ def log_api(
if "argv" in all_props:
all_props["argv"] = _clean_args_list(all_props["argv"])


if is_install:
posthog.capture(distinct_id=uid, event="install_success", properties=all_props)

Expand Down Expand Up @@ -390,7 +391,7 @@ def _clean_args_list(args: List[str]) -> List[str]:
"source",
"test",
"rpc",
"run-operation"
"run-operation",
]
REDACTED = "[REDACTED]"
output = []
Expand Down
9 changes: 5 additions & 4 deletions src/fal/telemetry/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,12 @@ def check_stats_enabled():
3. Otherwise use the value in stats_enabled in the config.yaml file
"""
if "FAL_STATS_ENABLED" in os.environ:
return os.environ["FAL_STATS_ENABLED"].lower() == "true"
val = os.environ["FAL_STATS_ENABLED"].lower().strip()
return val != "0" and val != "false" and val != ""

if "DO_NOT_TRACK" in os.environ:
do_not_track = os.environ["DO_NOT_TRACK"].lower()
return do_not_track == "0" or do_not_track == "false"
val = os.environ["DO_NOT_TRACK"].lower().strip()
return val != "1" and val != "true"

# Check if local config exists
config_path = Path(check_dir_exist(CONF_DIR), "config.yaml")
Expand Down Expand Up @@ -404,7 +405,7 @@ def _clean_args_list(args: List[str]) -> List[str]:
"--vars",
"--var",
"--target",
"--globals"
"--globals",
]
REDACTED = "[REDACTED]"
output = []
Expand Down

0 comments on commit 14e7767

Please sign in to comment.