|
1 | 1 | # app_kernel.py |
2 | 2 | import asyncio |
3 | 3 | import logging |
| 4 | +import os |
4 | 5 | import uuid |
5 | 6 | from typing import Dict, List, Optional |
6 | 7 |
|
|
9 | 10 | from auth.auth_utils import get_authenticated_user_details |
10 | 11 |
|
11 | 12 | # Azure monitoring |
| 13 | +from azure.monitor.opentelemetry import configure_azure_monitor |
12 | 14 | from config_kernel import Config |
13 | 15 | from event_utils import track_event_if_configured |
14 | 16 |
|
|
32 | 34 | # Updated import for KernelArguments |
33 | 35 | from utils_kernel import initialize_runtime_and_context, rai_success |
34 | 36 |
|
35 | | -# # Check if the Application Insights Instrumentation Key is set in the environment variables |
36 | | -# connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING") |
37 | | -# if connection_string: |
38 | | -# # Configure Application Insights if the Instrumentation Key is found |
39 | | -# configure_azure_monitor(connection_string=connection_string) |
40 | | -# logging.info( |
41 | | -# "Application Insights configured with the provided Instrumentation Key" |
42 | | -# ) |
43 | | -# else: |
44 | | -# # Log a warning if the Instrumentation Key is not found |
45 | | -# logging.warning( |
46 | | -# "No Application Insights Instrumentation Key found. Skipping configuration" |
47 | | -# ) |
| 37 | +# Check if the Application Insights Instrumentation Key is set in the environment variables |
| 38 | +connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING") |
| 39 | +if connection_string: |
| 40 | + # Configure Application Insights if the Instrumentation Key is found |
| 41 | + configure_azure_monitor(connection_string=connection_string) |
| 42 | + logging.info( |
| 43 | + "Application Insights configured with the provided Instrumentation Key" |
| 44 | + ) |
| 45 | +else: |
| 46 | + # Log a warning if the Instrumentation Key is not found |
| 47 | + logging.warning( |
| 48 | + "No Application Insights Instrumentation Key found. Skipping configuration" |
| 49 | + ) |
48 | 50 |
|
49 | 51 | # Configure logging |
50 | 52 | logging.basicConfig(level=logging.INFO) |
@@ -137,9 +139,8 @@ async def input_task_endpoint(input_task: InputTask, request: Request): |
137 | 139 | # Convert input task to JSON for the kernel function, add user_id here |
138 | 140 |
|
139 | 141 | # Use the planner to handle the task |
140 | | - result = await group_chat_manager.handle_input_task(input_task) |
| 142 | + await group_chat_manager.handle_input_task(input_task) |
141 | 143 |
|
142 | | - print(f"Result: {result}") |
143 | 144 | # Get plan from memory store |
144 | 145 | plan = await memory_store.get_plan_by_session(input_task.session_id) |
145 | 146 |
|
@@ -176,7 +177,6 @@ async def input_task_endpoint(input_task: InputTask, request: Request): |
176 | 177 | } |
177 | 178 |
|
178 | 179 | except Exception as e: |
179 | | - logging.exception(f"Error handling input task: {e}") |
180 | 180 | track_event_if_configured( |
181 | 181 | "InputTaskError", |
182 | 182 | { |
@@ -779,18 +779,17 @@ async def delete_all_messages(request: Request) -> Dict[str, str]: |
779 | 779 | authenticated_user = get_authenticated_user_details(request_headers=request.headers) |
780 | 780 | user_id = authenticated_user["user_principal_id"] |
781 | 781 | if not user_id: |
| 782 | + track_event_if_configured( |
| 783 | + "UserIdNotFound", {"status_code": 400, "detail": "no user"} |
| 784 | + ) |
782 | 785 | raise HTTPException(status_code=400, detail="no user") |
783 | 786 |
|
784 | 787 | # Initialize memory context |
785 | 788 | kernel, memory_store = await initialize_runtime_and_context("", user_id) |
786 | 789 |
|
787 | | - logging.info("Deleting all plans") |
788 | 790 | await memory_store.delete_all_items("plan") |
789 | | - logging.info("Deleting all sessions") |
790 | 791 | await memory_store.delete_all_items("session") |
791 | | - logging.info("Deleting all steps") |
792 | 792 | await memory_store.delete_all_items("step") |
793 | | - logging.info("Deleting all agent_messages") |
794 | 793 | await memory_store.delete_all_items("agent_message") |
795 | 794 |
|
796 | 795 | # Clear the agent factory cache |
@@ -840,6 +839,9 @@ async def get_all_messages(request: Request): |
840 | 839 | authenticated_user = get_authenticated_user_details(request_headers=request.headers) |
841 | 840 | user_id = authenticated_user["user_principal_id"] |
842 | 841 | if not user_id: |
| 842 | + track_event_if_configured( |
| 843 | + "UserIdNotFound", {"status_code": 400, "detail": "no user"} |
| 844 | + ) |
843 | 845 | raise HTTPException(status_code=400, detail="no user") |
844 | 846 |
|
845 | 847 | # Initialize memory context |
|
0 commit comments