Skip to content

Commit b7ee1e0

Browse files
Implementation of Configurable Logging Control via Flag
1 parent 130cc02 commit b7ee1e0

File tree

10 files changed

+78
-75
lines changed

10 files changed

+78
-75
lines changed

infra/main.bicep

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,6 @@ var dnsZoneIndex = {
460460
sqlServer: 9
461461
search: 10
462462
}
463-
// List of DNS zone indices that correspond to AI-related services.
464-
var aiRelatedDnsZoneIndices = [
465-
dnsZoneIndex.cognitiveServices
466-
dnsZoneIndex.openAI
467-
dnsZoneIndex.aiServices
468-
]
469463

470464
// ===================================================
471465
// DEPLOY PRIVATE DNS ZONES
@@ -1571,6 +1565,8 @@ module webSiteBackend 'modules/web-sites.bicep' = {
15711565
SOLUTION_NAME: solutionSuffix
15721566
APP_ENV: 'Prod'
15731567
AZURE_CLIENT_ID: backendUserAssignedIdentity.outputs.clientId
1568+
AZURE_BASIC_LOGGING_LEVEL: 'INFO'
1569+
AZURE_PACKAGE_LOGGING_LEVEL: 'WARNING'
15741570
}
15751571
// WAF aligned configuration for Monitoring
15761572
applicationInsightResourceId: enableMonitoring ? applicationInsights!.outputs.resourceId : null

infra/main.json

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"_generator": {
77
"name": "bicep",
88
"version": "0.37.4.10188",
9-
"templateHash": "13729415444270857669"
9+
"templateHash": "14194719810689418497"
1010
}
1111
},
1212
"parameters": {
@@ -359,13 +359,8 @@
359359
"sqlServer": 9,
360360
"search": 10
361361
},
362-
"aiRelatedDnsZoneIndices": [
363-
"[variables('dnsZoneIndex').cognitiveServices]",
364-
"[variables('dnsZoneIndex').openAI]",
365-
"[variables('dnsZoneIndex').aiServices]"
366-
],
367362
"userAssignedIdentityResourceName": "[format('id-{0}', variables('solutionSuffix'))]",
368-
"sqlUserAssignedIdentityResourceName": "[format('id-sql-{0}', variables('solutionSuffix'))]",
363+
"backendUserAssignedIdentityResourceName": "[format('id-backend-{0}', variables('solutionSuffix'))]",
369364
"keyVaultName": "[format('kv-{0}', variables('solutionSuffix'))]",
370365
"existingOpenAIEndpoint": "[if(not(empty(parameters('existingAiFoundryAiProjectResourceId'))), format('https://{0}.openai.azure.com/', split(parameters('existingAiFoundryAiProjectResourceId'), '/')[8]), '')]",
371366
"existingProjEndpoint": "[if(not(empty(parameters('existingAiFoundryAiProjectResourceId'))), format('https://{0}.services.ai.azure.com/api/projects/{1}', split(parameters('existingAiFoundryAiProjectResourceId'), '/')[8], split(parameters('existingAiFoundryAiProjectResourceId'), '/')[10]), '')]",
@@ -20485,18 +20480,18 @@
2048520480
}
2048620481
}
2048720482
},
20488-
"sqlUserAssignedIdentity": {
20483+
"backendUserAssignedIdentity": {
2048920484
"type": "Microsoft.Resources/deployments",
2049020485
"apiVersion": "2022-09-01",
20491-
"name": "[take(format('avm.res.managed-identity.user-assigned-identity.{0}', variables('sqlUserAssignedIdentityResourceName')), 64)]",
20486+
"name": "[take(format('avm.res.managed-identity.user-assigned-identity.{0}', variables('backendUserAssignedIdentityResourceName')), 64)]",
2049220487
"properties": {
2049320488
"expressionEvaluationOptions": {
2049420489
"scope": "inner"
2049520490
},
2049620491
"mode": "Incremental",
2049720492
"parameters": {
2049820493
"name": {
20499-
"value": "[variables('sqlUserAssignedIdentityResourceName')]"
20494+
"value": "[variables('backendUserAssignedIdentityResourceName')]"
2050020495
},
2050120496
"location": {
2050220497
"value": "[parameters('location')]"
@@ -24333,6 +24328,11 @@
2433324328
"principalId": "[reference('userAssignedIdentity').outputs.principalId.value]",
2433424329
"principalType": "ServicePrincipal"
2433524330
},
24331+
{
24332+
"roleDefinitionIdOrName": "53ca6127-db72-4b80-b1b0-d745d6d5456d",
24333+
"principalId": "[reference('backendUserAssignedIdentity').outputs.principalId.value]",
24334+
"principalType": "ServicePrincipal"
24335+
},
2433624336
{
2433724337
"roleDefinitionIdOrName": "64702f94-c441-49e6-a78b-ef80e0188fee",
2433824338
"principalId": "[reference('userAssignedIdentity').outputs.principalId.value]",
@@ -24342,6 +24342,16 @@
2434224342
"roleDefinitionIdOrName": "5e0bd9bd-7b93-4f28-af87-19fc36ad61bd",
2434324343
"principalId": "[reference('userAssignedIdentity').outputs.principalId.value]",
2434424344
"principalType": "ServicePrincipal"
24345+
},
24346+
{
24347+
"roleDefinitionIdOrName": "64702f94-c441-49e6-a78b-ef80e0188fee",
24348+
"principalId": "[reference('backendUserAssignedIdentity').outputs.principalId.value]",
24349+
"principalType": "ServicePrincipal"
24350+
},
24351+
{
24352+
"roleDefinitionIdOrName": "5e0bd9bd-7b93-4f28-af87-19fc36ad61bd",
24353+
"principalId": "[reference('backendUserAssignedIdentity').outputs.principalId.value]",
24354+
"principalType": "ServicePrincipal"
2434524355
}
2434624356
]
2434724357
},
@@ -30052,9 +30062,10 @@
3005230062
}
3005330063
},
3005430064
"dependsOn": [
30055-
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').cognitiveServices)]",
30056-
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').openAI)]",
3005730065
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').aiServices)]",
30066+
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').openAI)]",
30067+
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').cognitiveServices)]",
30068+
"backendUserAssignedIdentity",
3005830069
"logAnalyticsWorkspace",
3005930070
"userAssignedIdentity",
3006030071
"virtualNetwork"
@@ -32381,8 +32392,8 @@
3238132392
},
3238232393
"dependsOn": [
3238332394
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').cognitiveServices)]",
32384-
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').openAI)]",
3238532395
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').aiServices)]",
32396+
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').openAI)]",
3238632397
"logAnalyticsWorkspace",
3238732398
"userAssignedIdentity",
3238832399
"virtualNetwork"
@@ -32448,6 +32459,11 @@
3244832459
"principalId": "[reference('userAssignedIdentity').outputs.principalId.value]",
3244932460
"principalType": "ServicePrincipal"
3245032461
},
32462+
{
32463+
"roleDefinitionIdOrName": "1407120a-92aa-4202-b7e9-c0e197c71c8f",
32464+
"principalId": "[reference('backendUserAssignedIdentity').outputs.principalId.value]",
32465+
"principalType": "ServicePrincipal"
32466+
},
3245132467
{
3245232468
"roleDefinitionIdOrName": "1407120a-92aa-4202-b7e9-c0e197c71c8f",
3245332469
"principalId": "[if(not(variables('useExistingAiFoundryAiProject')), reference('aiFoundryAiServices').outputs.aiProjectInfo.value.aiprojectSystemAssignedMIPrincipalId, reference('existingAiFoundryAiServicesProject', '2025-04-01-preview', 'full').identity.principalId)]",
@@ -34771,6 +34787,7 @@
3477134787
"dependsOn": [
3477234788
"aiFoundryAiServices",
3477334789
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').search)]",
34790+
"backendUserAssignedIdentity",
3477434791
"existingAiFoundryAiServicesProject",
3477534792
"logAnalyticsWorkspace",
3477634793
"userAssignedIdentity",
@@ -40746,10 +40763,10 @@
4074640763
}
4074740764
},
4074840765
"dependsOn": [
40749-
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').storageBlob)]",
4075040766
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').storageFile)]",
40751-
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').storageDfs)]",
4075240767
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').storageQueue)]",
40768+
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').storageDfs)]",
40769+
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').storageBlob)]",
4075340770
"userAssignedIdentity",
4075440771
"virtualNetwork"
4075540772
]
@@ -40802,7 +40819,7 @@
4080240819
],
4080340820
"assignments": [
4080440821
{
40805-
"principalId": "[reference('userAssignedIdentity').outputs.principalId.value]"
40822+
"principalId": "[reference('backendUserAssignedIdentity').outputs.principalId.value]"
4080640823
}
4080740824
]
4080840825
}
@@ -44587,9 +44604,9 @@
4458744604
},
4458844605
"dependsOn": [
4458944606
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').cosmosDB)]",
44607+
"backendUserAssignedIdentity",
4459044608
"logAnalyticsWorkspace",
4459144609
"storageAccount",
44592-
"userAssignedIdentity",
4459344610
"virtualNetwork"
4459444611
]
4459544612
},
@@ -44645,7 +44662,8 @@
4464544662
"value": {
4464644663
"systemAssigned": true,
4464744664
"userAssignedResourceIds": [
44648-
"[reference('userAssignedIdentity').outputs.resourceId.value]"
44665+
"[reference('userAssignedIdentity').outputs.resourceId.value]",
44666+
"[reference('backendUserAssignedIdentity').outputs.resourceId.value]"
4464944667
]
4465044668
}
4465144669
},
@@ -51230,6 +51248,7 @@
5123051248
},
5123151249
"dependsOn": [
5123251250
"[format('avmPrivateDnsZones[{0}]', variables('dnsZoneIndex').sqlServer)]",
51251+
"backendUserAssignedIdentity",
5123351252
"logAnalyticsWorkspace",
5123451253
"userAssignedIdentity",
5123551254
"virtualNetwork"
@@ -52437,7 +52456,7 @@
5243752456
"value": true
5243852457
},
5243952458
"arguments": {
52440-
"value": "[join(createArray(format('-SqlServerName ''{0}''', variables('sqlServerResourceName')), format('-SqlDatabaseName ''{0}''', variables('sqlDbModuleName')), format('-ClientId ''{0}''', reference('sqlUserAssignedIdentity').outputs.clientId.value), format('-DisplayName ''{0}''', reference('sqlUserAssignedIdentity').outputs.name.value), format('-DatabaseRoles ''{0}''', join(variables('databaseRoles'), ','))), ' ')]"
52459+
"value": "[join(createArray(format('-SqlServerName ''{0}''', variables('sqlServerResourceName')), format('-SqlDatabaseName ''{0}''', variables('sqlDbModuleName')), format('-ClientId ''{0}''', reference('backendUserAssignedIdentity').outputs.clientId.value), format('-DisplayName ''{0}''', reference('backendUserAssignedIdentity').outputs.name.value), format('-DatabaseRoles ''{0}''', join(variables('databaseRoles'), ','))), ' ')]"
5244152460
},
5244252461
"scriptContent": {
5244352462
"value": "[variables('$fxv#0')]"
@@ -52985,8 +53004,8 @@
5298553004
}
5298653005
},
5298753006
"dependsOn": [
53007+
"backendUserAssignedIdentity",
5298853008
"sqlDBModule",
52989-
"sqlUserAssignedIdentity",
5299053009
"storageAccount",
5299153010
"userAssignedIdentity",
5299253011
"virtualNetwork"
@@ -53022,7 +53041,7 @@
5302253041
},
5302353042
"diagnosticSettings": "[if(parameters('enableMonitoring'), createObject('value', createArray(createObject('workspaceResourceId', if(variables('useExistingLogAnalytics'), parameters('existingLogAnalyticsWorkspaceId'), reference('logAnalyticsWorkspace').outputs.resourceId.value)))), createObject('value', null()))]",
5302453043
"skuName": "[if(or(parameters('enableScalability'), parameters('enableRedundancy')), createObject('value', 'P1v3'), createObject('value', 'B3'))]",
53025-
"skuCapacity": "[if(parameters('enableScalability'), createObject('value', 3), createObject('value', 1))]",
53044+
"skuCapacity": "[if(parameters('enableScalability'), createObject('value', 1), createObject('value', 1))]",
5302653045
"zoneRedundant": "[if(parameters('enableRedundancy'), createObject('value', true()), createObject('value', false()))]"
5302753046
},
5302853047
"template": {
@@ -53592,7 +53611,7 @@
5359253611
"value": {
5359353612
"systemAssigned": true,
5359453613
"userAssignedResourceIds": [
53595-
"[reference('userAssignedIdentity').outputs.resourceId.value]"
53614+
"[reference('backendUserAssignedIdentity').outputs.resourceId.value]"
5359653615
]
5359753616
}
5359853617
},
@@ -53622,7 +53641,7 @@
5362253641
"AZURE_COSMOSDB_ENABLE_FEEDBACK": "True",
5362353642
"SQLDB_DATABASE": "[format('sqldb-{0}', variables('solutionSuffix'))]",
5362453643
"SQLDB_SERVER": "[format('{0}{1}', reference('sqlDBModule').outputs.name.value, environment().suffixes.sqlServerHostname)]",
53625-
"SQLDB_USER_MID": "[reference('sqlUserAssignedIdentity').outputs.clientId.value]",
53644+
"SQLDB_USER_MID": "[reference('backendUserAssignedIdentity').outputs.clientId.value]",
5362653645
"AZURE_AI_SEARCH_ENDPOINT": "[format('https://{0}.search.windows.net', variables('aiSearchName'))]",
5362753646
"AZURE_AI_SEARCH_INDEX": "call_transcripts_index",
5362853647
"AZURE_AI_SEARCH_CONNECTION_NAME": "[variables('aiSearchName')]",
@@ -53632,7 +53651,9 @@
5363253651
"DUMMY_TEST": "True",
5363353652
"SOLUTION_NAME": "[variables('solutionSuffix')]",
5363453653
"APP_ENV": "Prod",
53635-
"AZURE_CLIENT_ID": "[reference('userAssignedIdentity').outputs.clientId.value]"
53654+
"AZURE_CLIENT_ID": "[reference('backendUserAssignedIdentity').outputs.clientId.value]",
53655+
"AZURE_BASIC_LOGGING_LEVEL": "INFO",
53656+
"AZURE_PACKAGE_LOGGING_LEVEL": "WARNING"
5363653657
},
5363753658
"applicationInsightResourceId": "[if(parameters('enableMonitoring'), reference('applicationInsights').outputs.resourceId.value, null())]"
5363853659
}
@@ -55628,11 +55649,10 @@
5562855649
"dependsOn": [
5562955650
"aiFoundryAiServices",
5563055651
"applicationInsights",
55652+
"backendUserAssignedIdentity",
5563155653
"cosmosDb",
5563255654
"logAnalyticsWorkspace",
5563355655
"sqlDBModule",
55634-
"sqlUserAssignedIdentity",
55635-
"userAssignedIdentity",
5563655656
"virtualNetwork",
5563755657
"webServerFarm"
5563855658
]
@@ -57876,7 +57896,7 @@
5787657896
"metadata": {
5787757897
"description": "Contains SQL database user managed identity client ID."
5787857898
},
57879-
"value": "[reference('sqlUserAssignedIdentity').outputs.clientId.value]"
57899+
"value": "[reference('backendUserAssignedIdentity').outputs.clientId.value]"
5788057900
},
5788157901
"USE_AI_PROJECT_CLIENT": {
5788257902
"type": "string",

src/api/.env.sample

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ SQLDB_DATABASE=
2424
SQLDB_SERVER=
2525
USE_CHAT_HISTORY_ENABLED="True"
2626
APP_ENV="dev"
27+
# Basic application logging (default: INFO level)
28+
AZURE_BASIC_LOGGING_LEVEL=INFO
29+
# Azure package logging (default: WARNING level to suppress INFO)
30+
AZURE_PACKAGE_LOGGING_LEVEL=WARNING
31+
# Comma-separated list of specific logger names to configure (default: empty - no custom loggers)
32+
# Example: AZURE_LOGGING_PACKAGES=azure.identity.aio._internal,azure.monitor.opentelemetry.exporter.export._base
33+
AZURE_LOGGING_PACKAGES=

src/api/api/api_routes.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
router = APIRouter()
2020

21-
# Configure logging
22-
logging.basicConfig(level=logging.INFO)
2321
logger = logging.getLogger(__name__)
2422

2523
# Check if the Application Insights Instrumentation Key is set in the environment variables
@@ -32,20 +30,6 @@
3230
# Log a warning if the Instrumentation Key is not found
3331
logging.warning("No Application Insights Instrumentation Key found. Skipping configuration")
3432

35-
# Configure logging
36-
logging.basicConfig(level=logging.INFO)
37-
38-
# Suppress INFO logs from 'azure.core.pipeline.policies.http_logging_policy'
39-
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(
40-
logging.WARNING
41-
)
42-
logging.getLogger("azure.identity.aio._internal").setLevel(logging.WARNING)
43-
44-
# Suppress info logs from OpenTelemetry exporter
45-
logging.getLogger("azure.monitor.opentelemetry.exporter.export._base").setLevel(
46-
logging.WARNING
47-
)
48-
4933

5034
@router.get("/fetchChartData")
5135
async def fetch_chart_data():

src/api/api/history_routes.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
router = APIRouter()
1313

14-
# Configure logging
15-
logging.basicConfig(level=logging.INFO)
1614
logger = logging.getLogger(__name__)
1715

1816
# Check if the Application Insights Instrumentation Key is set in the environment variables
@@ -25,20 +23,6 @@
2523
# Log a warning if the Instrumentation Key is not found
2624
logging.warning("No Application Insights Instrumentation Key found. Skipping configuration")
2725

28-
# Configure logging
29-
logging.basicConfig(level=logging.INFO)
30-
31-
# Suppress INFO logs from 'azure.core.pipeline.policies.http_logging_policy'
32-
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(
33-
logging.WARNING
34-
)
35-
logging.getLogger("azure.identity.aio._internal").setLevel(logging.WARNING)
36-
37-
# Suppress info logs from OpenTelemetry exporter
38-
logging.getLogger("azure.monitor.opentelemetry.exporter.export._base").setLevel(
39-
logging.WARNING
40-
)
41-
4226
# Single instance of HistoryService (if applicable)
4327
history_service = HistoryService()
4428

src/api/app.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"""
88

99

10+
import logging
11+
import os
1012
from contextlib import asynccontextmanager
1113
from fastapi import FastAPI
1214
from fastapi.middleware.cors import CORSMiddleware
@@ -21,8 +23,28 @@
2123
from api.api_routes import router as backend_router
2224
from api.history_routes import router as history_router
2325

26+
# Load environment variables
2427
load_dotenv()
2528

29+
# Configure logging
30+
# Basic application logging (default: INFO level)
31+
AZURE_BASIC_LOGGING_LEVEL = os.getenv("AZURE_BASIC_LOGGING_LEVEL", "INFO").upper()
32+
# Azure package logging (default: WARNING level to suppress INFO)
33+
AZURE_PACKAGE_LOGGING_LEVEL = os.getenv("AZURE_PACKAGE_LOGGING_LEVEL", "WARNING").upper()
34+
# Azure logging packages (default: empty list)
35+
azure_logging_packages_env = os.getenv("AZURE_LOGGING_PACKAGES")
36+
AZURE_LOGGING_PACKAGES = azure_logging_packages_env.split(",") if azure_logging_packages_env else []
37+
38+
# Basic config: logging.basicConfig(level=logging.INFO)
39+
logging.basicConfig(
40+
level=getattr(logging, AZURE_BASIC_LOGGING_LEVEL, logging.INFO),
41+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
42+
)
43+
44+
# Package config: Azure loggers set to WARNING to suppress INFO
45+
for logger_name in AZURE_LOGGING_PACKAGES:
46+
logging.getLogger(logger_name).setLevel(getattr(logging, AZURE_PACKAGE_LOGGING_LEVEL, logging.WARNING))
47+
2648

2749
@asynccontextmanager
2850
async def lifespan(fastapi_app: FastAPI):

src/api/helpers/utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55

66
import requests
77

8-
DEBUG = os.environ.get("DEBUG", "false")
9-
if DEBUG.lower() == "true":
10-
logging.basicConfig(level=logging.DEBUG)
11-
128
AZURE_SEARCH_PERMITTED_GROUPS_COLUMN = os.environ.get(
139
"AZURE_SEARCH_PERMITTED_GROUPS_COLUMN"
1410
)

src/api/services/chart_service.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from api.models.input_models import ChartFilters
55
from common.database.sqldb_service import adjust_processed_data_dates, fetch_chart_data, fetch_filters_data
66

7-
# Configure logging
8-
logging.basicConfig(level=logging.INFO)
97
logger = logging.getLogger(__name__)
108

119

0 commit comments

Comments
 (0)