Azure SRE Agent – Root Cause Analysis with Code Context: telemetry to code to GitHub issue

Azure SRE Agent – Root Cause Analysis with Code Context Using GitHub Integration

What is Code-Aware Root Cause Analysis?

Imagine your team gets a message from support at 10 AM: “Customers say the site throws an error after they click the button a few times.” The App Service metrics show a spike in HTTP 5xx responses. So far, so good – you know what is failing. But the question that actually matters is why: which line of code throws, what condition triggers it, and was it a code change or a configuration change? Answering that means opening the repository, searching for the error, reading the code path, and then going back to the portal to check app settings and recent changes.

That back-and-forth between telemetry and source code is where most debugging time disappears. Telemetry tells you the symptom. The code tells you the cause. Somebody has to connect the two.

This is what code-aware root cause analysis in Azure SRE Agent does. When you connect a GitHub (or Azure DevOps or GitLab) repository to the agent, it can read and search your code during an investigation. It correlates what it finds in Azure Monitor with the exact file and lines that produce the error, explains the triggering condition, and proposes a fix. It can then open a GitHub issue that already contains the investigation, so the developer who picks it up starts with the answer instead of the question.

This is the second article in my six-part series on Azure SRE Agent. In the first article, we created our agent (az-sre-agent) and walked through onboarding. In this one, we deploy a small .NET sample app to Azure App Service, connect its GitHub repository to the agent, break the app on purpose, and let the agent find the root cause – down to the line of code – and raise a GitHub issue for it. Everything below is from a real run in my own tenant in December 2026, including a few places where the live portal differs from the documentation.

How the Agent Uses Your Code

Root cause analysis in SRE Agent is hypothesis-driven. Instead of running a fixed script, the agent gathers context, forms theories about what could be wrong, tests each one against the evidence, and only then states a conclusion – together with the evidence and its limits.

The evidence sources it can use are:

SourceWhat the agent gets from it
Azure Monitor metricsPlatform metrics such as Requests, Http5xx, CPU and memory
Application Insights / Log AnalyticsFailed requests, exceptions and logs (when connected as a log source)
Resource configurationApp settings, deployment source, slots and other properties of the affected resource
Activity log and deployment historyControl-plane changes: setting updates, restarts, deployments
Memory and knowledge filesWhat the agent learned during onboarding, plus runbooks you upload
Source codeReads files and searches across the connected repositories

Everything except source code works from Azure’s built-in signals. Source code is the piece that turns “the app returns 500s” into “Program.cs throws on the sixth Increment request when INJECT_ERROR is 1”.

Code Access vs the GitHub Connector

In the current portal there are two separate places where GitHub shows up, and they are easy to confuse:

Code accessGitHub connector
WhereBuild + configure → Context → Code accessBuild + configure → Extensions → Connectors → Add connector → GitHub
What it isA repository connection (GitHub, Azure DevOps or GitLab)The GitHub MCP server (https://api.githubcopilot.com/mcp/, Streamable-HTTP)
AuthenticationOAuth, personal access token, or your own GitHub AppPersonal access token or API key
What the agent getsThe repository is cloned into the agent’s workspace so it can read and search code; the same credential is used for GitHub API callsThe GitHub MCP tool catalog, with tool selection

When I opened Connectors, a banner said “Repository connections have moved to Code Access” – older docs and screenshots that show repositories under Connectors are out of date. More importantly, I found that code access alone was enough for the agent to create a GitHub issue (more on that in Step 8). You only need the MCP connector if you want its wider tool catalog.

What You Need

RequirementDetails
An Azure SRE AgentI’m reusing az-sre-agent from Article 1 (Central US, Review mode, Reader permission level)
SRE Agent Administrator role on the agentNeeded to add repositories, connectors and Azure resource scopes
Owner or User Access Administrator on the resource groupOnly resource groups where you hold one of these roles are listed when you add Azure resources, because the portal assigns roles to the agent’s identity
A GitHub accountTo fork the sample repository and sign in from the agent
Permission to create resourcesContributor on the resource group for the demo App Service app

Step 1 – Fork the Sample App to Your GitHub Account

Microsoft publishes a tiny ASP.NET Core sample for SRE Agent demos: Azure-Samples/app-service-dotnet-agent-tutorial. It shows a counter with an Increment button. When the app setting INJECT_ERROR is set to 1, the sixth click throws an exception and the app returns HTTP 500. That gives us a realistic “configuration change breaks production” scenario with a clear line of code behind it.

Open the repository and select Fork to copy it into your own account. The agent needs a repository it can sign in to and create issues in, so we work on our fork, not the Microsoft original. In the fork, go to Settings → General → Features and make sure Issues is ticked – forks have issues turned off by default.

Fork of app-service-dotnet-agent-tutorial in my GitHub account

Figure 1: The sample repository forked into my GitHub account

The sample targets .NET 9, which is no longer offered as an App Service runtime. In my fork I changed TargetFramework in SreAgentMemoryDemo.csproj to net10.0 (and the Microsoft.AspNetCore.OpenApi package to 10.0.0) so it runs on the .NET 10 (LTS) stack.

The code that matters is in Program.cs. Keep it in mind – we will watch the agent find it on its own later:

bool injectError = Environment.GetEnvironmentVariable("INJECT_ERROR") == "1"; // line 11
...
if (buttonPressed && !safeMode)
pressCount++; // counter kept in a cookie
...
if (injectError && !safeMode && buttonPressed && pressCount > 5)
throw new Exception("Simulated error after 5 button clicks!"); // line 28

Step 2 – Deploy the Sample to Azure App Service

I deployed the app into the same resource group as the agent (rg-sre-agent-demo) on a Free (F1) Windows plan in Central US, so the demo app itself costs nothing. In the portal: App Services → Create → Web App, runtime stack .NET 10 (LTS), Windows, a new F1 plan, and Application Insights enabled. Then Deployment Center → External Git pointing at the fork’s main branch. Or with the Azure CLI:

# Variables
RG=rg-sre-agent-demo
LOCATION=centralus
PLAN=asp-sre-demo
APP=sre-demo-counter-<unique-suffix>
REPO=https://github.com/<your-github-user>/app-service-dotnet-agent-tutorial
# Free Windows plan + web app on .NET 10
az appservice plan create -g $RG -n $PLAN -l $LOCATION --sku F1
az webapp create -g $RG -p $PLAN -n $APP --runtime "dotnet:10"
# Deploy straight from the fork (one-off pull, no CI/CD needed)
az webapp deployment source config -g $RG -n $APP \
--repo-url $REPO --branch main --manual-integration

Browse to the app and click Increment a few times to confirm the counter goes up. Everything is healthy – for now.

Sample counter app running on App Service

Figure 2: The sample counter app running on App Service

Step 3 – Give the Agent Access to the Resource Group

The agent can only investigate what it can see. In sre.azure.com, open the agent’s setup page (Complete setup). On the Azure resources card select +, choose Resource group, and tick rg-sre-agent-demo. Note the banner: only resource groups where you are Owner or User Access Administrator are listed.

Add resource groups dialog with rg-sre-agent-demo selected

Figure 3: Selecting the demo resource group (other resource group names blurred)

Select Next to see View agent permissions. With the Reader permission level, the portal grants the agent’s managed identity three roles on the resource group: Reader, Monitoring Reader and Log Analytics Reader. That is enough to read metrics, logs and resource properties, but not to change anything. Select Add resource group.

Roles to be granted to the agent: Reader, Monitoring Reader, Log Analytics Reader

Figure 4: The roles the agent’s managed identity receives on the resource group

Step 4 – Connect the GitHub Repository (Code Access)

Now the important part. On the setup page, select + on the Code card (or go to Build + configure → Context → Code access → Add repository). In the Add repositories dialog:

  1. Choose GitHub as the platform (Azure DevOps and GitLab are also available).
  2. Paste the fork’s URL into Repository URL. The dialog tells you the credential will apply to all repositories on github.com for that account.
  3. Choose the Connection method: OAuth, Personal access token (PAT) or Use your GitHub App. I used OAuth.
  4. Read the warning: “Your sign-in will be used by everyone who can access this agent.” More on this in the governance section.
  5. Select Sign in to GitHub and complete the pop-up.
Add repositories dialog with GitHub, the repository URL and OAuth selected

Figure 5: Adding the fork with the OAuth connection method

The pop-up asks you to authorise the SREAgent-OAuth app published by Azure-SRE-Agent. Note that it requests access to your public and private repositories – the OAuth app is not scoped to one repository. I didn’t grant access to any GitHub organisation.

GitHub authorisation page for the SREAgent-OAuth app

Figure 6: Authorising the SREAgent-OAuth app on GitHub (organisation names blurred)

Back in the dialog you will see Connected to GitHub. Select Next, check the repository and display name, and select Save.

Add repositories step with the fork and its display name

Figure 7: Confirming the repository and display name

The setup page now shows Code – 1 repository and Azure resources – 1 resource group added, both with green ticks.

Agent setup page showing Code and Azure resources completed

Figure 8: Code and Azure resources connected on the setup page

You can manage the connection later under Build + configure → Context → Code access, which lists each repository, its connection (here OAuth for prawin2k) and when it was last synced.

Code access configuration page listing the connected repository

Figure 9: The Code access page with the connected repository

What About the GitHub Connector?

Out of curiosity I also opened Extensions → Connectors → Add connector → GitHub. In the live portal this connector is the GitHub MCP server: connection type Streamable-HTTP, URL https://api.githubcopilot.com/mcp/, and a required personal access token or API key field. I cancelled it – as you’ll see in Step 8, it wasn’t needed for issue creation.

Set up GitHub connector form showing the MCP URL and PAT field

Figure 10: The GitHub connector is the GitHub MCP server and needs a PAT

Step 5 – Break the App

Time to simulate a bad change. In the Azure portal, open the web app, go to Settings → Environment variables → App settings, add INJECT_ERROR = 1, select Apply and confirm the restart. Or with the CLI:

az webapp config appsettings set -g rg-sre-agent-demo -n $APP --settings INJECT_ERROR=1

Tip: the portal’s value field for app settings is masked. If you prefer, use Advanced edit and add {"name": "INJECT_ERROR", "value": "1", "slotSetting": false} to the JSON array.

Browse to the app. It now shows a red ERROR INJECTION ENABLED warning. Click Increment six times and the app returns HTTP 500. Keep clicking or refreshing for a minute so there is telemetry for the agent to find.

Browser showing HTTP ERROR 500 from the counter app

Figure 11: The app returning HTTP 500 after INJECT_ERROR=1

This is a very common real-world failure pattern: nobody changed the code, but someone changed a setting that sends the code down a path that was never meant to run in production.

Step 6 – Ask the Agent to Investigate

In sre.azure.com, select New chat and describe the problem the way a support ticket would – without giving the agent the answer:

Users report that our counter web app sre-demo-counter-pks in rg-sre-agent-demo
starts returning HTTP 500 errors after they click the Increment button a few
times. Can you investigate, find the root cause in the code from the connected
GitHub repo, and recommend a fix?

The agent announced its plan (check failures and configuration, then trace the Increment path in the repository), loaded its built-in web_app_down skill, and within seconds read Program.cs, README.md and the project file from my fork, plus its own onboarding memory. You can expand each step to see exactly what it read.

Agent chat showing the web_app_down skill and Read Program.cs, memory and README steps

Figure 12: The agent reads the code from the connected repository

The Permission Prompts

Next, the agent tried to read the app’s configuration with az webapp show and az webapp config appsettings list. Its managed identity got an authorization error – reading app settings needs the Microsoft.Web/sites/config/list/action permission, which the Reader role doesn’t include. Instead of failing, the agent showed an Authorization required card with the exact command, a risk label (Low or Medium), and a Grant permissions button. If you grant it, the command runs once with your credentials (on-behalf-of, OBO).

Authorization required card asking to run az webapp config appsettings list with the user's credentials

Figure 13: The agent asks before running a command with my credentials (subscription ID blurred)

I granted only the read-only requests scoped to the demo app. Each grant then shows your name on the card, so it’s clear afterwards which commands ran as you. I also noticed that a subagent the agent started to double-check its findings couldn’t ask for this permission (“User input cannot be requested from this execution until permission bubbling is supported”), so a few of its checks simply failed – the main agent carried on without them.

Metrics and Hypotheses

With the setting confirmed, the agent pulled the Requests and Http5xx metrics for the app, drew charts in the chat, and summarised them: Http5xx was flat at zero except for a single spike of six 5xx responses among 12 requests at 05:42 UTC – exactly when I was clicking. It also checked CPU and memory to rule out a capacity problem, and the deployment source to confirm the app was deployed from the same repository’s main branch.

Http5xx metric chart drawn by the agent showing a spike to 6 at 05:42

Figure 14: The agent’s Http5xx chart: one spike while the app was failing

Step 7 – Review the Root Cause

About ten minutes after I sent the prompt, the agent gave its conclusion:

  • Likely root cause: the production app has INJECT_ERROR=1. In Program.cs lines 11–28, each Increment request raises a cookie-backed counter and deliberately throws once it exceeds five – on the sixth click.
  • Evidence: the live app setting, the code path, and Azure Monitor’s six 5xx responses among 12 requests at 05:42 UTC.
  • Recommended fix: set INJECT_ERROR to 0 (or remove it) on production, then verify Increment works beyond six clicks. For a durable fix, remove the deliberate throw from production code and keep error injection to a test environment.
  • Limits: the exact deployed commit and request-level exception traces weren’t available, so the metrics corroborate the cause but don’t prove every one of those six responses came from this exact line. It also stated clearly that no settings or code were changed.
Agent answer with likely root cause, Program.cs link and recommended fix

Figure 15: The root cause with a link to the exact lines in Program.cs

The Program.cs#L11-L28 reference is a real link to those lines in my fork, so you can check the agent’s reasoning in one click. That honest “what I can and can’t prove” paragraph is one of the things I like most about it.

A note on redaction: the agent’s commands and answers include your subscription ID and resource IDs. Blur them before you share screenshots or paste the transcript into a ticket.

Step 8 – Let the Agent Create a GitHub Issue

Next, I asked the agent to hand the finding over to the developers:

Please create a GitHub issue in the connected repo
<your-github-user>/app-service-dotnet-agent-tutorial summarising this root cause
(with the Program.cs line reference and the Http5xx evidence) and the recommended fix.

I expected to need the GitHub connector for this. I didn’t. The agent used the GitHub CLI in its own workspace with the code access OAuth credential: it checked the repository and credential, looked for an existing duplicate issue, created the issue through the GitHub API, and then read it back to verify it contained the code reference, the metric evidence and the fix. The whole thing took under a minute.

Agent chat showing Creating GitHub issue, duplicate check, create and verify steps

Figure 16: The agent creates and verifies the GitHub issue

The issue Prevent intentional HTTP 500s after six Increment clicks has a summary, the evidence with links to the exact lines, a numbered fix plan and the same honest limits. It even spotted a second, unrelated bug I hadn’t noticed: the on-page help text tells users to append ?=safe=1, but the handler expects ?safe=1 (line 115).

GitHub issue #1 created by the agent with summary, evidence and recommended fix

Figure 17: The GitHub issue created by the agent

Two things to notice. First, the issue is opened as me (prawin2k), because the OAuth credential is my GitHub sign-in. Second, even though the agent runs in Review mode, it did not ask me to approve the issue before creating it – the only approval prompts I saw were the Azure OBO ones. In this case I had asked for the issue explicitly, so that was fine, but it means Review mode is not a reliable gate for GitHub writes made with the code access credential.

Step 9 – Fix and Verify

Our agent has Reader access only, so it can’t change the app itself – that’s by design. I applied the fix myself by deleting the setting (portal: Environment variables → delete INJECT_ERROR → Apply → Confirm), or with the CLI:

az webapp config appsettings delete -g rg-sre-agent-demo -n $APP --setting-names INJECT_ERROR

After the restart, the warning was gone and the counter happily went past six without errors.

Counter app showing 8 with no error message

Figure 18: The counter past six clicks after removing INJECT_ERROR

If you later give the agent Privileged access (Contributor-level roles) on the resource group, it can propose the mitigation itself and run it after you approve. Start with Reader, and widen access only once you trust its recommendations for a specific workload.

Governance and Security

AreaWhat to think about
Whose GitHub identityWith OAuth, the sign-in “will be used by everyone who can access this agent”. Anyone who can chat with the agent can make it read your repositories and create issues as you. For shared agents, use a fine-grained PAT or your own GitHub App owned by a service account.
Repository scopeThe SREAgent-OAuth app requests access to public and private repositories, and the credential applies to all repositories on github.com for that account. A fine-grained PAT or GitHub App can be limited to specific repositories.
Write actions to GitHubIn my test, Review mode did not prompt before creating the issue. Treat the GitHub credential’s permissions as the real control: if the agent shouldn’t write, give it a read-only token.
Azure accessCode access gives no Azure permissions. Azure access comes from the managed identity’s roles (Reader, Monitoring Reader, Log Analytics Reader here). Reader can’t list app settings, which is why OBO prompts appear.
OBO grantsA grant runs that one command with your credentials and records your name on the card. Read the command and risk label before you approve, and never grant write commands you didn’t ask for.
Revoking accessRemove the repository under Code access, and revoke the SREAgent-OAuth app in GitHub under Settings → Applications → Authorized OAuth Apps.
Sensitive data in answersAgent output contains subscription and resource IDs. Redact before sharing.

Pricing

Connecting a repository isn’t billed on its own. What you pay for is the same as in Article 1:

  • Always-on flow – charged per agent per hour for as long as the agent exists (waived for my agent during the trial, as the banner in the portal shows).
  • Active flow – token-based charges for each chat, investigation and scheduled task. A code-reading investigation with metrics, charts and a verification subagent is one of the heavier interactions, so keep demo prompts focused.

You can see the consumption for your agent under Build + configure → Monitor → Agent consumption. The demo app runs on the Free F1 plan, so it adds nothing.

My Recommendation

Start with your most incident-prone service. Connect its repository with code access, give the agent Reader on that service’s resource group, and run a couple of controlled “break it” exercises like this one – a bad setting, a failing dependency, a bad deployment. Compare how quickly the agent gets to the right line of code with how long it takes your on-call engineer. In my run it took about ten minutes from a vague support-style prompt to a root cause with line references, and another minute to a well-written GitHub issue – that comparison is the best business case you can make for the tool.

For anything beyond a personal demo, don’t use your own OAuth sign-in. Create a fine-grained PAT (or a GitHub App) for a service account, limit it to the repositories the agent needs, and decide deliberately whether it gets Issues: Read and write.

Limitations to Keep in Mind

  • The OAuth app asks for access to all your public and private repositories; scoping needs a PAT or your own GitHub App.
  • Review mode didn’t gate GitHub issue creation in my test – rely on the token’s permissions instead.
  • With the Reader permission level, the agent needs OBO approval to read app settings, and subagents can’t request it yet.
  • The analysis is only as good as the telemetry and code it can see. Without request-level exceptions or the exact deployed commit, the agent said so and gave a “likely” root cause rather than a proven one.
  • Like any LLM-based tool, it can be wrong. Treat the file and line references as a strong lead and check them – which is easy, because it links to them.
  • The portal changes quickly: repository connections moved from Connectors to Code access, and the GitHub connector is now the GitHub MCP server.

Summary

In this article, we learnt how to connect a GitHub repository to Azure SRE Agent with code access, break an App Service app with a bad configuration change, and let the agent trace the HTTP 500 errors to the exact lines in Program.cs and raise a GitHub issue with its findings.

TopicWhat to Remember
Code-aware RCAThe agent combines Azure Monitor metrics, resource configuration and your source code to explain why an error happens, with links to the exact lines.
Code accessBuild + configure → Context → Code access. GitHub, Azure DevOps or GitLab; OAuth, PAT or your own GitHub App.
GitHub connectorNow the GitHub MCP server and needs a PAT. Not required for creating issues.
Azure permissionsReader level grants Reader, Monitoring Reader and Log Analytics Reader. Reading app settings needs an OBO grant.
Investigation flowPlan → read code → check configuration → metrics and charts → root cause, evidence, fix and limits.
GitHub issuesCreated with the code access credential, as the signed-in user, without a Review-mode prompt in my test.
GovernanceThe OAuth sign-in is shared by everyone who uses the agent. Prefer a scoped PAT or GitHub App for shared agents.
CostRepositories are free to connect; investigations consume active-flow usage. Check Monitor → Agent consumption.

Discover more from Praveen Kumar Sreeram's Blog

Subscribe to get the latest posts sent to your email.

One comment

Leave a Reply