skip to content
Alvin Lucillo

Using log-analytics to query func logs

/ 2 min read

We learned from yesterday’s journal that using the Azure functions core tools may not work all the time. In that case, we can use Azure CLI. In the commands below, the function app name is funcapp1.

(1) Check if APPLICATIONINSIGHTS_CONNECTION_STRING is set. If it is, it means Application Insights is configured.

 az functionapp config appsettings list \
  --name funcapp1 \
  --resource-group funcapp1_group \
  --query "[?contains(name, 'APPINSIGHTS') || contains(name, 'APPLICATIONINSIGHTS')].name" \
  --output table
Result
-------------------------------------
APPLICATIONINSIGHTS_CONNECTION_STRING

(2) Find the insights resource associated to your function app.

az resource list \
  --resource-type "microsoft.insights/components" \
  --query "[].{name:name, resourceGroup:resourceGroup}" \
  --output table
Name             ResourceGroup
---------------  ---------------------
funcapp1         funcapp1_group

(3) Get the workspace resource ID of insights app

WORKSPACE_RESOURCE_ID=$(az monitor app-insights component show \
  --app "funcapp1" \
  --resource-group "funcapp1_group" \
  --query workspaceResourceId \
  --output tsv)

(4) Get the workspace ID from log-analytics based on the workspace resource ID from the previous step

WORKSPACE_ID=$(az monitor log-analytics workspace show \
  --ids "$WORKSPACE_RESOURCE_ID" \
  --query customerId \
  --output tsv)

(5) Now using the workspace ID from the previous step, we cna perform log analytics query:

az monitor log-analytics query \
  --workspace "$WORKSPACE_ID" \
  --analytics-query "AppTraces | where TimeGenerated > ago(1h) | where AppRoleName == 'funcapp1' | where Message contains 'Timer function processed request' | order by TimeGenerated desc | project TimeGenerated, Message" \
  --output table
Message                            TableName      TimeGenerated
---------------------------------  -------------  ----------------------------
Timer function processed request.  PrimaryResult  2026-05-19T12:34:30.0055293Z
Timer function processed request.  PrimaryResult  2026-05-19T12:34:20.0052954Z
Timer function processed request.  PrimaryResult  2026-05-19T12:34:10.0053659Z
Timer function processed request.  PrimaryResult  2026-05-19T12:34:00.0053114Z