Application Insights:已记录 HTTP OPTIONS,但 GET/POST 被忽略

Application Insights: HTTP OPTIONS recorded but GET/POST ignored

我在一个有 WebAPI 后端的 Angular 站点上使用 AI。

我正在设置 AuthenticatedUserContext,在向我的 API 发出 http 请求时,我可以看到信息作为 cookie 附加。由于 CORS,有一个飞行前的 http OPTIONS 请求,正如预期的那样,这个请求不包括 AI cookie。

查看 AI 中的遥测数据,我只能看到 OPTIONS 请求,但看不到 GET/POST 请求。会话和经过身份验证的用户信息未附加到 OPTIONS 请求。为什么记录了 OPTIONS 请求而不记录 GET/POST?如何在没有 OPTIONS 请求

的情况下记录 GET/POST 请求

我在msdn论坛回复你了。也在这里回复:

我认为你达到了 bug。 GitHub 问题有解决方法建议,您可以尝试

要进行过滤,请使用此 doc。您将拥有这样的代码:

using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;

public class SuccessfulDependencyFilter : ITelemetryProcessor
{
    private ITelemetryProcessor Next { get; set; }

    // Link processors to each other in a chain.
    public SuccessfulDependencyFilter(ITelemetryProcessor next)
    {
        this.Next = next;
    }

    public void Process(ITelemetry item)
    {
        if (!OKtoSend(item)) { return; }

        this.Next.Process(item);
    }

    private bool OKtoSend (ITelemetry item)
    {
        var request = item as RequestTelemetry;

        //if its not a Request, return true.  We don't care to filter it here
        if (request == null) return true;

        if (request.Name.StartsWith("OPTIONS")) //CORS Pre Flight Request
        {
            return false;
        }
    }
}