---
title: Observability & Alert Response
summary: Operator playbook for inspecting live Aspire Dashboard telemetry, running Log Analytics KQL queries, checking resource saturation, and responding to alerts.
owners:
  - platform-engineering-team
badges:
  - content: SRE / Incident
    backgroundColor: teal
    textColor: teal
---

## When to Use & Blast Radius

Use this guide when an Azure Monitor alert fires, latency degrades, or you need to correlate distributed traces and logs across **API Gateway**, backend services, **Message Broker** consumers, and AI pipelines. All commands in this runbook are read-only and safe to run against `Production`.

### Telemetry and Alerting Surface

<MermaidFileLoader file="mermaids/002-observability-and-diagnostics-diagram-1.mmd" />

## Pre-Flight Check

Verify your Azure CLI context and retrieve the Log Analytics workspace ID before running queries:

```bash
az account set --subscription "<SUBSCRIPTION_ID>"
WORKSPACE_ID=$(az monitor log-analytics workspace list --resource-group "<RESOURCE_GROUP>" --query "[0].customerId" -o tsv)
echo "Workspace ID: ${WORKSPACE_ID}"
```

## Procedure

<Steps>
<Step title="Stream live container logs for immediate triage">

Stream real-time stdout/stderr or platform lifecycle events without waiting for Log Analytics ingestion lag:

```bash
# Application stdout/stderr
az containerapp logs show --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" --type console --follow

# Platform events (image pulls, probe failures, scaling)
az containerapp logs show --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" --type system --tail 100
```

</Step>

<Step title="Query application errors and trace IDs in Log Analytics">

Run KQL queries across all Container Apps to surface recent exceptions or correlate a single request by `<TRACE_ID>`:

```bash
# Recent application errors across all services
az monitor log-analytics query --workspace "${WORKSPACE_ID}" \
  --analytics-query "ContainerAppConsoleLogs_CL | where TimeGenerated > ago(1h) | where Log_s has_any ('Error','Exception','Unhandled','Failed') | summarize ErrorCount=count() by ContainerAppName_s | order by ErrorCount desc" \
  -o table

# Correlate a specific trace or request ID end-to-end
az monitor log-analytics query --workspace "${WORKSPACE_ID}" \
  --analytics-query "ContainerAppConsoleLogs_CL | where TimeGenerated > ago(2h) | where Log_s contains '<TRACE_ID>' | project TimeGenerated, ContainerAppName_s, Log_s | order by TimeGenerated asc" \
  -o table
```

</Step>

<Step title="Inspect asynchronous Message Broker and dead-letter queue logs">

Check consumer failures and dead-letter routing across **Ordering Service**, **Finance Orchestrator**, **Basket Service**, **Notification Service**, **Catalog Service**, **Catalog Ingestion**, **Rating Service**, and **Scheduler Service**:

```bash
az monitor log-analytics query --workspace "${WORKSPACE_ID}" \
  --analytics-query "ContainerAppConsoleLogs_CL | where TimeGenerated > ago(1h) | where ContainerAppName_s in ('ordering','finance','basket','notification','catalog','catalog-ingestion','rating','scheduler') | where Log_s has_any ('dead-letter','Wolverine','Kafka','ConsumeException') | project TimeGenerated, ContainerAppName_s, Log_s | order by TimeGenerated desc | take 50" \
  -o table
```

</Step>

<Step title="Check compute and datastore saturation">

Inspect Container App replica counts, PostgreSQL CPU/storage, and Redis memory pressure:

```bash
# Container App active replicas and provisioning state
az containerapp revision list --name "<APP_NAME>" --resource-group "<RESOURCE_GROUP>" \
  --query "[?properties.active==\`true\`].{Revision:name, Replicas:properties.replicas, Health:properties.healthState}" -o table

# PostgreSQL CPU and storage utilization (last 30 minutes)
PG_ID=$(az postgres flexible-server show --name "<POSTGRES_SERVER>" --resource-group "<RESOURCE_GROUP>" --query id -o tsv)
az monitor metrics list --resource "${PG_ID}" --metric cpu_percent storage_percent --interval PT5M --output table

# Azure Managed Redis memory usage
REDIS_ID=$(az redisenterprise show --name "<REDIS_NAME>" --resource-group "<RESOURCE_GROUP>" --query id -o tsv)
az monitor metrics list --resource "${REDIS_ID}" --metric usedmemorypercentage --interval PT5M --output table
```

</Step>

<Step title="Inspect live traces in the managed Aspire Dashboard">

In the Azure Portal, open **Resource groups** → `<RESOURCE_GROUP>` → **Container Apps Environment** → **Aspire Dashboard** to view end-to-end W3C traces, ASP.NET Core / HTTP metrics, and structured logs. For local troubleshooting, open `https://localhost:17290`.

</Step>

</Steps>

## Common Alert Playbooks

<Accordion title="Alert: Gateway or Service 5xx Spike">

1. Run the KQL error summary query in Step 2 to identify which `<APP_NAME>` is throwing exceptions.
2. Check `ContainerAppSystemLogs_CL` for `ContainerTerminated` or `UnhealthyProbe` events:

```bash
az monitor log-analytics query --workspace "${WORKSPACE_ID}" \
 --analytics-query "ContainerAppSystemLogs_CL | where TimeGenerated > ago(1h) | where Reason_s in ('ContainerTerminated','ImagePullFailed','UnhealthyProbe') | project TimeGenerated, ContainerAppName_s, Reason_s, Log_s | order by TimeGenerated desc" -o table
```

3. If correlated with a recent deployment, follow [[doc|operational/001-azure-deployment-guide]] to roll back the revision immediately.

</Accordion>

<Accordion title="Alert: Microsoft Foundry HTTP 429 Throttling or AI Latency">

1. Open **Application Insights** linked to the AI project and filter **Failures** for HTTP `429`
   on `chat`, `decision`, or `embedding` deployments. 2. Check **Privacy Analyzer** and **Privacy
   Anonymizer** Container Apps (`presidio-analyzer`, `presidio-anonymizer`) for CPU/replica
   saturation. 3. Increase model RPM/TPM capacity in Microsoft Foundry or scale up the privacy
   sidecars using [[doc|operational/007-scaling-and-cost-guardrails]].

</Accordion>

<Accordion title="Alert: PostgreSQL or Redis Saturation">

1. Verify `cpu_percent` and `storage_percent` on `<POSTGRES_SERVER>` and `usedmemorypercentage` on `<REDIS_NAME>` using Step 4.
2. Check for runaway batch jobs in **Quartz Dashboard** (`https://quartz-dashboard.<DOMAIN>/quartz`) or stuck sagas in **Finance Orchestrator**.
3. Scale compute/storage SKUs temporarily or pause non-critical batch ingestion until saturation subsides.

</Accordion>

<Accordion title="AI-Assisted Correlation with Azure SRE Agent">

When an Azure Monitor alert triggers an **Azure SRE Agent** incident workflow, the agent automatically correlates Application Insights failures, Log Analytics exceptions, and recent deployment history.

1. Verify the `sre` Azure CLI extension is available (`az sre --help`) or query the agent's threads endpoint:
   ```bash
   SRE_ENDPOINT=$(az rest -m GET \
     --url "https://management.azure.com/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.App/agents/<SRE_AGENT_NAME>?api-version=2025-05-01-preview" \
     --query properties.agentEndpoint -o tsv)
   SRE_TOKEN=$(az account get-access-token --resource https://azuresre.dev --query accessToken -o tsv)
   curl -s -H "Authorization: Bearer ${SRE_TOKEN}" "${SRE_ENDPOINT}/api/v1/threads"
   ```
2. Approve or reject proposed mitigations in the Azure Portal (**Review** mode) before any automated scaling or restart action runs against `Production`.

</Accordion>

## Verification

Confirm log ingestion is active across all Container Apps within the last 15 minutes:

```bash
az monitor log-analytics query --workspace "${WORKSPACE_ID}" \
  --analytics-query "ContainerAppConsoleLogs_CL | where TimeGenerated > ago(15m) | summarize Logs=count() by ContainerAppName_s | order by ContainerAppName_s asc" \
  -o table
```

Expected output:

```text
ContainerAppName_s    Logs
--------------------  ------
backoffice            14
basket                22
catalog               41
commerce              12
gateway               105
...
```

## Rollback / Escape Hatch

All diagnostic queries in this runbook are read-only. If you adjusted log sampling, diagnostic settings, or alert thresholds during an incident, revert them to baseline via `aspire deploy --environment "<ENV>"`.
