diff --git a/src/snowflake/cli/api/commands/execution_metadata.py b/src/snowflake/cli/api/commands/execution_metadata.py index 7d5464af3e..b53ab72943 100644 --- a/src/snowflake/cli/api/commands/execution_metadata.py +++ b/src/snowflake/cli/api/commands/execution_metadata.py @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import time -from dataclasses import dataclass +import uuid +from dataclasses import dataclass, field from enum import Enum @@ -23,10 +24,10 @@ class ExecutionStatus(Enum): @dataclass class ExecutionMetadata: - execution_id: str - start_time: float = 0 - end_time: float = 0 + start_time: float = 0.0 + end_time: float = 0.0 status: ExecutionStatus = ExecutionStatus.SUCCESS + execution_id: str = field(default_factory=lambda: uuid.uuid4().hex) def __post_init__(self): self.start_time = time.monotonic() @@ -35,5 +36,5 @@ def complete(self, status: ExecutionStatus): self.end_time = time.monotonic() self.status = status - def duration(self): + def get_duration(self): return self.end_time - self.start_time diff --git a/src/snowflake/cli/api/commands/snow_typer.py b/src/snowflake/cli/api/commands/snow_typer.py index 56af8e9a01..64a4e2b4b2 100644 --- a/src/snowflake/cli/api/commands/snow_typer.py +++ b/src/snowflake/cli/api/commands/snow_typer.py @@ -16,7 +16,6 @@ import dataclasses import logging -import uuid from functools import wraps from typing import Any, Callable, Dict, List, Optional, Tuple @@ -96,7 +95,7 @@ def custom_command(command_callable): @wraps(command_callable) def command_callable_decorator(*args, **kw): """Wrapper around command callable. This is what happens at "runtime".""" - execution = ExecutionMetadata(uuid.uuid4().hex) + execution = ExecutionMetadata() self.pre_execute(execution) try: result = command_callable(*args, **kw) diff --git a/src/snowflake/cli/app/telemetry.py b/src/snowflake/cli/app/telemetry.py index 8bd310d00f..95cd9fb041 100644 --- a/src/snowflake/cli/app/telemetry.py +++ b/src/snowflake/cli/app/telemetry.py @@ -164,7 +164,7 @@ def log_command_result(execution: ExecutionMetadata): TelemetryField.KEY_TYPE: TelemetryEvent.CMD_EXECUTION_RESULT.value, CLITelemetryField.COMMAND_EXECUTION_ID: execution.execution_id, CLITelemetryField.COMMAND_RESULT_STATUS: execution.status.value, - CLITelemetryField.COMMAND_EXECUTION_TIME: execution.duration(), + CLITelemetryField.COMMAND_EXECUTION_TIME: execution.get_duration(), } ) @@ -179,7 +179,7 @@ def log_command_execution_error(exception: Exception, execution: ExecutionMetada CLITelemetryField.COMMAND_EXECUTION_ID: execution.execution_id, CLITelemetryField.ERROR_TYPE: exception_type, CLITelemetryField.IS_CLI_EXCEPTION: is_cli_exception, - CLITelemetryField.COMMAND_EXECUTION_TIME: execution.duration(), + CLITelemetryField.COMMAND_EXECUTION_TIME: execution.get_duration(), } )