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#

TracesMetricsApp LogsCustom LogsProfiling
✅✅✖✅✖

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:

1dotnet 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();.

1var configuration = new ConfigurationBuilder()
2    .SetBasePath(Directory.GetCurrentDirectory())
3    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
4    .AddEnvironmentVariables()
5    .Build();
6
7builder.Services.ConfigureMWInstrumentation(configuration);
8
9builder.Logging.AddConfiguration(configuration.GetSection("Logging"));
10builder.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:

1{
2  "MW": {
3    "ApiKey": "<MW_API_KEY>",
4    "TargetURL": "https://<MW_UID>.middleware.io:443",
5    "ServiceName": "<service-name>",
6    "ProjectName": "<project-name>",
7    "ConsoleExporter": "true",
8    "ExcludeLinks": "[\"/health\"]",
9    "ApmCollectMetrics": "true",
10    "ApmCollectTraces": "true",
11    "ApmCollectLogs": "true"
12  }
13}

Replace the placeholders with your Middleware account details.

Configuration reference#

SettingDescription
ApiKeyMiddleware API key
TargetURLMiddleware ingestion endpoint
ServiceNameService name displayed in Middleware APM
ProjectNameOptional project name for grouping services
ConsoleExporterEnables console output for debugging
ExcludeLinksRoutes excluded from instrumentation, such as /health
ApmCollectMetricsEnables metric collection
ApmCollectTracesEnables trace collection
ApmCollectLogsEnables 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:
NameValue
MW__ApiKey<MW_API_KEY>
MW__TargetURLhttps://<MW_UID>.middleware.io:443
MW__ServiceName<service-name>
MW__ProjectName<project-name>
  1. 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.
  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 to inspect individual requests.
  • Review application metrics in the service overview.
  • View custom logs in Log Monitoring, 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 keyAzure App SettingRequiredDescription
MW:ApiKeyMW__ApiKeyYesMiddleware API key
MW:TargetURLMW__TargetURLYesMiddleware ingestion endpoint
MW:ServiceNameMW__ServiceNameYesLogical service name
MW:ProjectNameMW__ProjectNameNoOptional project grouping
MW:ApmCollectMetricsMW__ApmCollectMetricsNoEnable or disable metrics
MW:ApmCollectTracesMW__ApmCollectTracesNoEnable or disable traces
MW:ApmCollectLogsMW__ApmCollectLogsNoEnable or disable logs
MW:ConsoleExporterMW__ConsoleExporterNoEnable console telemetry output
MW:ExcludeLinksMW__ExcludeLinksNoJSON array string of routes to exclude

Example: Exclude health check endpoints#

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

1MW__ExcludeLinks=["/health"]

You can include multiple endpoints:

1MW__ExcludeLinks=["/health","/ready","/live"]

Example: Disable log collection#

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

1MW__ApmCollectLogs=false
2MW__ApmCollectTraces=true
3MW__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 [email protected].

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

What did you think of this content?