Azure Web App

TracesMetricsApp LogsCustom LogsProfiling

Installation

1 Install the Package

1dotnet add package MW.APM

2 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, and MW:ServiceName are present (either in appsettings.json or 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) to MW:ExcludeLinks (JSON array string).
  • Only metrics but no logs/traces: check MW:ApmCollectTraces / MW:ApmCollectLogs toggles are set to "true" and that your app restarts after editing appsettings.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 pathEnv var (Azure App Setting)RequiredPurpose
MW:ApiKeyMW__ApiKeyYesMiddleware API key (store securely; avoid committing to code).
MW:TargetURLMW__TargetURLYesMiddleware ingestion endpoint (https://<MW_UID>.middleware.io:443).
MW:ServiceNameMW__ServiceNameYesLogical service label shown in Middleware.
MW:ProjectNameMW__ProjectNameNoOptional grouping for services.
MW:ApmCollectMetricsMW__ApmCollectMetricsNoToggle metrics (true/false).
MW:ApmCollectTracesMW__ApmCollectTracesNoToggle traces (true/false).
MW:ApmCollectLogsMW__ApmCollectLogsNoToggle logs (true/false).
MW:ConsoleExporterMW__ConsoleExporterNoLocal debugging aid (true/false).
MW:ExcludeLinksMW__ExcludeLinksNoJSON 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.