Skip to content

Commit befbb08

Browse files
bmehta001Copilot
andcommitted
Log workflow exceptions as error telemetry
Keep OliveRecipe focused on recipe outcome metadata and use the existing log_error path for workflow exceptions. This avoids duplicating exception fields on recipe events while preserving detailed formatted exception messages in error telemetry. Files changed: - olive/telemetry/telemetry_extensions.py - olive/telemetry/telemetry.py - olive/workflows/run/run.py - test/workflows/test_workflow_run.py Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d9247e2 commit befbb08

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

olive/telemetry/telemetry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
"workflow_id",
8383
"config_overrides",
8484
"success",
85-
"exception_type",
8685
"input_model_type",
8786
"input_model_source",
8887
"model_task",

olive/telemetry/telemetry_extensions.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,12 @@ def log_recipe_result(
4949
recipe_name: str,
5050
success: bool,
5151
metadata: Optional[dict[str, Any]] = None,
52-
exception_type: Optional[str] = None,
5352
) -> None:
5453
telemetry = _get_logger()
5554
attributes = {
5655
"recipe_name": recipe_name,
5756
"success": success,
5857
}
59-
if exception_type:
60-
attributes["exception_type"] = exception_type
6158
telemetry.log(RECIPE_EVENT_NAME, attributes, metadata)
6259

6360

olive/workflows/run/run.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from olive.systems.common import SystemType
2222
from olive.telemetry.constants import SUPPRESS_WORKFLOW_TELEMETRY_ENV
2323
from olive.telemetry.telemetry import is_ci_environment
24-
from olive.telemetry.telemetry_extensions import log_recipe_result
24+
from olive.telemetry.telemetry_extensions import _format_exception_message, log_error, log_recipe_result
2525
from olive.workflows.run.config import RunConfig
2626

2727
if TYPE_CHECKING:
@@ -213,7 +213,7 @@ def run(
213213

214214
parsed_run_config = None
215215
success = False
216-
exception_type = None
216+
exception = None
217217
try:
218218
package_config = OlivePackageConfig.parse_file_or_obj(package_config)
219219
parsed_run_config = RunConfig.parse_file_or_obj(run_config)
@@ -238,9 +238,14 @@ def run(
238238
success = True
239239
return workflow_output
240240
except Exception as exc:
241-
exception_type = type(exc).__name__
241+
exception = exc
242242
raise
243243
finally:
244+
if exception is not None:
245+
log_error(
246+
exception_type=type(exception).__name__,
247+
exception_message=_format_exception_message(exception, exception.__traceback__),
248+
)
244249
if os.environ.get(SUPPRESS_WORKFLOW_TELEMETRY_ENV) != "1":
245250
metadata = _build_recipe_result_metadata(
246251
run_config,
@@ -252,7 +257,7 @@ def run(
252257
package_config_provided=package_config_provided,
253258
)
254259
recipe_name = metadata.pop("recipe_name")
255-
log_recipe_result(recipe_name, success=success, metadata=metadata, exception_type=exception_type)
260+
log_recipe_result(recipe_name, success=success, metadata=metadata)
256261

257262

258263
def generate_files_from_packages(packages, file_name):

test/workflows/test_workflow_run.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,10 @@ def test_run_logs_recipe_result_success(_, mock_run_engine, mock_log_recipe_resu
200200
assert config_overrides["systems"][0]["accelerators"][0]["execution_providers"] == ["CUDAExecutionProvider"]
201201

202202

203+
@patch("olive.workflows.run.run.log_error")
203204
@patch("olive.workflows.run.run.log_recipe_result")
204205
@patch("olive.workflows.run.run.run_engine")
205-
def test_run_logs_recipe_result_failure(mock_run_engine, mock_log_recipe_result):
206+
def test_run_logs_recipe_result_failure(mock_run_engine, mock_log_recipe_result, mock_log_error):
206207
config = {
207208
"input_model": {
208209
"type": "HfModel",
@@ -228,7 +229,10 @@ def test_run_logs_recipe_result_failure(mock_run_engine, mock_log_recipe_result)
228229
mock_log_recipe_result.assert_called_once()
229230
assert mock_log_recipe_result.call_args.args[0] == "Quantize"
230231
assert mock_log_recipe_result.call_args.kwargs["success"] is False
231-
assert mock_log_recipe_result.call_args.kwargs["exception_type"] == "ValueError"
232+
assert "exception_type" not in mock_log_recipe_result.call_args.kwargs
233+
mock_log_error.assert_called_once()
234+
assert mock_log_error.call_args.kwargs["exception_type"] == "ValueError"
235+
assert "recipe failed" in mock_log_error.call_args.kwargs["exception_message"]
232236

233237

234238
@patch("olive.workflows.run.run.log_recipe_result")

0 commit comments

Comments
 (0)