Skip to content

Commit 216160a

Browse files
fixed app insights logging issue
1 parent 01e9292 commit 216160a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

content-gen/src/backend/app.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from services.blob_service import get_blob_service
2525
from services.title_service import get_title_service
2626
from api.admin import admin_bp
27+
from azure.monitor.opentelemetry import configure_azure_monitor
2728

2829
# In-memory task storage for generation tasks
2930
# In production, this should be replaced with Redis or similar
@@ -37,6 +38,16 @@
3738
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(logging.WARNING)
3839
logger = logging.getLogger(__name__)
3940

41+
# Check if the Application Insights Instrumentation Key is set in the environment variables
42+
instrumentation_key = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
43+
if instrumentation_key:
44+
# Configure Application Insights if the Instrumentation Key is found
45+
configure_azure_monitor(connection_string=instrumentation_key)
46+
logging.info("Application Insights configured with the provided Instrumentation Key")
47+
else:
48+
# Log a warning if the Instrumentation Key is not found
49+
logging.warning("No Application Insights Instrumentation Key found. Skipping configuration")
50+
4051
# Create Quart app
4152
app = Quart(__name__)
4253
app = cors(app, allow_origin="*")

0 commit comments

Comments
 (0)