File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import sys
44
55import uvicorn
6+ from azure .monitor .opentelemetry import configure_azure_monitor
67from fastapi import FastAPI , HTTPException , Request
78from fastapi .middleware .cors import CORSMiddleware
89from fastapi .responses import JSONResponse
3435# Get logger for this module (logging already configured above)
3536logger = logging .getLogger (__name__ )
3637
38+ # Check if the Application Insights Instrumentation Key is set in the environment variables
39+ instrumentation_key = os .getenv ("APPLICATIONINSIGHTS_CONNECTION_STRING" )
40+ if instrumentation_key :
41+ # Configure Application Insights if the Instrumentation Key is found
42+ configure_azure_monitor (connection_string = instrumentation_key )
43+ logging .info ("Application Insights configured with the provided Instrumentation Key" )
44+ else :
45+ # Log a warning if the Instrumentation Key is not found
46+ logging .warning ("No Application Insights Instrumentation Key found. Skipping configuration" )
47+
3748# Create FastAPI app
3849app = FastAPI (
3950 title = settings .app_name ,
You can’t perform that action at this time.
0 commit comments