Link to home
Create AccountLog in
Avatar of Zack
ZackFlag for Australia

asked on

KQL query no exception messages appear.

Hi EE,


I made this query to trace exception in App Insights it works a treat but never return the messages or any details about the exception:


requests | where sdkVersion startswith "apim:" and success == false | project timestamp, operation_Id = tostring(operation_Id), requestId=customDimensions["Request Id"], requestName=name, url, httpCode=resultCode, httpMethod=customDimensions["HTTP Method"], duration, userId=user_AuthenticatedId, apiName=customDimensions["API Name"], apiRevision=customDimensions["API Revision"], apiOperation=customDimensions["Operation Name"], apiProduct=customDimensions["Product Name"], apiSubscription=customDimensions["Subscription Name"] | order by timestamp desc | lookup kind=leftouter (  requests   | where operation_Id <> operation_ParentId  | project operation_Id=tostring(split(trim_start(@"\|", operation_ParentId), ".")[0]), inner_operation_Id=operation_Id) on operation_Id | lookup kind=leftouter (  exceptions   | where customDimensions['Category'] == "Host.Results"  | project exceptionType=type, severityLevel, resourceName = cloud_RoleName, operation_Id, operationName = operation_Name, exceptions = array_reverse(['details'])  | mv-apply exceptions on  (     project message = exceptions["message"]    | summarize messages = make_list(message, 5)    | project exceptionMessages = strcat_array(messages, " | ")  )) on $left.inner_operation_Id == $right.operation_Id | project-away inner_operation_Id, operation_Id

Open in new window


Any ideas on what I could change to get details about the exceptions to display?


Thank you.

ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Zack

ASKER

Hi David,


I fixed an issue with inner_operation_id join (the column 'inner_operation_Id' must exist on both sides of the join). Also, I fixed an issue with MostCommonExceptionType; MostCommonExceptionType = top 1 by count_exceptionType = exceptionType - top gave this error; The operator cannot be the first operator in a query. So, I fixed that error, too.  



One error remains that none of these attributes are recognized: 

   timestamp,

    requestId,

    requestName,

    url,

    httpCode,

    httpMethod,

    duration,

    userId,

    apiName,

    apiRevision,

    apiOperation,

    apiProduct,

    apiSubscription



let errorCategory = "Host.Results";
requests
| where tostring(sdkVersion) startswith "apim:" and success == false
| project
    timestamp,
    operation_Id = tostring(operation_Id),
    requestId = tostring(customDimensions["Request Id"]),
    requestName = tostring(name),
    url,
    httpCode = tostring(resultCode),
    httpMethod = tostring(customDimensions["HTTP Method"]),
    duration,
    userId = tostring(user_AuthenticatedId),
    apiName = tostring(customDimensions["API Name"]),
    apiRevision = tostring(customDimensions["API Revision"]),
    apiOperation = tostring(customDimensions["Operation Name"]),
    apiProduct = tostring(customDimensions["Product Name"]),
    apiSubscription = tostring(customDimensions["Subscription Name"]),
    inner_operation_Id = tostring(split(trim_start(@"\|", operation_ParentId), ".")[0])
| order by timestamp desc
| lookup kind=leftouter (
    requests
    | where operation_Id <> operation_ParentId
    | project
        operation_Id = tostring(split(trim_start(@"\|", operation_ParentId), ".")[0]),
        inner_operation_Id = tostring(operation_Id)
) on operation_Id
| lookup kind=leftouter (
    exceptions
    | where customDimensions['Category'] == errorCategory and operation_Id != ""
    | project
        exceptionType = tostring(type),
        severityLevel = tostring(customDimensions['Severity Level']),
        resourceName = tostring(cloud_RoleName),
        operationName = tostring(operation_Name),
        message = tostring(customDimensions['Details']),
        inner_operation_Id = tostring(operation_Id)
) on inner_operation_Id
| project-away inner_operation_Id, operation_Id// Include exceptionType in project-away
| summarize
    TotalExceptions = count(),
    UniqueExceptionTypes = dcount(exceptionType), // Calculate unique exception types
    count_exceptionType = count() by exceptionType
    | top 1 by count_exceptionType desc
| project
    TotalExceptions,
    UniqueExceptionTypes,
    count_exceptionType

Open in new window



Thank you. 


Have you tried just reducing this to something basic, like a single field that doesn't seem to be working otherwise?


requests
| where tostring(sdkVersion) startswith "apim:" and success == false
| project url

Open in new window


Avatar of Zack

ASKER

Hi Guys,


Worked out the issue it was a logging issue on our end. This was the final query we went with:


let errorCategory = "Host.Results";
requests
| where tostring(sdkVersion) startswith "apim:" and success == false
| project
    timestamp,
    operation_Id = tostring(operation_Id),
    requestId = tostring(customDimensions["Request Id"]),
    requestName = tostring(name),
    url,
    httpCode = tostring(resultCode),
    httpMethod = tostring(customDimensions["HTTP Method"]),
    duration,
    userId = tostring(user_AuthenticatedId),
    apiName = tostring(customDimensions["API Name"]),
    apiRevision = tostring(customDimensions["API Revision"]),
    apiOperation = tostring(customDimensions["Operation Name"]),
    apiProduct = tostring(customDimensions["Product Name"]),
    apiSubscription = tostring(customDimensions["Subscription Name"]),
    inner_operation_Id = tostring(split(trim_start(@"\|", operation_ParentId), ".")[0])
| order by timestamp desc
| lookup kind=leftouter (
    requests
    | where operation_Id <> operation_ParentId
    | project
        operation_Id = tostring(split(trim_start(@"\|", operation_ParentId), ".")[0]),
        inner_operation_Id = tostring(operation_Id)
) on operation_Id
| lookup kind=leftouter (
    exceptions
    | where customDimensions['Category'] == errorCategory and operation_Id != ""
    | project
        exceptionType = tostring(type),
        severityLevel = tostring(customDimensions['Severity Level']),
        resourceName = tostring(cloud_RoleName),
        operationName = tostring(operation_Name),
        message = tostring(customDimensions['Details']),
        inner_operation_Id = tostring(operation_Id)
) on inner_operation_Id
| project-away inner_operation_Id, operation_Id// Include exceptionType in project-away
| summarize
    TotalExceptions = count(),
    UniqueExceptionTypes = dcount(exceptionType), // Calculate unique exception types
    count_exceptionType = count() by exceptionType
    | top 1 by count_exceptionType desc
| project
    TotalExceptions,
    UniqueExceptionTypes,
    count_exceptionType
 

Open in new window

Thank you.