Skip to content

feat: Add LLM token usage tracking to Application Insights#586

Draft
Prachig-Microsoft wants to merge 1 commit into
devfrom
feature/token-usage-tracking
Draft

feat: Add LLM token usage tracking to Application Insights#586
Prachig-Microsoft wants to merge 1 commit into
devfrom
feature/token-usage-tracking

Conversation

@Prachig-Microsoft
Copy link
Copy Markdown
Contributor

Implement comprehensive token usage tracking across all LLM call sites in ContentProcessor and ContentProcessorWorkflow, following the MACAE psl-token-usage branch pattern.

Changes:

  • Add token_usage_utils.py with extract/emit helpers for both projects
  • Instrument MapHandler (ContentProcessor) with per-call token events
  • Instrument RAI, Summarize, GapAnalysis executors (Workflow)
  • Add summary and per-model token events in save_handler
  • Add 18 KQL queries for Azure Workbook visualization
  • Add unit tests (18 tests) for token_usage_utils

Events emitted to Application Insights:

  • LLM_Agent_Token_Usage: per agent/step with model, process_id
  • LLM_Model_Token_Usage: per model deployment aggregation
  • LLM_Token_Usage_Summary: per document totals

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

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

Deployment Validation

  • [ x] 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

Implement comprehensive token usage tracking across all LLM call sites
in ContentProcessor and ContentProcessorWorkflow, following the MACAE
psl-token-usage branch pattern.

Changes:
- Add token_usage_utils.py with extract/emit helpers for both projects
- Instrument MapHandler (ContentProcessor) with per-call token events
- Instrument RAI, Summarize, GapAnalysis executors (Workflow)
- Add summary and per-model token events in save_handler
- Add 18 KQL queries for Azure Workbook visualization
- Add unit tests (18 tests) for token_usage_utils

Events emitted to Application Insights:
- LLM_Agent_Token_Usage: per agent/step with model, process_id
- LLM_Model_Token_Usage: per model deployment aggregation
- LLM_Token_Usage_Summary: per document totals

Ref: User Story #43251

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

Coverage

Coverage Report •
FileStmtsMissCoverMissing
TOTAL121716186% 
report-only-changed-files is enabled. No files were changed during this commit :)

Tests Skipped Failures Errors Time
244 0 💤 0 ❌ 0 🔥 4.023s ⏱️

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.

1 participant