Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move usage telemetry to post_execute callback #1796

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/snowflake/cli/api/commands/snow_typer.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ def pre_execute(execution: ExecutionMetadata, require_warehouse: bool = False):
Pay attention to make this method safe to use if performed operations are not necessary
for executing the command in proper way.
"""
from snowflake.cli._app.telemetry import log_command_usage

log.debug("Executing command pre execution callback")
log_command_usage(execution)
if require_warehouse and not SqlExecutionMixin().session_has_warehouse():
raise ClickException(
"The command requires warehouse. No warehouse found in current connection."
Expand Down Expand Up @@ -166,9 +163,14 @@ def post_execute(execution: ExecutionMetadata):
Callback executed after running any command callable. Pay attention to make this method safe to
use if performed operations are not necessary for executing the command in proper way.
"""
from snowflake.cli._app.telemetry import flush_telemetry, log_command_result
from snowflake.cli._app.telemetry import (
flush_telemetry,
log_command_result,
log_command_usage,
)

log.debug("Executing command post execution callback")
log_command_usage(execution)
Copy link
Contributor

@sfc-gh-melnacouzi sfc-gh-melnacouzi Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean that commands that do not require connection will not be part of telemetry anymore?

log_command_result(execution)
flush_telemetry()

Expand Down
1 change: 1 addition & 0 deletions src/snowflake/cli/api/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def update(self, **updates):
setattr(self, key, value)

def update_from_config(self) -> ConnectionContext:
self.validate_and_complete()
sfc-gh-pjob marked this conversation as resolved.
Show resolved Hide resolved
connection_config = get_connection_dict(connection_name=self.connection_name)
if "private_key_path" in connection_config:
connection_config["private_key_file"] = connection_config[
Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_failing_executing_command_sends_telemetry_data(
# The method is called with a TelemetryData type, so we cast it to dict for simpler comparison
result_command_event = (
mock_conn.return_value._telemetry.try_add_log_to_batch.call_args_list[ # noqa: SLF001
1
0
sfc-gh-pjob marked this conversation as resolved.
Show resolved Hide resolved
]
.args[0]
.to_dict()
Expand Down
Loading