Skip to content

feat: Add Application Insights exception tracking to rules API routes - #2606

Merged
Aibono1225 merged 3 commits into
mainfrom
copilot/fix-related-rules-loading-error
Apr 24, 2026
Merged

feat: Add Application Insights exception tracking to rules API routes#2606
Aibono1225 merged 3 commits into
mainfrom
copilot/fix-related-rules-loading-error

Conversation

Copilot AI commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Rules API routes were only calling console.error on failure — no structured exception data (stack trace, message, request context) was flowing to Application Insights, making 500 errors from the related-rules fetch nearly impossible to diagnose.

Changes

New: lib/appInsights.server.ts

Thin server-side telemetry helper wrapping the applicationinsights Node.js SDK (already initialised in instrumentation.ts):

export function trackServerException(error: unknown, properties?: Record<string, string>): void
export function trackServerEvent(name: string, properties?: Record<string, string>): void
  • Uses require() at call time (not import time) — safe across all server contexts
  • No-ops silently when defaultClient is null (local dev, SDK not initialised)
  • Inner try/catch ensures telemetry never crashes the caller

Updated API routes

trackServerException(err, { route: "..." }) added to all four rules error handlers:

Route File
GET /api/rules app/api/rules/route.ts
GET /api/rules/paginated app/api/rules/paginated/route.ts
GET /api/tina/rule app/api/tina/rule/route.ts
GET /api/tina/rules-by-author app/api/tina/rules-by-author/route.ts

The route property surfaces in Application Insights as a custom dimension, allowing quick filtering in the Azure Portal.

Screenshot (optional)

N/A — server-side telemetry change; observable in Application Insights exceptions blade.

Copilot AI changed the title [WIP] Fix bug where related rules list fails to load feat: Add Application Insights exception tracking to rules API routes Apr 22, 2026
Copilot AI requested a review from Aibono1225 April 22, 2026 12:36
@Aibono1225
Aibono1225 marked this pull request as ready for review April 22, 2026 12:38
@Aibono1225

Copy link
Copy Markdown
Member

/deploy

@joshbermanssw joshbermanssw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@Aibono1225
Aibono1225 merged commit 4ee8988 into main Apr 24, 2026
1 check passed
@Aibono1225
Aibono1225 deleted the copilot/fix-related-rules-loading-error branch April 24, 2026 08:31
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.

🐛 Bug - Related rules list fails to load and error details are not logged in Application Insights

3 participants