首页 > 解决方案 > Azure Function V4 (.net 6) - 自定义指标 - 跟踪事件未正确记录

问题描述

我创建了 Azure 函数 (HTTP) 并使用 HTTPClient 调用了另一个 HTTP 函数。例如:Function1 调用 Function2。在 Function1 中,我有循环并基于它(次数)Function2 被调用。

我有以下代码的 startup.cs 文件

    var aiOptions = new    
    Microsoft.ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions();
            aiOptions.EnableAdaptiveSampling = false;
            aiOptions.EnableQuickPulseMetricStream = false;
            aiOptions.InstrumentationKey = "xxxxxxxxxxxxxxxxxxxxx";
            aiOptions.RequestCollectionOptions.TrackExceptions = true;
            builder.Services.AddApplicationInsightsTelemetry(aiOptions);

并使用下面的代码 in 函数来获取遥测客户端

   public Function1(TelemetryClient _TC)
        {
            this._telementryclient = _TC;            
        }

下面的代码存在于循环中。

    var properties = new Dictionary<string, string>
                    {{"ID", "xxxxxxxx"}, {"ProductID", "xxxxxxxxx"}, {"Track", "Function1" } 
    };
                    var metrics = new Dictionary<string, double>
                        {{"Count", 1}, { "Status", 1}};

                    //// Send the event:
                    _telementryclient.TrackEvent("TableTest", properties, metrics);

问题是上面的代码循环运行了 10 次,但事件在 customevents 表中只记录了 6-7 行。

    host.json:
    "logging": {      
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": false,
        "maxTelemetryItemsPerSecond": 20
      }
    }
packages used:
Microsoft.Azure.WebJobs.Extensions.ApplicationInsights (1.0.0 preview2)
Microsoft.Azure.WebJobs.Logging.ApplicationInsights 3.0.27

Please suggest

标签: azureazure-functionsazure-application-insights

解决方案


推荐阅读