Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
log: Enrich logger with context from call
Clémence Lesné78546d9c92e1
diff --git a/app/helpers/monitoring.py b/app/helpers/monitoring.pyindex 5687c02..204dbec 100644--- a/app/helpers/monitoring.py+++ b/app/helpers/monitoring.py@@ -6,6 +6,7 @@ from opentelemetry.instrumentation.aiohttp_client import AioHttpClientInstrumentfrom opentelemetry.instrumentation.httpx import HTTPXClientInstrumentorfrom opentelemetry.trace.span import INVALID_SPANfrom opentelemetry.util.types import AttributeValue+from structlog.contextvars import bind_contextvarsVERSION = environ.get("VERSION", "0.0.0-unknown")@@ -33,6 +34,10 @@ def span_attribute(key: str, value: AttributeValue) -> None:Returns None."""+ # Enrich logging+ bind_contextvars(**{key: value})++ # Enrich spanspan = trace.get_current_span()if span == INVALID_SPAN:returndiff --git a/app/main.py b/app/main.pyindex 652935c..b08185e 100644--- a/app/main.py+++ b/app/main.py@@ -542,7 +542,7 @@ async def communicationservices_wss_post(# Accept connectionawait websocket.accept()- logger.info("WebSocket connection established for call %s", call.call_id)+ logger.info("WebSocket connection established")# Client SDKautomation_client = await _use_automation_client()@@ -665,7 +665,7 @@ async def _communicationservices_event_worker(automation_client = await _use_automation_client()# Log- logger.debug("Call event received %s for call %s", event_type, call.call_id)+ logger.debug("Call event received %s", event_type)match event_type:case "Microsoft.Communication.CallConnected": # Call answered@@ -754,9 +754,13 @@ async def training_event(Returns None."""call = CallStateModel.model_validate_json(training.content)- logger.debug("Training event received for call %s", call)++ # Enrich spanspan_attribute(CallAttributes.CALL_ID, str(call.call_id))span_attribute(CallAttributes.CALL_PHONE_NUMBER, call.initiate.phone_number)++ logger.debug("Training event received")+await call.trainings(cache_only=False) # Get trainings by advance to populate cache@@ -773,9 +777,13 @@ async def post_event(if not call:logger.warning("Call %s not found", post.content)return- logger.debug("Post event received for call %s", call.call_id)++ # Enrich spanspan_attribute(CallAttributes.CALL_ID, str(call.call_id))span_attribute(CallAttributes.CALL_PHONE_NUMBER, call.initiate.phone_number)++ logger.debug("Post event received")+await on_end_call(call)