Skip to content

04 - Logging and Monitoring (Consumption)

Set up baseline observability for a Consumption (Y1) Function App with Application Insights and CLI log queries.

Prerequisites

Tool Version Purpose
Azure CLI 2.61+ Configure diagnostics and query logs
Deployed Function App Y1 Existing app from tutorial 02
Application Insights Workspace-based Telemetry destination

What You'll Build

You will connect the Function App to Application Insights, generate sample traffic, and verify request telemetry and live logs for a Linux Consumption deployment.

Infrastructure Context

Plan: Consumption (Y1) | Network: Public internet only | VNet: ❌ Not supported

Consumption has no VNet integration or private endpoint support. All traffic flows over the public internet. Storage uses connection string authentication.

flowchart TD
    INET[Internet] -->|HTTPS| FA[Function App\nConsumption Y1\nLinux Python 3.11]

    FA -->|System-Assigned MI| ENTRA[Microsoft Entra ID]
    FA -->|"AzureWebJobsStorage__accountName\n+ connection string"| ST[Storage Account\npublic access]
    FA --> AI[Application Insights]

    subgraph STORAGE[Storage Services]
        ST --- FS[Azure Files\ncontent share]
    end

    NO_VNET["⚠️ No VNet integration\nNo private endpoints"] -. limitation .- FA

    style FA fill:#0078d4,color:#fff
    style NO_VNET fill:#FFF3E0,stroke:#FF9800
    style STORAGE fill:#FFF3E0
flowchart LR
    A[Function App requests] --> B[Application Insights]
    B --> C[CLI query for recent requests]
    A --> D[Live log tail]

Steps

Step 1 - Set variables

export RG="rg-func-consumption-demo"
export APP_NAME="func-consumption-demo-001"
export STORAGE_NAME="stconsumptiondemo001"
export LOCATION="koreacentral"

Step 2 - Create Application Insights

Auto-created Application Insights

When you create a Function App via az functionapp create, an Application Insights resource is often auto-created with the same name as the app. Check your resource group first with az resource list --resource-group "$RG" --query "[?type=='Microsoft.Insights/components']" --output table. If one already exists, skip this step and use its name in Step 3.

az monitor app-insights component create \
  --app "appi-func-consumption-demo" \
  --resource-group "$RG" \
  --location "$LOCATION" \
  --application-type web
export APPINSIGHTS_CONNECTION_STRING=$(az monitor app-insights component show \
  --app "appi-func-consumption-demo" \
  --resource-group "$RG" \
  --query "connectionString" \
  --output tsv)

az functionapp config appsettings set \
  --name "$APP_NAME" \
  --resource-group "$RG" \
  --settings "APPLICATIONINSIGHTS_CONNECTION_STRING=$APPINSIGHTS_CONNECTION_STRING"

Step 4 - Generate test traffic

curl --request GET "https://$APP_NAME.azurewebsites.net/api/health"
curl --request GET "https://$APP_NAME.azurewebsites.net/api/requests/log-levels"
curl --request GET "https://$APP_NAME.azurewebsites.net/api/exceptions/test-error"

Step 5 - Query recent requests

az monitor app-insights query \
  --app "appi-func-consumption-demo" \
  --resource-group "$RG" \
  --analytics-query "requests | take 5 | project timestamp, name, resultCode, success" \
  --output table

Telemetry ingestion delay

Application Insights has a 2-5 minute ingestion delay. If Step 5 returns empty results immediately after Step 4, wait a few minutes and retry.

Step 6 - Stream host logs from CLI

az webapp log tail \
  --name "$APP_NAME" \
  --resource-group "$RG"

Cold start and log streaming

On Consumption (Y1), the app may be cold (scaled to zero) when you start log streaming. Send a request to the health endpoint first to wake the app, then start the log tail. Press Ctrl+C to stop streaming.

Use log streaming and Application Insights for diagnostics on Linux Consumption.

Verification

Application Insights query output excerpt:

Timestamp                    Name                    ResultCode    Success
---------------------------  ----------------------  ------------  --------
2026-04-03T09:37:10.123456Z GET /api/health         200           True
2026-04-03T09:37:13.012345Z GET /api/requests/...   200           True
2026-04-03T09:37:16.456789Z GET /api/exceptions/... 200           True

Log tail excerpt:

2026-04-03T09:37:10.100Z  Executing 'Functions.health' (Reason='This function was programmatically called...')
2026-04-03T09:37:10.123Z  Executed 'Functions.health' (Succeeded, Duration=23ms)
2026-04-03T09:37:16.430Z  Executed 'Functions.test_error' (Succeeded, Duration=44ms)

Next Steps

Use Infrastructure as Code to make this setup repeatable.

Next: 05 - Infrastructure as Code

See Also

Sources