diff --git a/azure/durable_functions/models/DurableOrchestrationContext.py b/azure/durable_functions/models/DurableOrchestrationContext.py index b25683da..784f1247 100644 --- a/azure/durable_functions/models/DurableOrchestrationContext.py +++ b/azure/durable_functions/models/DurableOrchestrationContext.py @@ -1,7 +1,9 @@ import json import datetime +import inspect from typing import List, Any, Dict, Optional from uuid import UUID, uuid5, NAMESPACE_URL +from datetime import timezone from .RetryOptions import RetryOptions from .TaskSet import TaskSet @@ -459,3 +461,15 @@ def new_guid(self) -> UUID: self._new_uuid_counter += 1 guid = uuid5(NAMESPACE_URL, guid_name) return guid + + def _pretty_print_history(self) -> str: + """Get a pretty-printed version of the orchestration's internal history.""" + def history_to_string(event): + json_dict = {} + for key, val in inspect.getmembers(event): + if not key.startswith('_') and not inspect.ismethod(val): + if isinstance(val, datetime.date): + val = val.replace(tzinfo=timezone.utc).timetuple() + json_dict[key] = val + return json.dumps(json_dict) + return str(list(map(history_to_string, self._histories)))