Skip to content

Commit b00f9e0

Browse files
authored
Merge pull request #525 from d1mashok/trace-logging-fix
Agent Trace logging - fix
2 parents 522b268 + 83ad5cc commit b00f9e0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

agents-and-function-calling/bedrock-agents/features-examples/06-prompt-and-session-attributes/06-prompt-and-session-attributes.ipynb

+11-1
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,16 @@
903903
"outputs": [],
904904
"source": [
905905
"%%time\n",
906+
"import json\n",
907+
"from datetime import datetime\n",
908+
"\n",
909+
"class DateTimeEncoder(json.JSONEncoder):\n",
910+
" def default(self, obj):\n",
911+
" if isinstance(obj, datetime):\n",
912+
" return obj.isoformat()\n",
913+
" return super().default(obj)\n",
914+
"\n",
915+
"\n",
906916
"event_stream = agentResponse['completion']\n",
907917
"try:\n",
908918
" for event in event_stream: \n",
@@ -913,7 +923,7 @@
913923
" end_event_received = True\n",
914924
" # End event indicates that the request finished successfully\n",
915925
" elif 'trace' in event:\n",
916-
" logger.info(json.dumps(event['trace'], indent=2))\n",
926+
" logger.info(json.dumps(event['trace'], indent=2, cls=DateTimeEncoder))\n",
917927
" else:\n",
918928
" raise Exception(\"unexpected event.\", event)\n",
919929
"except Exception as e:\n",

0 commit comments

Comments
 (0)