---
title: "Azure Web App"
description: "Learn how to configure Middleware APM for Azure Web Apps to monitor app health, performance metrics, and application errors."
section: "Cloud Platform"
breadcrumb: "Cloud Platform > Azure Web App"
canonical: "https://docs.middleware.io/get-started/agent/azure-web-app"
---
# Azure Web App

The Middleware .NET APM SDK collects application traces, metrics, and configured logs from .NET applications on Azure App Service (Web Apps).

Monitor request performance, investigate errors, and identify slow endpoints in your Azure-hosted applications without installing a separate infrastructure Agent.

## How it works

Middleware uses the .NET APM SDK to collect telemetry from your Azure Web App.

Once configured, the SDK automatically instruments supported .NET operations and sends telemetry to your Middleware account.

You can configure the SDK through `appsettings.json` or Azure Application Settings without changing your application code for each environment.

### Supported telemetry

| Traces | Metrics | App Logs | Custom Logs | Profiling |
| --- | --- | --- | --- | --- |
| ✅ | ✅ | ✖ | ✅ | ✖ |

## Prerequisites

Before installing Middleware, make sure you have:

- An existing .NET application deployed to Azure App Service.
- Access to the application source code.
- Permissions to update and deploy your Azure Web App.
- A Middleware account with an API key and target URL.
- Outbound HTTPS connectivity from Azure App Service to your Middleware target on port 443.

## Installation

#### 1 Install the Middleware APM package

Open your .NET application project and install the Middleware APM SDK:

```bash
dotnet add package MW.APM
```

Verify that `MW.APM` appears in your project's NuGet dependencies.

#### 2 Configure instrumentation

Open `Program.cs` and add the following configuration before `var app = builder.Build();`.

```csharp
var configuration = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
    .AddEnvironmentVariables()
    .Build();

builder.Services.ConfigureMWInstrumentation(configuration);

builder.Logging.AddConfiguration(configuration.GetSection("Logging"));
builder.Logging.AddConsole();
```

This initializes Middleware instrumentation and configures application logging.

**Note**: The example assumes your application uses the ASP.NET Core hosting model with a `builder` instance already defined.

#### 3 Configure Middleware credentials

Open `appsettings.json` and add the following configuration:

```json
{
  "MW": {
    "ApiKey": "your-initial-token",
    "TargetURL": "your-initial-uid",
    "ServiceName": "<service-name>",
    "ProjectName": "<project-name>",
    "ConsoleExporter": "true",
    "ExcludeLinks": "[\"/health\"]",
    "ApmCollectMetrics": "true",
    "ApmCollectTraces": "true",
    "ApmCollectLogs": "true"
  }
}
```

Replace the placeholders with your Middleware account details.

#### Configuration reference

| Setting | Description |
| --- | --- |
| `ApiKey` | Middleware API key |
| `TargetURL` | Middleware ingestion endpoint |
| `ServiceName` | Service name displayed in Middleware APM |
| `ProjectName` | Optional project name for grouping services |
| `ConsoleExporter` | Enables console output for debugging |
| `ExcludeLinks` | Routes excluded from instrumentation, such as `/health` |
| `ApmCollectMetrics` | Enables metric collection |
| `ApmCollectTraces` | Enables trace collection |
| `ApmCollectLogs` | Enables log collection |

**Note**: For production deployments, store your API key in Azure Application Settings or reference it through Azure Key Vault rather than committing it to `appsettings.json`.

#### 4 Configure Azure Application Settings (recommended)

Azure App Service lets you configure Middleware credentials and instrumentation options without modifying `appsettings.json`.

1. Open **Azure Portal → App Services**.
2. Select your Web App.
3. Go to **Settings → Environment variables** (or **Configuration → Application settings**, depending on the portal version).
4. Add the following application settings:

| Name | Value |
| --- | --- |
| `MW__ApiKey` | `<MW_API_KEY>` |
| `MW__TargetURL` | `https://<MW_UID>.middleware.io:443` |
| `MW__ServiceName` | `<service-name>` |
| `MW__ProjectName` | `<project-name>` |

5. Save the configuration and restart the Web App if required.

.NET uses double underscores (`__`) to represent nested configuration sections. For example, `MW__ApiKey` overrides `MW:ApiKey` from `appsettings.json`.

**Note**: Because the SDK configuration includes `AddEnvironmentVariables()`, Azure Application Settings take precedence over the values defined in `appsettings.json`.

#### 5 Deploy the application

Deploy the updated .NET application to Azure App Service using your existing deployment method, such as Azure DevOps, GitHub Actions, or Visual Studio.

After deployment, verify that the Web App is running and accessible.

#### 6 Verify data collection

1. Open your Azure Web App URL and generate a few requests.
2. Log in to Middleware.
3. Go to [APM → Services](https://app.middleware.io/apm/services).
4. Find the service configured using `MW:ServiceName`.
5. Open the service to view request traces, latency, and errors.

You can also:

- Open **[APM → Traces](https://app.middleware.io/apm/traces)** to inspect individual requests.
- Review application metrics in the service overview.
- View custom logs in [Log Monitoring](https://app.middleware.io/logs), if log collection is configured.

Telemetry should begin appearing after the application generates traffic and successfully exports data.

## Environment variables reference

You can override Middleware configuration using Azure Application Settings.

| Configuration key | Azure App Setting | Required | Description |
| --- | --- | --- | --- |
| `MW:ApiKey` | `MW__ApiKey` | Yes | Middleware API key |
| `MW:TargetURL` | `MW__TargetURL` | Yes | Middleware ingestion endpoint |
| `MW:ServiceName` | `MW__ServiceName` | Yes | Logical service name |
| `MW:ProjectName` | `MW__ProjectName` | No | Optional project grouping |
| `MW:ApmCollectMetrics` | `MW__ApmCollectMetrics` | No | Enable or disable metrics |
| `MW:ApmCollectTraces` | `MW__ApmCollectTraces` | No | Enable or disable traces |
| `MW:ApmCollectLogs` | `MW__ApmCollectLogs` | No | Enable or disable logs |
| `MW:ConsoleExporter` | `MW__ConsoleExporter` | No | Enable console telemetry output |
| `MW:ExcludeLinks` | `MW__ExcludeLinks` | No | JSON array string of routes to exclude |

### Example: Exclude health check endpoints

To prevent health check requests from generating unnecessary telemetry, configure:

```bash
MW__ExcludeLinks=["/health"]
```

You can include multiple endpoints:

```bash
MW__ExcludeLinks=["/health","/ready","/live"]
```

### Example: Disable log collection

To disable custom log collection while keeping traces and metrics enabled:

```bash
MW__ApmCollectLogs=false
MW__ApmCollectTraces=true
MW__ApmCollectMetrics=true
```

Save the settings and restart the Web App if necessary.

## Troubleshooting

### No traces or metrics in Middleware

If the Web App is running but telemetry does not appear:

- Verify that the `MW.APM` package is installed.
- Confirm that `ConfigureMWInstrumentation()` is called before `builder.Build()`.
- Check that `MW:ApiKey`, `MW:TargetURL`, and `MW:ServiceName` are configured correctly.
- Generate application traffic to trigger telemetry collection.
- Verify outbound HTTPS connectivity to your Middleware target.

### Azure Application Settings are not taking effect

If changes to the Azure configuration do not apply:

- Verify that the setting names use double underscores (`__`) for nested keys.
- Check for conflicting values in `appsettings.json`.
- Save the Azure Application Settings.
- Restart the Web App after making changes.

### Metrics appear but traces or logs are missing

If only some telemetry types are available:

- Verify that `MW:ApmCollectTraces` is set to `true`.
- Verify that `MW:ApmCollectLogs` is set to `true`.
- Check the application's logging configuration.
- Restart the Web App after changing SDK settings.

### Too many health check traces

If health checks generate unnecessary traces:

- Add `/health` or other health check routes to `MW:ExcludeLinks`.
- Ensure the value is formatted as a JSON array string.
- Restart the Web App after updating the configuration.

### Application cannot connect to Middleware

If the SDK reports export or connection errors:

- Verify that the Middleware target URL is correct.
- Check Azure App Service outbound network restrictions.
- If your Web App uses VNet integration, verify the outbound routing and firewall rules.
- Confirm that HTTPS traffic to the Middleware endpoint on port 443 is allowed.

If the issue persists, contact Middleware Support at support@middleware.io.

Need assistance or want to learn more about Middleware? Get in touch with us via our Contact Us page or join our Slack channel.
