From 8786be38491cfa8243378c4cf977f34cf96cd449 Mon Sep 17 00:00:00 2001 From: even-wei Date: Mon, 16 Dec 2024 17:40:26 +0800 Subject: [PATCH 1/2] Add cli args to Amplitude events Signed-off-by: even-wei --- recce/__init__.py | 7 +++++++ recce/event/__init__.py | 6 +++++- recce/event/track.py | 6 +++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/recce/__init__.py b/recce/__init__.py index 1d5cb2d6..7ac7237e 100644 --- a/recce/__init__.py +++ b/recce/__init__.py @@ -34,6 +34,13 @@ def get_runner(): return None +def get_cli_args(): + # Join all arguments starting from the script name + full_command_line = ' '.join(sys.argv) + + return full_command_line + + def get_version(): version_file = os.path.normpath(os.path.join(os.path.dirname(__file__), 'VERSION')) with open(version_file) as fh: diff --git a/recce/event/__init__.py b/recce/event/__init__.py index 070b6eda..a139fe49 100644 --- a/recce/event/__init__.py +++ b/recce/event/__init__.py @@ -9,7 +9,7 @@ import sentry_sdk -from recce import is_ci_env, get_version, get_runner +from recce import is_ci_env, get_version, get_runner, get_cli_args() from recce import yaml as pyml from recce.event.collector import Collector from recce.github import is_github_codespace, get_github_codespace_info, get_github_codespace_name, \ @@ -174,6 +174,10 @@ def log_event(prop, event_type, **kwargs): if runner == 'github codespaces': prop['codespaces_name'] = get_github_codespace_name() + cli_args = get_cli_args() + if cli_args is not None: + prop['cli_args'] = cli_args + payload = dict( **prop, ) diff --git a/recce/event/track.py b/recce/event/track.py index e9ea653e..1c37ce57 100644 --- a/recce/event/track.py +++ b/recce/event/track.py @@ -11,7 +11,7 @@ from rich.console import Console from rich.markup import escape -from recce import event, get_runner +from recce import event, get_runner, get_cli_args() from recce.core import load_context from recce.exceptions import RecceException from recce.git import current_branch, hosting_repo @@ -90,6 +90,7 @@ def invoke(self, ctx: Context) -> t.Any: end_time = time.time() duration = end_time - start_time runner = get_runner() + cli_args = get_cli() repo = hosting_repo() branch = current_branch() command = ctx.command.name @@ -103,6 +104,9 @@ def invoke(self, ctx: Context) -> t.Any: if runner is not None: props['runner_type'] = runner + if cli_args is not None: + props['cli_args'] = cli_args + if repo is not None: props['repository'] = sha256(repo.encode()).hexdigest() From e36309f4a871985819a75131a41ff5c6594e7d74 Mon Sep 17 00:00:00 2001 From: even-wei Date: Tue, 17 Dec 2024 15:32:30 +0800 Subject: [PATCH 2/2] Extract args and send with command events Signed-off-by: even-wei --- recce/__init__.py | 7 ------- recce/event/__init__.py | 6 +----- recce/event/track.py | 19 +++++++++++++------ 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/recce/__init__.py b/recce/__init__.py index 7ac7237e..1d5cb2d6 100644 --- a/recce/__init__.py +++ b/recce/__init__.py @@ -34,13 +34,6 @@ def get_runner(): return None -def get_cli_args(): - # Join all arguments starting from the script name - full_command_line = ' '.join(sys.argv) - - return full_command_line - - def get_version(): version_file = os.path.normpath(os.path.join(os.path.dirname(__file__), 'VERSION')) with open(version_file) as fh: diff --git a/recce/event/__init__.py b/recce/event/__init__.py index a139fe49..070b6eda 100644 --- a/recce/event/__init__.py +++ b/recce/event/__init__.py @@ -9,7 +9,7 @@ import sentry_sdk -from recce import is_ci_env, get_version, get_runner, get_cli_args() +from recce import is_ci_env, get_version, get_runner from recce import yaml as pyml from recce.event.collector import Collector from recce.github import is_github_codespace, get_github_codespace_info, get_github_codespace_name, \ @@ -174,10 +174,6 @@ def log_event(prop, event_type, **kwargs): if runner == 'github codespaces': prop['codespaces_name'] = get_github_codespace_name() - cli_args = get_cli_args() - if cli_args is not None: - prop['cli_args'] = cli_args - payload = dict( **prop, ) diff --git a/recce/event/track.py b/recce/event/track.py index 1c37ce57..755a2592 100644 --- a/recce/event/track.py +++ b/recce/event/track.py @@ -11,7 +11,7 @@ from rich.console import Console from rich.markup import escape -from recce import event, get_runner, get_cli_args() +from recce import event, get_runner from recce.core import load_context from recce.exceptions import RecceException from recce.git import current_branch, hosting_repo @@ -88,31 +88,38 @@ def invoke(self, ctx: Context) -> t.Any: sys.exit(1) finally: end_time = time.time() - duration = end_time - start_time runner = get_runner() - cli_args = get_cli() repo = hosting_repo() branch = current_branch() command = ctx.command.name + duration = end_time - start_time + target_path = ctx.params.get('target_path', None) + target_base_path = ctx.params.get('target_base_path', None) props = dict( command=command, status=status, reason=reason, duration=duration, + cloud=ctx.params.get('cloud', False), + review=ctx.params.get('review', False), + debug=ctx.params.get('debug', False), ) if runner is not None: props['runner_type'] = runner - if cli_args is not None: - props['cli_args'] = cli_args - if repo is not None: props['repository'] = sha256(repo.encode()).hexdigest() if branch is not None: props['branch'] = sha256(branch.encode()).hexdigest() + if target_path is not None: + props['target_path'] = sha256(target_path.encode()).hexdigest() + + if target_base_path is not None: + props['target_base_path'] = sha256(target_base_path.encode()).hexdigest() + try: recce_context = load_context() except Exception: