Skip to content

fix: fixed app insights logging issue#753

Open
AjitPadhi-Microsoft wants to merge 3 commits intodevfrom
PSL-US-35960
Open

fix: fixed app insights logging issue#753
AjitPadhi-Microsoft wants to merge 3 commits intodevfrom
PSL-US-35960

Conversation

@AjitPadhi-Microsoft
Copy link
Contributor

Purpose

  • This pull request adds integration with Azure Application Insights to enable telemetry and monitoring for the backend application. The main changes involve importing the necessary Azure monitoring library and conditionally configuring Application Insights based on the presence of an environment variable.

Azure Application Insights integration:

  • Imported configure_azure_monitor from azure.monitor.opentelemetry in app.py to support telemetry.
  • Added logic to check for the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable; if present, the app configures Azure Application Insights for monitoring, otherwise it logs a warning.

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

What to Check

Verify that the following are valid

  • ...

Other Information

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds Azure Application Insights (via Azure Monitor OpenTelemetry) initialization to the backend entrypoint so the service can emit telemetry when an Application Insights connection string is provided.

Changes:

  • Import configure_azure_monitor and conditionally configure Azure Monitor at startup based on APPLICATIONINSIGHTS_CONNECTION_STRING.
  • Add startup log lines indicating whether Application Insights was configured.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +49
# Check if the Application Insights Instrumentation Key is set in the environment variables
instrumentation_key = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
if instrumentation_key:
# Configure Application Insights if the Instrumentation Key is found
configure_azure_monitor(connection_string=instrumentation_key)
logging.info("Application Insights configured with the provided Instrumentation Key")
else:
# Log a warning if the Instrumentation Key is not found
logging.warning("No Application Insights Instrumentation Key found. Skipping configuration")
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments/log messages and variable name refer to an "Instrumentation Key", but the code is reading APPLICATIONINSIGHTS_CONNECTION_STRING and passes it as connection_string. Please rename instrumentation_key to something like appinsights_connection_string and update the comments/messages to consistently refer to a connection string (or change the env var if you truly intend to use an instrumentation key).

Suggested change
# Check if the Application Insights Instrumentation Key is set in the environment variables
instrumentation_key = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
if instrumentation_key:
# Configure Application Insights if the Instrumentation Key is found
configure_azure_monitor(connection_string=instrumentation_key)
logging.info("Application Insights configured with the provided Instrumentation Key")
else:
# Log a warning if the Instrumentation Key is not found
logging.warning("No Application Insights Instrumentation Key found. Skipping configuration")
# Check if the Application Insights connection string is set in the environment variables
appinsights_connection_string = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
if appinsights_connection_string:
# Configure Application Insights if the connection string is found
configure_azure_monitor(connection_string=appinsights_connection_string)
logging.info("Application Insights configured with the provided connection string")
else:
# Log a warning if the connection string is not found
logging.warning("No Application Insights connection string found. Skipping configuration")

Copilot uses AI. Check for mistakes.
Comment on lines +46 to +49
logging.info("Application Insights configured with the provided Instrumentation Key")
else:
# Log a warning if the Instrumentation Key is not found
logging.warning("No Application Insights Instrumentation Key found. Skipping configuration")
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file defines a module logger (logger = logging.getLogger(__name__)), but these new lines log via the root logging module. Please use the module logger (logger.info / logger.warning) so log records have the correct logger name and can be filtered/structured consistently with the rest of the file.

Suggested change
logging.info("Application Insights configured with the provided Instrumentation Key")
else:
# Log a warning if the Instrumentation Key is not found
logging.warning("No Application Insights Instrumentation Key found. Skipping configuration")
logger.info("Application Insights configured with the provided Instrumentation Key")
else:
# Log a warning if the Instrumentation Key is not found
logger.warning("No Application Insights Instrumentation Key found. Skipping configuration")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants