Azure AppInsights 未记录服务器响应时间

Azure AppInsights is not logging Server Response Time

我们正在使用 "Microsoft.ApplicationInsights 2.1.0.0" 并安装了 appinsight nugget 包。已配置的应用程序。我可以看到 PAGE VIEW、SERVER REQUEST 和 FAILED REQUEST。但我在 Azure 门户中看不到任何服务器响应时间。如果我向下钻取,我可以看到 OPERATION NAME。有没有什么东西不见了。

  public void LogTrace(string message, Dictionary<string,string> dict)
    {
         TelemetryClient.TrackTrace(message,dict);
    }

    public void LogHttpRequest(string Name,DateTime CreatedDateTime,TimeSpan Duration,string ResponseCode,bool flag)
    {
        TelemetryClient.TrackRequest(Name, CreatedDateTime, Duration, ResponseCode, flag);           
    }

private void LogMessage(string message, SeverityLevel traceSeverity, string title)
    {
       TelemetryClient.TrackTrace(title, traceSeverity, null);
    } 



public void LogMetrics(string PageName, double totalDuration)
    {
   TelemetryClient.TrackMetric(new MetricTelemetry(PageName, totalDuration));
    }

 public void LogCustomEvent(string message, Dictionary<string, string> extendedInformation, Dictionary<string, double> metrics)
    {
        TelemetryClient.TrackEvent(message, extendedInformation, metrics);
    }

public void LogException(Exception ex, string APPNAME)
    {
        var additonal = new Dictionary<string, string>();
        additonal.Add(APPNAME,APPNAME );
        TelemetryClient.TrackException(ex, new Dictionary<string, string>()
           {
                { "Exception Message", ex.Message },
                { "Exception Source", ex.Source },
                { "CallStack",ex.StackTrace??String.Empty}
           }, new Dictionary<string, double>()
            {
                { "Total HTTP Exceptions", 1 }
            });         
    }

是否有任何我遗漏的东西,这就是我们看不到任何服务器响应时间的原因。

根据您的代码,我假设您正在使用 Application Insights API 来获取自定义指标。我检查了 TrackRequest 并使用以下代码记录 HTTP 请求,如下所示:

TelemetryClient client = new TelemetryClient()
{
    InstrumentationKey = "{your-Instrumentation-Key}"
};
client.TrackRequest(new RequestTelemetry()
{
    Name = "/api/values",
    StartTime = DateTime.UtcNow,
    Duration = TimeSpan.FromSeconds(2),
    ResponseCode = "200",
    Success = true
});

结果:

总之,请确保您的事件类型正确并且可以包含持续时间。