Search code examples
c#azure-application-insights

Stop Application Insights including path parameters in the Operation Name


Our ASP.NET MVC application includes some URI path parameters, like:

https://example.com/api/query/14hes1017ceimgS2ESsIec

In Application Insights, this URI above becomes Operation Name

GET /api/query/14hes1017ceimgS2ESsIec

We don't want millions of unique Operations like this; it's just one code method serving them all (see below). We want to roll them up under an Operation Name like

GET /api/query/{path}

Here is the code method - I think App Insights could detect that the URI contains a query parameter... but it doesn't.

    [Route("api/query/{hash}")]
    public HttpResponseMessage Get(string hash)
    {
        ...

Solution

  • The reason Application Insights does not detect that the suffix of your Operation Name is a parameter is because the SDK does not look at your code, and for all practical purposes that's a valid URI.
    Two options to get what you want:

    1. Change your API to pass the parameter in the query string (that is stripped out of the Operation Name)
    2. Implement your own ITelemetryProcessor (detailed explanation can be found here), and remove the suffix hash from the Operation Name yourself