From e8b9cc00357b03972c88ade38d17ea48012e5572 Mon Sep 17 00:00:00 2001 From: Ajit Padhi Date: Thu, 20 Nov 2025 17:29:09 +0530 Subject: [PATCH 1/4] Implementation of Configurable Logging Control via Flag --- infra/main.bicep | 2 ++ src/App/.env.sample | 5 +++++ src/App/app.py | 21 +++++++++++++-------- src/App/backend/common/config.py | 8 ++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/infra/main.bicep b/infra/main.bicep index eeddf4169..e840628a0 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -1122,6 +1122,8 @@ module webSite 'modules/web-sites.bicep' = { AZURE_SEARCH_STRICTNESS: azureSearchStrictness AZURE_OPENAI_EMBEDDING_NAME: embeddingModel AZURE_OPENAI_EMBEDDING_ENDPOINT : aiFoundryAiServices.outputs.endpoint + AZURE_BASIC_LOGGING_LEVEL: 'INFO' + AZURE_PACKAGE_LOGGING_LEVEL: 'WARNING' SQLDB_SERVER: sqlServerFqdn SQLDB_DATABASE: sqlDbName USE_INTERNAL_STREAM: useInternalStream diff --git a/src/App/.env.sample b/src/App/.env.sample index 53ae69bf2..3ad8478af 100644 --- a/src/App/.env.sample +++ b/src/App/.env.sample @@ -12,6 +12,11 @@ AZURE_OPENAI_ENDPOINT= AZURE_OPENAI_EMBEDDING_NAME="text-embedding-ada-002" AZURE_OPENAI_EMBEDDING_ENDPOINT= +# Logging settings +AZURE_BASIC_LOGGING_LEVEL="INFO" +AZURE_PACKAGE_LOGGING_LEVEL="WARNING" +# AZURE_LOGGING_PACKAGES="azure.core.pipeline.policies.http_logging_policy,azure.identity.aio._internal,azure.monitor.opentelemetry.exporter.export._base" + # User Interface UI_TITLE= UI_LOGO= diff --git a/src/App/app.py b/src/App/app.py index 0f154083e..545f465b2 100644 --- a/src/App/app.py +++ b/src/App/app.py @@ -56,18 +56,23 @@ ) # Configure logging -logging.basicConfig(level=logging.INFO) +basic_level = getattr( + logging, config.AZURE_BASIC_LOGGING_LEVEL.upper(), logging.INFO +) +logging.basicConfig(level=basic_level) -# Suppress INFO logs from 'azure.core.pipeline.policies.http_logging_policy' -logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel( - logging.WARNING +# Configure Azure package logging levels +azure_packages_env = os.environ.get("AZURE_LOGGING_PACKAGES") +azure_packages = ( + [pkg.strip() for pkg in azure_packages_env.split(',')] + if azure_packages_env else [] ) -logging.getLogger("azure.identity.aio._internal").setLevel(logging.WARNING) -# Suppress info logs from OpenTelemetry exporter -logging.getLogger("azure.monitor.opentelemetry.exporter.export._base").setLevel( - logging.WARNING +package_level = getattr( + logging, config.AZURE_PACKAGE_LOGGING_LEVEL.upper(), logging.WARNING ) +for package in azure_packages: + logging.getLogger(package).setLevel(package_level) def create_app(): diff --git a/src/App/backend/common/config.py b/src/App/backend/common/config.py index 49775830f..b3e33ae0a 100644 --- a/src/App/backend/common/config.py +++ b/src/App/backend/common/config.py @@ -35,6 +35,14 @@ def __init__(self): "APPLICATIONINSIGHTS_CONNECTION_STRING" ) + # Azure Logging Configuration + self.AZURE_BASIC_LOGGING_LEVEL = os.environ.get( + "AZURE_BASIC_LOGGING_LEVEL", "INFO" + ) + self.AZURE_PACKAGE_LOGGING_LEVEL = os.environ.get( + "AZURE_PACKAGE_LOGGING_LEVEL", "WARNING" + ) + self.DEBUG = os.environ.get("DEBUG", "false") # Current minimum Azure OpenAI version supported From 1b08365d69b2f40a146237504c146d3b70b16cf7 Mon Sep 17 00:00:00 2001 From: Ajit Padhi Date: Tue, 25 Nov 2025 12:28:08 +0530 Subject: [PATCH 2/4] bicep updated --- infra/main.bicep | 1 + infra/main.json | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/infra/main.bicep b/infra/main.bicep index e840628a0..1acdaec7f 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -1124,6 +1124,7 @@ module webSite 'modules/web-sites.bicep' = { AZURE_OPENAI_EMBEDDING_ENDPOINT : aiFoundryAiServices.outputs.endpoint AZURE_BASIC_LOGGING_LEVEL: 'INFO' AZURE_PACKAGE_LOGGING_LEVEL: 'WARNING' + AZURE_LOGGING_PACKAGES: '' SQLDB_SERVER: sqlServerFqdn SQLDB_DATABASE: sqlDbName USE_INTERNAL_STREAM: useInternalStream diff --git a/infra/main.json b/infra/main.json index db7909f83..515dc388d 100644 --- a/infra/main.json +++ b/infra/main.json @@ -6,7 +6,7 @@ "_generator": { "name": "bicep", "version": "0.37.4.10188", - "templateHash": "16197733130303817508" + "templateHash": "10200691163213391924" } }, "parameters": { @@ -29912,8 +29912,8 @@ } }, "dependsOn": [ - "[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').cognitiveServices)]", "[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').aiServices)]", + "[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').cognitiveServices)]", "logAnalyticsWorkspace", "userAssignedIdentity", "virtualNetwork" @@ -39522,8 +39522,8 @@ } }, "dependsOn": [ - "[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').storageQueue)]", "[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').storageBlob)]", + "[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').storageQueue)]", "keyvault", "userAssignedIdentity", "virtualNetwork" @@ -49989,6 +49989,9 @@ "AZURE_SEARCH_STRICTNESS": "[variables('azureSearchStrictness')]", "AZURE_OPENAI_EMBEDDING_NAME": "[parameters('embeddingModel')]", "AZURE_OPENAI_EMBEDDING_ENDPOINT": "[reference('aiFoundryAiServices').outputs.endpoint.value]", + "AZURE_BASIC_LOGGING_LEVEL": "INFO", + "AZURE_PACKAGE_LOGGING_LEVEL": "WARNING", + "AZURE_LOGGING_PACKAGES": "", "SQLDB_SERVER": "[variables('sqlServerFqdn')]", "SQLDB_DATABASE": "[variables('sqlDbName')]", "USE_INTERNAL_STREAM": "[variables('useInternalStream')]", From 30ae6c544bf2e2d402f5958827ceca432b0930a6 Mon Sep 17 00:00:00 2001 From: Ajit Padhi Date: Fri, 28 Nov 2025 11:54:41 +0530 Subject: [PATCH 3/4] updated bicep --- infra/main_custom.bicep | 3 +++ 1 file changed, 3 insertions(+) diff --git a/infra/main_custom.bicep b/infra/main_custom.bicep index f089dbf27..376b29465 100644 --- a/infra/main_custom.bicep +++ b/infra/main_custom.bicep @@ -970,6 +970,9 @@ module webSite 'modules/web-sites.bicep' = { AZURE_SEARCH_STRICTNESS: azureSearchStrictness AZURE_OPENAI_EMBEDDING_NAME: embeddingModel AZURE_OPENAI_EMBEDDING_ENDPOINT : aiFoundryAiServices.outputs.endpoints['OpenAI Language Model Instance API'] + AZURE_BASIC_LOGGING_LEVEL: 'INFO' + AZURE_PACKAGE_LOGGING_LEVEL: 'WARNING' + AZURE_LOGGING_PACKAGES: '' SQLDB_SERVER: sqlServerFqdn SQLDB_DATABASE: sqlDbName USE_INTERNAL_STREAM: useInternalStream From 7f978601bc56f9a674698f776ff92713f646174e Mon Sep 17 00:00:00 2001 From: Ajit Padhi Date: Fri, 28 Nov 2025 12:02:46 +0530 Subject: [PATCH 4/4] updated custom bicep --- infra/main_custom.bicep | 3 +++ 1 file changed, 3 insertions(+) diff --git a/infra/main_custom.bicep b/infra/main_custom.bicep index 160358b12..01261e0bc 100644 --- a/infra/main_custom.bicep +++ b/infra/main_custom.bicep @@ -1126,6 +1126,9 @@ module webSite 'modules/web-sites.bicep' = { AZURE_SEARCH_STRICTNESS: azureSearchStrictness AZURE_OPENAI_EMBEDDING_NAME: embeddingModel AZURE_OPENAI_EMBEDDING_ENDPOINT : aiFoundryAiServices.outputs.endpoint + AZURE_BASIC_LOGGING_LEVEL: 'INFO' + AZURE_PACKAGE_LOGGING_LEVEL: 'WARNING' + AZURE_LOGGING_PACKAGES: '' SQLDB_SERVER: sqlServerFqdn SQLDB_DATABASE: sqlDbName USE_INTERNAL_STREAM: useInternalStream