A realistic chain: a latency spike in infra triggers a timeout, which triggers a retry, which triples token cost - because the retry pulled in a much longer context, sourced from a bad retrieval step in the data layer. Four symptoms, one root cause, four different dashboards if you're not tracing end to end.
This is where distributed tracing earns its keep. Built on OpenTelemetry, tracing captures the full execution path of an AI request - model calls, tool invocations, retrieval steps, and agent-to-agent handoffs - as a single connected trace rather than isolated logs per component.
Microsoft Foundry: Models, Machine Learning, Agent Service, Tools and IQ, unified under one Control Plane spanning edge and cloud.
Microsoft Foundry is a useful concrete example of what unified telemetry looks like in practice. Evaluation results, traces, latency, token usage, and quality metrics all land in the same Azure Monitor Application Insights workspace - so when a groundedness score drops, you can tell in minutes whether the cause is a model update, a retrieval pipeline issue, or an infrastructure problem, instead of hours of manual correlation across disconnected tools.
Foundry's observability and evaluation capabilities - evaluation, monitoring, and tracing - reached general availability in March 2026, with tracing support across popular agent frameworks including LangChain, LangGraph, the OpenAI Agents SDK, and the Microsoft Agent Framework.
๐ Official Microsoft documentation: Set up tracing in Microsoft Foundry
Alongside tracing, you need metrics that speak to quality, not just health:
These are typically scored on a continuous scale, not pass/fail, because AI quality genuinely lives on a spectrum. Production behavior also drifts even without a code change - model updates, shifting user input, data drift - so one-time pre-deployment evaluation isn't enough. The emerging best practice is continuous evaluation in production, sampling a percentage of live traffic (commonly starting around 5-10%) and tuning that rate against cost, since every sampled evaluation is itself an additional model call.
Before you can observe quality, you need to observe usage - and AI consumption is measured very differently from a typical web workload. The core unit is the token (input tokens + output tokens), and everything else - cost, throughput, and quota behavior - derives from it.
Total tokens Overview
Left unmonitored, TPM/RPM limits surface as throttling incidents rather than a graceful degradation - which is itself an observability failure: the first sign of a capacity problem shouldn't be a rate-limit error in production. PTU vs. Pay-As-You-Go becomes an observability-informed decision rather than a guess: PTU pays off once usage is stable and predictable enough that reserved capacity beats variable per-token billing - a call you can only make correctly if you're already watching TPM/RPM trends over time.
A GenAI API gateway - Azure API Management (APIM) in front of your AI services - turns several invisible failure modes into observable, governed ones: opaque token consumption becomes token tracking and chargeback, uncontrolled usage becomes cost and capacity management, and inconsistent performance becomes full observability with model- and token-aware routing.
Three APIM policies do most of the heavy lifting:
Token Metric policy - collects token usage data per user or subscription and emits it to Application Insights, enabling accurate cross-charging:
<llm-emit-token-metric namespace="AzureOpenAI">
<dimension name="User ID" />
<dimension name="Subscription ID" />
</azure-openai-emit-token-metric>
Semantic Caching policy - caches semantically similar prompts via Azure Cache for Redis, cutting repeated model calls and their token cost:
<azure-openai-semantic-cache-lookup
score-threshold="0.05"
embeddings-backend-id="azure-openai-backend">
<vary-by>@(context.Subscription.Id)</vary-by>
</azure-openai-semantic-cache-lookup>
Token Limit policy - enforces TPM limits per counter key (e.g. per subscription), so throttling happens by policy, not by surprise:
<llm-token-limit
counter-key="@(context.Subscription.Id)"
tokens-per-minute="1000"
estimate-prompt-tokens="false" />
Together, these policies make an AI gateway one of the highest-leverage observability investments you can make: every request that passes through it is automatically metered, capped, and attributable - before it ever reaches your tracing and evaluation layer.
๐ Official Microsoft documentation: Azure API Management GenAI Gateway capabilities
Everything above is exactly what TeraSky's open-source AI Foundry FinOps Framework implements end to end - APIM token rate limiting, cost quotas, auto-suspend/reactivate, and a live pricing sync, wired into a single Azure Monitor workbook.
Architecture: TeraSky-OSS / microsoft-foundry-cost-demo (open source, MIT-style repo).
The framework wires together six pieces:
The cost-calculation flow itself runs as a KQL join every 5 minutes: APIM logs token usage (prompt/completion tokens, subscription ID) to Log Analytics โ an alert rule joins that with the pricing table to compute real cost โ if cost exceeds quota, the Logic App suspends the subscription โ a second alert re-activates it once cost falls back in range (e.g. a new billing period).
All of this surfaces in one Azure Monitor workbook with four sections: Usage Overview (requests and tokens by model, token usage by tier, request volume over time), Quota & Suspension Status, Cost Analysis (cost over time, MTD cost by subscription and model), and Projected Month-End Cost with a Budget Burn Rate view comparing actual spend pace against expected pace per tier.
Architecture: TeraSky-OSS / microsoft-foundry-cost-demo (open source, MIT-style repo).
Deploying it is a four-step process:
# 1. Infrastructure
az group create --name rg-foundry-finops-demo --location eastus2
az deployment group create --name finops-demo --resource-group rg-foundry-finops-demo --template-file main.bicep --parameters parameters.json
# 2. Pricing sync function
cd functions/pricing-sync
func azure functionapp publish <function-app-name> --python
# 3. Seed pricing + quota data
python trigger-pricing-sync.py -g rg-foundry-finops-demo
python ingest-quota.py -g rg-foundry-finops-demo -n finops-demo
# 4. Simulate traffic to populate the dashboard
python simulate.py dashboard -g rg-foundry-finops-demo -n finops-demo --runs 30
๐ Repository: github.com/TeraSky-OSS/microsoft-foundry-cost-demo
Put together, mature AI observability isn't a dashboard you check - it's a loop:
Trace โ Evaluate โ Find the weak spot โ Improve โ Trace again.
Every production incident becomes training data for the next iteration, and every quality regression gets caught by a signal before a customer notices it.
If your AI monitoring strategy only answers "is it up," you have half an observability practice. The other half - is it right, is it grounded, is it costing what it should - requires tracing across infra/data/model layers, continuous quality evaluation, and consumption metering at the gateway, not just uptime checks.
The teams that get ahead of this aren't the ones with the most dashboards. They're the ones who can look at a single trace and immediately tell you which layer broke, why, and what it cost - and who have automated the response, the way TeraSky's FinOps framework auto-suspends a runaway subscription before it becomes a budget incident.
๐ Read more from Captain Azure:
FinOps in Azure - A Practical Guide