Skip to content

Commit 560076b

Browse files
committed
Update condition for running in production for credential
1 parent d49f60c commit 560076b

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

app/backend/app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,14 @@ async def setup_clients():
440440
USE_SPEECH_OUTPUT_BROWSER = os.getenv("USE_SPEECH_OUTPUT_BROWSER", "").lower() == "true"
441441
USE_SPEECH_OUTPUT_AZURE = os.getenv("USE_SPEECH_OUTPUT_AZURE", "").lower() == "true"
442442

443+
# WEBSITE_HOSTNAME is always set by App Service, RUNNING_IN_PRODUCTION is set in main.bicep
444+
RUNNING_ON_AZURE = os.getenv("WEBSITE_HOSTNAME") is not None or os.getenv("RUNNING_IN_PRODUCTION") is not None
445+
443446
# Use the current user identity for keyless authentication to Azure services.
444447
# This assumes you use 'azd auth login' locally, and managed identity when deployed on Azure.
445448
# The managed identity is setup in the infra/ folder.
446449
azure_credential: Union[AzureDeveloperCliCredential, ManagedIdentityCredential]
447-
if os.getenv("WEBSITE_HOSTNAME"): # Environment variable set on Azure Web Apps
450+
if RUNNING_ON_AZURE:
448451
current_app.logger.info("Setting up Azure credential using ManagedIdentityCredential")
449452
azure_credential = ManagedIdentityCredential()
450453
elif AZURE_TENANT_ID:

docs/appservice.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,17 @@ To see any exceptions and server errors, navigate to the _Investigate -> Failure
631631

632632
## Configuring log levels
633633

634-
By default, the deployed app only logs messages with a level of `WARNING` or higher.
634+
By default, the deployed app only logs messages from packages with a level of `WARNING` or higher,
635+
but logs all messages from the app with a level of `INFO` or higher.
635636

636637
These lines of code in `app/backend/app.py` configure the logging level:
637638

638639
```python
640+
# Set root level to WARNING to avoid seeing overly verbose logs from SDKS
641+
logging.basicConfig(level=logging.WARNING)
642+
# Set the app logger level to INFO by default
639643
default_level = "INFO"
640-
if os.getenv("WEBSITE_HOSTNAME"): # In production, don't log as heavily
641-
default_level = "WARNING"
642-
logging.basicConfig(level=os.getenv("APP_LOG_LEVEL", default_level))
644+
app.logger.setLevel(os.getenv("APP_LOG_LEVEL", default_level))
643645
```
644646

645647
To change the default level, either change `default_level` or set the `APP_LOG_LEVEL` environment variable

infra/main.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ var appEnvVariables = {
353353
AZURE_DOCUMENTINTELLIGENCE_SERVICE: documentIntelligence.outputs.name
354354
USE_LOCAL_PDF_PARSER: useLocalPdfParser
355355
USE_LOCAL_HTML_PARSER: useLocalHtmlParser
356+
RUNNING_IN_PRODUCTION: 'true'
356357
}
357358

358359
// App Service for the web application (Python Quart app with JS frontend)

0 commit comments

Comments
 (0)