feat: improve Application Insights logging and telemetry handling#389
Merged
Roopan-Microsoft merged 8 commits intodevfrom Apr 3, 2026
Merged
feat: improve Application Insights logging and telemetry handling#389Roopan-Microsoft merged 8 commits intodevfrom
Roopan-Microsoft merged 8 commits intodevfrom
Conversation
…tion Insights dependency and enhancing event tracking
…ved error handling and attribute tracking in OpenTelemetry spans
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors backend telemetry/logging to improve observability by switching custom event tracking to the Azure Monitor Events extension, enriching API telemetry with contextual IDs, and tightening logging output by suppressing noisy SDK loggers.
Changes:
- Refactored custom event tracking to use
azure.monitor.events.extension.track_eventand updated tests accordingly. - Added span attribute enrichment and expanded event/log context (e.g.,
batch_id,file_id,user_id) across API routes and batch processing code. - Updated app startup telemetry configuration to use
configure_azure_monitor()and added an instrumentor monkey-patch for an Azure AI telemetry serialization bug.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/backend/api/event_utils.py | Switches custom event emission to Azure Monitor Events extension. |
| src/backend/app.py | Moves to configure_azure_monitor() and adds SDK log suppression + instrumentor patching. |
| src/backend/api/api_routes.py | Adds span attribute enrichment and more contextual telemetry/events/logs. |
| src/backend/sql_agents/process_batch.py | Refactors logging to structured AppLogger and adds batch/file context. |
| src/backend/sql_agents/convert_script.py | Refactors logging to structured AppLogger and reduces raw content logging. |
| src/backend/common/logger/app_logger.py | Changes error() to forward exc_info (now defaulting to True). |
| src/backend/common/telemetry/patch_instrumentor.py | Adds monkey-patch for Azure AI instrumentor response_format serialization. |
| src/backend/common/telemetry/init.py | Exports patch_instrumentors only. |
| src/backend/common/services/batch_service.py | Adds informational logs for upload/delete/status update operations. |
| src/backend/requirements.txt | Replaces applicationinsights with azure-monitor-events-extension. |
| src/tests/backend/api/event_utils_test.py | Updates tests to mock the new track_event path. |
| src/tests/backend/common/storage/blob_azure_test.py | Updates expectation to include exc_info=True on error logging. |
| infra/main.bicep | Removes unused diagnosticSettings from App Insights module configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ception context Agent-Logs-Url: https://github.com/microsoft/Modernize-your-code-solution-accelerator/sessions/9a6c2020-0f93-4936-bc01-9d333c0444b2 Co-authored-by: Abdul-Microsoft <192570837+Abdul-Microsoft@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ent UnboundLocalError Agent-Logs-Url: https://github.com/microsoft/Modernize-your-code-solution-accelerator/sessions/1182bdcf-25b8-4af7-b0e9-da0938566ee0 Co-authored-by: Abdul-Microsoft <192570837+Abdul-Microsoft@users.noreply.github.com>
Roopan-Microsoft
approved these changes
Apr 3, 2026
|
🎉 This PR is included in version 1.6.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
azure.monitor.events.extensionpackage, and OpenTelemetry spans now consistently include important contextual attributes such asbatch_id,file_id, anduser_id. Additionally, error and event logging now provides more relevant details for debugging and monitoring.Telemetry and Observability Enhancements:
azure.monitor.events.extensionpackage and removed the legacyTelemetryClient-based implementation, simplifying event tracking logic inevent_utils.py.set_span_attributesfunction inapi_routes.pyto attach contextual attributes (e.g.,batch_id,file_id,user_id) to the current OpenTelemetry span for improved traceability across API endpoints.api_routes.pyto callset_span_attributeswith appropriate identifiers, ensuring trace context is enriched for batch and file operations. [1] [2] [3] [4] [5] [6] [7] [8]Event Tracking and Logging Improvements:
track_event_if_configured) to consistently include relevant context (such asbatch_id,file_id, anduser_id) in event payloads for better monitoring and diagnostics. [1] [2] [3] [4] [5] [6] [7]api_routes.pyto include contextual identifiers, making logs more actionable and easier to correlate with specific operations or failures. [1] [2] [3] [4] [5] [6]Azure Monitor and OpenTelemetry Configuration:
app.pyto useconfigure_azure_monitorfor streamlined Azure Monitor setup and removed unused OpenTelemetry exporter imports. [1] [2]Infrastructure Adjustment:
diagnosticSettingsproperty from the Application Insights Bicep module, likely as part of infrastructure cleanup or simplification.Does this introduce a breaking change?
Golden Path Validation
Deployment Validation
What to Check
Verify that the following are valid
Other Information