ericOnline
ericOnline

Reputation: 2008

Combine Complex Kusto Queries

I have a Python Azure Function that produces custom logging messages when the Function executes. I'm able to pull specific info from the JSON inside the log strings (thank you @yoni).

How do I correctly combine 2 or more Kusto queries which parse different logging messages into a single query?

Example:

Kusto query (spacing for readability):

let varLookback = ago(1d);

let varPath = 

union traces
| union exceptions
| where timestamp > varLookback
| where message contains "####### Will write to"

//Pulls filePath out of Python logging string
| extend parsedMessage = todynamic(trim(@"#######",substring(message, 21)))
| project operation_Id, timestamp, filePath = parsedMessage;

union traces
| union exceptions
| where timestamp > varLookback
| where message contains "####### EventGrid trigger processing an event"

//Pulls message JSON out of Python logging string
| extend parsedMessage = todynamic(trim(@"#######",substring(message, 46)))

//Parses fileName and contentLength from message JSON
| project operation_Id, timestamp, fileName = split(parsedMessage["data"]["blobUrl"], "/")[6], contentLength = parsedMessage["data"]["contentLength"]

//I've tried different join kinds here (inner, inner_unique, right_outer, etc. same erroneous results)
| join varPath on $left.operation_Id == $right.operation_Id
| order by timestamp asc

Issue:

EDIT 1:

Why are some Function executions not showing custom logging?

Upvotes: 1

Views: 1182

Answers (1)

Yoni L.
Yoni L.

Reputation: 25995

a. Make sure you've chosen the right join kind (default is innerunique(doc))

  • If that doesn't help, perhaps including the (obfuscated) contents of both join legs in your question would help (as the total number of records seem low enough to fit)

Unrelated, perf tips:

  1. Prefer using has over contains whenever possible (doc)

  2. trim() (doc) takes a regular expression as its first argument. Based on the content of your messages, see if you can choose a better operator function, that doesn't require a regular expression (e.g. parse operator or substring() function)

Upvotes: 3

Related Questions