Azure function fastapi endpoint log is not appearing in the application insights
We are facing an issue with the logging functionality in an Azure Function App using FastAPI. Specifically, logging.info
statements are not displaying logs in Application Insights, which makes it difficult to monitor and troubleshoot the function. Below are the details of the current environment:
- Azure Function Plan: Flex Consumption Plan
- SDK: Python
- Python Version: 3.10
- Function Runtime Version: 4
- Function App version: 1.21.3
host.json
{
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
},
"extensions": {
"http": {
"routePrefix": ""
}
},
"logging": {
"applicationInsights": {
"samplingSettings": {
"excludedTypes": "Request",
"isEnabled": true
}
},
"logLevel": {
"default": "Information",
"Host.Aggregator": "Trace"
}
},
"version": "2.0"
}
except Exception as e:
import logging
logging.error(f"Exception: {e}")
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="An unexpected error",
) from e
import azure.functions as func
from functions.api.api import app_fastapi
app = func.AsgiFunctionApp(app=app_fastapi, http_auth_level=func.AuthLevel.ANONYMOUS)
Despite configuring logging and utilizing the standard logging.info
statements in the FastAPI endpoints, the logs are not being captured or displayed in Application Insights. The issue persists across multiple function invocations, and there is no indication in Application Insights that the log messages are being sent.
We are seeking a solution or investigation into why the logging.info
statements are not being displayed in Application Insights and how to resolve the issue.