Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
ops: Mark suppressed exceptions as OK
Clémence Lesnéf00ee70f4bcb
diff --git a/app/helpers/call_utils.py b/app/helpers/call_utils.pyindex c2b568d..c3c6e27 100644--- a/app/helpers/call_utils.py+++ b/app/helpers/call_utils.py@@ -3,7 +3,7 @@ import jsonimport reimport timefrom collections.abc import AsyncGenerator, Awaitable, Callable, Generator-from contextlib import asynccontextmanager, contextmanager, suppress+from contextlib import asynccontextmanager, contextmanagerfrom enum import Enumfrom typing import Any@@ -55,6 +55,7 @@ from app.helpers.monitoring import (call_stt_complete_latency,counter_add,gauge_set,+ suppress,)from app.models.call import CallStateModelfrom app.models.message import (@@ -113,9 +114,7 @@ class ContextEnum(str, Enum):"""Transfer failed"""-def tts_sentence_split(- text: str, include_last: bool-) -> Generator[tuple[str, int]]:+def tts_sentence_split(text: str, include_last: bool) -> Generator[tuple[str, int]]:"""Split a text into sentences.diff --git a/app/helpers/monitoring.py b/app/helpers/monitoring.pyindex 510b4c3..d2d8e21 100644--- a/app/helpers/monitoring.py+++ b/app/helpers/monitoring.py@@ -1,3 +1,4 @@+from contextlib import contextmanagerfrom enum import Enumfrom os import environ@@ -6,6 +7,7 @@ from opentelemetry import metrics, tracefrom opentelemetry.instrumentation.aiohttp_client import AioHttpClientInstrumentorfrom opentelemetry.metrics._internal.instrument import Counter, Gaugefrom opentelemetry.semconv.attributes import service_attributes+from opentelemetry.trace import Status, StatusCodefrom opentelemetry.trace.span import INVALID_SPANfrom opentelemetry.util.types import AttributeValuefrom structlog.contextvars import bind_contextvars, get_contextvars@@ -169,3 +171,20 @@ def counter_add(**get_contextvars(),},)+++@contextmanager+def suppress(*exceptions):+ """+ Context manager to suppress exceptions, while also logging them properly in OTEL.++ OTEL span will always be set to OK status, even if an exception occurs. But exception will still be recorded.+ """+ try:+ # Try executing the block+ yield+ # If an exception occurs, set the span status to OK and record the exception+ except exceptions as e:+ span = trace.get_current_span()+ span.set_status(Status(StatusCode.OK))+ span.record_exception(e)diff --git a/app/main.py b/app/main.pyindex 4a934bf..cfccdbb 100644--- a/app/main.py+++ b/app/main.py@@ -2,7 +2,7 @@ import asyncioimport jsonimport timefrom base64 import b64decode, b64encode-from contextlib import asynccontextmanager, suppress+from contextlib import asynccontextmanagerfrom datetime import timedeltafrom http import HTTPStatusfrom os import getenv@@ -65,6 +65,7 @@ from app.helpers.monitoring import (call_frames_in_latency,call_frames_out_latency,gauge_set,+ suppress,tracer,)from app.helpers.pydantic_types.phone_numbers import PhoneNumberdiff --git a/app/persistence/ai_search.py b/app/persistence/ai_search.pyindex 24ae49a..0ed403c 100644--- a/app/persistence/ai_search.py+++ b/app/persistence/ai_search.py@@ -1,5 +1,3 @@-from contextlib import suppress-from azure.core.exceptions import (HttpResponseError,ResourceExistsError,@@ -50,6 +48,7 @@ from app.helpers.config_models.ai_search import AiSearchModelfrom app.helpers.http import azure_transportfrom app.helpers.identity import credentialfrom app.helpers.logging import logger+from app.helpers.monitoring import suppressfrom app.models.readiness import ReadinessEnumfrom app.models.training import TrainingModelfrom app.persistence.icache import ICachediff --git a/app/persistence/cosmos_db.py b/app/persistence/cosmos_db.pyindex 9c637dd..2382f5e 100644--- a/app/persistence/cosmos_db.py+++ b/app/persistence/cosmos_db.py@@ -1,6 +1,6 @@import asynciofrom collections.abc import AsyncGenerator-from contextlib import asynccontextmanager, suppress+from contextlib import asynccontextmanagerfrom typing import Anyfrom uuid import UUID, uuid4@@ -16,6 +16,7 @@ from app.helpers.features import callback_timeout_hourfrom app.helpers.http import azure_transportfrom app.helpers.identity import credentialfrom app.helpers.logging import logger+from app.helpers.monitoring import suppressfrom app.models.call import CallStateModelfrom app.models.readiness import ReadinessEnumfrom app.persistence.icache import ICachediff --git a/app/persistence/memory.py b/app/persistence/memory.pyindex 738860f..3b5e01b 100644--- a/app/persistence/memory.py+++ b/app/persistence/memory.py@@ -1,9 +1,9 @@import hashlibfrom collections import OrderedDict-from contextlib import suppressfrom datetime import UTC, datetime, timedeltafrom app.helpers.config_models.cache import MemoryModel+from app.helpers.monitoring import suppressfrom app.models.readiness import ReadinessEnumfrom app.persistence.icache import ICache