diff --git a/content-gen/src/backend/app.py b/content-gen/src/backend/app.py index 1e2a41b80..e1a429630 100644 --- a/content-gen/src/backend/app.py +++ b/content-gen/src/backend/app.py @@ -24,6 +24,7 @@ from services.blob_service import get_blob_service from services.title_service import get_title_service from api.admin import admin_bp +from azure.monitor.opentelemetry import configure_azure_monitor # In-memory task storage for generation tasks # In production, this should be replaced with Redis or similar @@ -37,6 +38,16 @@ logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(logging.WARNING) logger = logging.getLogger(__name__) +# Check if the Application Insights connection string is set in the environment variables +appinsights_connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING") +if appinsights_connection_string: + # Configure Application Insights if the connection string is found + configure_azure_monitor(connection_string=appinsights_connection_string) + logger.info("Application Insights configured with the provided connection string") +else: + # Log a warning if the connection string is not found + logger.warning("No Application Insights connection string found. Skipping configuration") + # Create Quart app app = Quart(__name__) app = cors(app, allow_origin="*") diff --git a/content-gen/src/backend/requirements.txt b/content-gen/src/backend/requirements.txt index e1471c19e..0b8cd1358 100644 --- a/content-gen/src/backend/requirements.txt +++ b/content-gen/src/backend/requirements.txt @@ -26,6 +26,9 @@ openai>=1.45.0 # HTTP Client (for Foundry direct API calls) httpx>=0.27.0 +# Monitoring / Telemetry +azure-monitor-opentelemetry>=1.6.0 + # Data Validation pydantic>=2.8.0 pydantic-settings>=2.4.0