You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何关闭Azure健康检查函数日志以降低ApplicationInsights开销

解决Azure健康检查日志过量占用Application Insights资源的问题

一、过滤Azure内部健康检查函数日志

直接修改host.json,精准指定健康检查相关命名空间的日志级别为None,覆盖默认配置:

{
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "excludedTypes": "Request"
      }
    },
    "logLevel": {
      "Microsoft.Azure.WebJobs.Extensions.HealthChecks": "None",
      "Azure.Core.HttpPipeline": "None"
    }
  }
}
  • 说明:之前仅设置Health相关级别未生效,是因为未定位到正确的命名空间。上述配置会直接阻止健康检查函数的FunctionStarted和FunctionCompleted日志输出。

二、拦截Web应用/api/health路径的请求日志

通过自定义TelemetryProcessor过滤健康检查请求日志:

  1. 创建自定义处理器类:
public class HealthCheckTelemetryProcessor : ITelemetryProcessor
{
    private readonly ITelemetryProcessor _nextProcessor;

    public HealthCheckTelemetryProcessor(ITelemetryProcessor nextProcessor)
    {
        _nextProcessor = nextProcessor;
    }

    public void Process(ITelemetry telemetry)
    {
        if (telemetry is RequestTelemetry requestTelemetry && 
            requestTelemetry.Url.PathAndQuery.StartsWith("/api/health", StringComparison.OrdinalIgnoreCase))
        {
            return; // 跳过健康检查请求的日志写入
        }
        _nextProcessor.Process(telemetry);
    }
}
  1. 在应用启动类中注册处理器:
services.AddApplicationInsightsTelemetry();
services.AddSingleton<ITelemetryProcessor, HealthCheckTelemetryProcessor>();

三、验证App Service健康检查配置

  • 确认App Service门户中配置的健康检查路径与你自定义的/api/health一致,避免触发额外的未预期检查请求。
  • 若有独立监控机制,可考虑关闭App Service层面的自动健康检查,但不推荐在生产环境直接关闭。

内容的提问来源于stack exchange,提问作者Richard Barraclough

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 11:45:06