Skip to content

Commit 2587b57

Browse files
committed
working version
1 parent 1518bec commit 2587b57

File tree

3 files changed

+350
-87
lines changed

3 files changed

+350
-87
lines changed

src/backend/app_kernel.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,6 @@ async def input_task_endpoint(input_task: InputTask, request: Request):
144144

145145
print(f"Plan: {plan}")
146146

147-
if not plan or not plan.id:
148-
# If plan not found by session, try to extract plan ID from result
149-
plan_id_match = re.search(r"Plan '([^']+)'", result)
150-
151-
if plan_id_match:
152-
plan_id = plan_id_match.group(1)
153-
plan = await memory_store.get_plan(plan_id)
154-
155-
# If still no plan found, handle the failure
156-
if not plan or not plan.id:
157-
track_event_if_configured(
158-
"PlanCreationFailed",
159-
{
160-
"session_id": input_task.session_id,
161-
"description": input_task.description,
162-
}
163-
)
164-
raise HTTPException(status_code=400, detail="Error: Failed to create plan")
165-
166147
# Log custom event for successful input task processing
167148
track_event_if_configured(
168149
"InputTaskProcessed",

src/backend/event_utils.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,24 @@
44

55

66
def track_event_if_configured(event_name: str, event_data: dict):
7-
instrumentation_key = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
8-
if instrumentation_key:
9-
track_event(event_name, event_data)
10-
# else:
11-
# logging.warning(f"Skipping track_event for {event_name} as Application Insights is not configured")
7+
"""Track an event if Application Insights is configured.
8+
9+
This function safely wraps the Azure Monitor track_event function
10+
to handle potential errors with the ProxyLogger.
11+
12+
Args:
13+
event_name: The name of the event to track
14+
event_data: Dictionary of event data/dimensions
15+
"""
16+
try:
17+
instrumentation_key = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
18+
if instrumentation_key:
19+
track_event(event_name, event_data)
20+
# else:
21+
# logging.warning(f"Skipping track_event for {event_name} as Application Insights is not configured")
22+
except AttributeError as e:
23+
# Handle the 'ProxyLogger' object has no attribute 'resource' error
24+
logging.warning(f"ProxyLogger error in track_event: {e}")
25+
except Exception as e:
26+
# Catch any other exceptions to prevent them from bubbling up
27+
logging.warning(f"Error in track_event: {e}")

0 commit comments

Comments
 (0)