Skip to content

Commit

Permalink
wip: temporary log to chat metric group
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesLoder committed Dec 6, 2024
1 parent 9e9e17e commit 8381943
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This only needs to be done once.

### Deploy a development stack

1. [Log into AWS](http://docs.rdc.library.northwestern.edu/2._Developer_Guides/Environment_and_Tools/AWS-Authentication/) using your `staging-admin` profile.
1. [Log into AWS](http://docs.rdc.library.northwestern.edu/2._Developer_Guides/Environment_and_Tools/AWS-Authentication/) using your `staging-superuser` profile.
2. Pick a unique stack name, e.g., `dc-api-chat-[YOUR_INITIALS]`
3. Create or synchronize the development stack
```bash
Expand Down
15 changes: 14 additions & 1 deletion chat/src/handlers/chat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import secrets # noqa
import boto3
import json
import logging
import os
from datetime import datetime
Expand Down Expand Up @@ -65,7 +66,19 @@ def handler(event, context):
config={"configurable": {"thread_id": config.ref}},
)

print(response)
log_group = os.getenv('METRICS_LOG_GROUP')
log_stream = context.log_stream_name
if log_group and ensure_log_stream_exists(log_group, log_stream):
log_client = boto3.client('logs')
log_events = [
{
'timestamp': timestamp(),
'message': json.dumps(response)
}
]
log_client.put_log_events(logGroupName=log_group, logStreamName=log_stream, logEvents=log_events)

return {"statusCode": 200}


def reshape_response(response, type):
Expand Down

0 comments on commit 8381943

Please sign in to comment.