JJvdw
JJvdw

Reputation: 13

Application Insights: HTTP OPTIONS recorded but GET/POST ignored

I'm using AI on an Angular site with a WebAPI backend.

I'm setting the AuthenticatedUserContext and I can see the info being attached as cookies when doing http requests to my API. Because of CORS there is a pre-flight http OPTIONS request and as expected this request does not include the AI cookies.

Looking at the telemetry data in AI I can only see the OPTIONS requests but not the GET/POST request. The session and Authenticated user info is not attached to the OPTIONS request. Why is the OPTIONS request recorded but not the GET/POST? How can I record the GET/POST requests without the OPTIONS requests



Upvotes: 0

Views: 1731

Answers (1)

Sergey Kanzhelev
Sergey Kanzhelev

Reputation: 343

I replied to you in msdn forum. Replying here as well:

I think you hit the bug. GitHub issue has a workaround suggestion you may try

For filtering use this doc. You'll have code like this:

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;
        }
    }
}

Upvotes: 4

Related Questions