Azure Web App
| Traces | Metrics | App Logs | Custom Logs | Profiling |
|---|---|---|---|---|
| ✅ | ✅ | ✖ | ✅ | ✖ |
Installation
1 Install the Package
1dotnet add package MW.APM2 Add code configuration to Program.cs (add near the top of the file, 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();3 Add Middleware settings to appsettings.json (placeholders only):
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}Troubleshooting
- No data in Traces/Metrics:
- Verify MW.APM is installed and appears in your project’s Dependencies → Packages.
- Confirm
MW:ApiKey,MW:TargetURL, andMW:ServiceNameare present (either inappsettings.jsonor as Azure App Settings overrides). - Make a few real requests to your Web App URL to generate traffic.
- App settings not taking effect: ensure Configuration → Application settings in the Azure portal matches your expected overrides and that you Restart the app after changes.
- Too much noise from health checks: add
/health(or your health endpoints) toMW:ExcludeLinks(JSON array string). - Only metrics but no logs/traces: check
MW:ApmCollectTraces/MW:ApmCollectLogstoggles are set to"true"and that your app restarts after editingappsettings.json.
Environment Variables
Because Program.cs includes AddEnvironmentVariables(), any appsettings.json key can be overridden by Azure Application settings. Use double underscores __ to denote sections.
| appsettings.json path | Env var (Azure App Setting) | Required | Purpose |
|---|---|---|---|
MW:ApiKey | MW__ApiKey | Yes | Middleware API key (store securely; avoid committing to code). |
MW:TargetURL | MW__TargetURL | Yes | Middleware ingestion endpoint (https://<MW_UID>.middleware.io:443). |
MW:ServiceName | MW__ServiceName | Yes | Logical service label shown in Middleware. |
MW:ProjectName | MW__ProjectName | No | Optional grouping for services. |
MW:ApmCollectMetrics | MW__ApmCollectMetrics | No | Toggle metrics (true/false). |
MW:ApmCollectTraces | MW__ApmCollectTraces | No | Toggle traces (true/false). |
MW:ApmCollectLogs | MW__ApmCollectLogs | No | Toggle logs (true/false). |
MW:ConsoleExporter | MW__ConsoleExporter | No | Local debugging aid (true/false). |
MW:ExcludeLinks | MW__ExcludeLinks | No | JSON array string of links to exclude (e.g. ["/health"]). |
Need assistance or want to learn more about Middleware? Contact our support team at [email protected] or join our Slack channel.