|
| 1 | +--- |
| 2 | +title: 'Tutorial: Troubleshoot with SRE Agent on Azure App Service' |
| 3 | +description: Learn how to use SRE Agent and Azure App Service to identify and fix app issues with AI-assisted troubleshooting. |
| 4 | +author: msangapu-msft |
| 5 | +ms.author: msangapu |
| 6 | +ms.topic: tutorial |
| 7 | +ms.custom: devx-track-azurecli |
| 8 | +ms.date: 04/22/2025 |
| 9 | +--- |
| 10 | + |
| 11 | +# Tutorial: Troubleshoot an App Service app using SRE Agent |
| 12 | + |
| 13 | +This tutorial shows how to deploy a broken web app to Azure App Service, create an Agent Space, and use its AI-assisted capabilities to troubleshoot and fix application issues. You'll use the Azure Developer CLI (azd) to provision and deploy resources, simulate a bug, and use Agent Space to diagnose and resolve the error. |
| 14 | + |
| 15 | +> [!div class="checklist"] |
| 16 | +> * Deploy a sample broken app using azd |
| 17 | +> * Set up Agent Space and link the resource group |
| 18 | +> * Use AI-driven prompts to troubleshoot and fix errors |
| 19 | +
|
| 20 | +[!INCLUDE [quickstarts-free-trial-note](~/reusable-content/ce-skilling/azure/includes/quickstarts-free-trial-note.md)] |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +To complete this tutorial, you need: |
| 25 | + |
| 26 | +- [Azure subscription](https://azure.microsoft.com/free/) |
| 27 | +- [Azure CLI installed](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) |
| 28 | +- [Azure Developer CLI (azd) installed](https://learn.microsoft.com/en-us/azure/developer/azure-developer-cli/install-azd) |
| 29 | +- Git installed |
| 30 | + |
| 31 | +[!INCLUDE [azure-cli-prepare-your-environment-no-header.md](~/reusable-content/azure-cli/azure-cli-prepare-your-environment-no-header.md)] |
| 32 | + |
| 33 | +## Create Azure resources |
| 34 | + |
| 35 | +### Clone and deploy the app |
| 36 | + |
| 37 | +Clone a broken app sample: |
| 38 | + |
| 39 | +```bash |
| 40 | +git clone https://github.com/Azure-Samples/broken-python-webapp.git |
| 41 | +cd broken-python-webapp |
| 42 | +``` |
| 43 | + |
| 44 | +Initialize the environment and project: |
| 45 | + |
| 46 | +```bash |
| 47 | +azd init --template . --environment brokenapp-env |
| 48 | +``` |
| 49 | + |
| 50 | +Provision and deploy the app: |
| 51 | + |
| 52 | +```bash |
| 53 | +azd up |
| 54 | +``` |
| 55 | + |
| 56 | +### Create Agent Space |
| 57 | + |
| 58 | +1. Go to the [Azure Portal](https://portal.azure.com) |
| 59 | +2. Search for **Agent Space** and select **+ Create** |
| 60 | +3. Choose a name, region, and link the same resource group created by `azd` |
| 61 | +4. Complete the creation |
| 62 | + |
| 63 | +## Troubleshoot the broken app |
| 64 | + |
| 65 | +### Verify the app is running |
| 66 | + |
| 67 | +Browse to your app’s URL from the `azd` output. You should see the app loading or returning an error. |
| 68 | + |
| 69 | +### Simulate a broken state |
| 70 | + |
| 71 | +In the Azure Portal: |
| 72 | + |
| 73 | +1. Go to your App Service |
| 74 | +2. Select **Configuration > Application settings** |
| 75 | +3. Remove a key like `APP_MODE` or alter it to trigger a runtime error |
| 76 | +4. Save and restart the app |
| 77 | + |
| 78 | +### Use Agent Space to identify and fix the issue |
| 79 | + |
| 80 | +Open your Agent Space and begin chatting: |
| 81 | + |
| 82 | +#### Prompt to identify the issue: |
| 83 | + |
| 84 | +> "My App Service app in resource group `brokenapp-env-rg` is returning a 500 error. Can you help me figure out why?" |
| 85 | +
|
| 86 | +#### Prompt to confirm recent change: |
| 87 | + |
| 88 | +> "I recently removed the `APP_MODE` setting. Could this be causing the issue?" |
| 89 | +
|
| 90 | +Agent Space will analyze logs, configurations, and suggest a fix. |
| 91 | + |
| 92 | +### Apply the fix |
| 93 | + |
| 94 | +Restore the environment variable in App Service or make the recommended code change, then redeploy: |
| 95 | + |
| 96 | +```bash |
| 97 | +azd deploy |
| 98 | +``` |
| 99 | + |
| 100 | +## Verify the fix |
| 101 | + |
| 102 | +- Browse to your app again |
| 103 | +- Confirm the 500 error is resolved |
| 104 | +- Repeat the steps that caused the issue to verify it's fixed |
| 105 | + |
| 106 | +## Clean up resources |
| 107 | + |
| 108 | +To remove all created resources: |
| 109 | + |
| 110 | +```bash |
| 111 | +azd down |
| 112 | +``` |
| 113 | + |
| 114 | +## Next steps |
| 115 | + |
| 116 | +* [Overview of Azure App Service](overview.md) |
| 117 | +* [Use Azure Developer CLI for modern app development](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview) |
| 118 | +* [Agent Space documentation](https://learn.microsoft.com/azure/agent-space/overview) |
| 119 | + |
0 commit comments