Azure Web App

TracesMetricsApp LogsCustom LogsProfiling

Installation#

1 Install the Package#

dotnet add package MW.APM

2 Add code configuration to Program.cs (add near the top of the file, before var app = builder.Build();):#

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();

3 Add Middleware settings to appsettings.json (placeholders only):#

{
  "MW": {
    "ApiKey": "<MW_API_KEY>",
    "TargetURL": "https://<MW_UID>.middleware.io:443",
    "ServiceName": "<service-name>",
    "ProjectName": "<project-name>",
    "ConsoleExporter": "true",
    "ExcludeLinks": "[\"/health\"]",
    "ApmCollectMetrics": "true",
    "ApmCollectTraces": "true",
    "ApmCollectLogs": "true"
  }
}

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.