Search code examples
azuresyntaxazure-application-insightsmetrics

Azure ApplicationInsights Metrics Syntax? - InternalServerFault


I'm using the ApplicationInsights API Explorer to test a filter clause. But it causes an error.

I found rare samples for the syntax (startswith(request/name, 'GET')) from which I derived my filter.

On the API Explorer: https://dev.applicationinsights.io/apiexplorer/metrics I entered my account credentials.

My Parameters are:

MetricID:

    requests/count

Filter:

    startswith(request/cloud_RoleInstance, 'development')

In Kusto language the query should be:

requests
| where cloud_RoleInstance startswith "development" 
| count 

and is working fine: result: ~ 47,000

Result from my query is:

  "error": {
    "message": "Unexpected error occurred",
    "code": "InternalServerFault",
    "innererror": {
      "code": "QueryCompilationError"
    }

But I expect the number of request that arrived in AppInsights from any cloud_RoleInstance starting with "development".

Documentation links typically point to https://dev.applicationinsights.io/ But I can't seem to find any helpful information about the filter syntax. Is the attribute cloud_RoleInstance not supported?


Solution

  • According to the specs, the filter query is an OData query "where the keys of each clause should be applicable dimensions for the metric you are retrieving". If I change your filter query slightly to cloud_RoleInstance eq 'development' then I get a more useful error: "The following dimensions are not valid in the filter clause for this metric: cloud_RoleInstance". I will reach out to the product team about returning a more useful error message in the first instance.

    The correct way to do this will be the Query API. Instead of translating your query to OData, you can encode your Kusto query and send it off as is.

    requests
    | where cloud_RoleInstance startswith "development" 
    | count 
    

    Encodes to:

    GET /v1/apps/{YOUR_APP}/query?query=requests%7C%20where%20cloud_RoleInstance%20startswith%20%22development%22%20%7C%20count%20 
    

    And returns the results you are looking for.