feat: improve Application Insights logging and telemetry handling#811
feat: improve Application Insights logging and telemetry handling#811Abdul-Microsoft wants to merge 5 commits intodevfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves API observability by centralizing Azure Monitor/OpenTelemetry setup in the FastAPI app startup and adding richer, structured telemetry events (success + error) across key API and history endpoints, while also standardizing logging to parameterized formats.
Changes:
- Centralizes
configure_azure_monitor+ FastAPI OpenTelemetry instrumentation inapp.pyand removes per-route configuration. - Adds
track_event_if_configured(...)calls to multiple endpoints (including error paths) and addsconversation_idas an OpenTelemetry span attribute for correlation. - Replaces f-string logging with parameterized logging in services/helpers/routes.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/api/app.py | Centralizes Azure Monitor + FastAPI OpenTelemetry configuration and suppresses noisy library loggers. |
| src/api/api/api_routes.py | Adds telemetry events on error paths and correlates traces via conversation_id; logging tweaks. |
| src/api/api/history_routes.py | Adds error telemetry events and correlates traces via conversation_id; removes per-route AI config. |
| src/api/helpers/chat_helper.py | Converts some logs to parameterized logging in chart processing helper. |
| src/api/services/history_service.py | Converts service logging to parameterized logging and adjusts exception logging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
This PR improves observability in the FastAPI API by centralizing Azure Monitor/OpenTelemetry setup and adding structured Application Insights custom events + span correlation (conversation_id) across key endpoints, while also standardizing logging to parameterized style.
Changes:
- Centralizes Azure Monitor configuration and FastAPI OpenTelemetry instrumentation in
app.py, and suppresses noisy Azure/OTel logs. - Adds
track_event_if_configuredcalls for error tracking (and some success/init events) acrossapi_routes.pyandhistory_routes.py, plus span attributes for correlation. - Replaces f-string logging with parameterized logging in several helpers/services.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| src/api/app.py | Centralized Azure Monitor + FastAPI instrumentation and log-level suppression. |
| src/api/common/logging/event_utils.py | Removes stdout print, adds docstring, parameterizes warning log. |
| src/api/api/api_routes.py | Adds custom telemetry events and improves logging formatting for key endpoints. |
| src/api/api/history_routes.py | Adds telemetry events and sets conversation_id on spans across history endpoints. |
| src/api/services/history_service.py | Standardizes logging to parameterized form in history service methods. |
| src/api/helpers/chat_helper.py | Standardizes logging to parameterized form for chart-generation flow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Purpose
Telemetry and Error Tracking Enhancements:
track_event_if_configuredcalls to all major API endpoints in bothapi_routes.pyandhistory_routes.pyto log structured telemetry events on errors, improving monitoring and diagnostics. Each event includes error details and type for better filtering and analysis. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]conversation_idas a span attribute for correlation inconversationand relevant history endpoints, enabling better traceability in Application Insights. [1] [2] [3] [4] [5] [6]Centralized Azure Monitor & OpenTelemetry Configuration:
api_routes.py,history_routes.py) to a centralized location inapp.py. Now, configuration is performed once at app startup, enabling live metrics, automatic request tracing, and reducing redundant/noisy logs. [1] [2]Logging Improvements:
Overall, these changes improve the reliability, observability, and maintainability of the API codebase.
Does this introduce a breaking change?
Golden Path Validation
Deployment Validation
What to Check
Verify that the following are valid
Other Information