簡體   English   中英

App Insights REST 調用使用 KQL 查詢返回空

[英]App Insights REST call using KQL query returns empty

按照 Microsoft 文檔,我想查詢App Insights資源以獲取跟蹤事件。 如果我使用特定端點直接訪問跟蹤:

https://api.applicationinsights.io/v1/apps/$aiAppId/events/traces

它完美地工作。 但我無法使用KQL查詢:

$aiAppId = 'my_app_insights_app_id'
$aiApiKey = 'my_app_insights_api_key'

$content = (Invoke-WebRequest -Uri "https://api.applicationinsights.io/v1/apps/$aiAppId/query" `
    -Method Post -UseBasicParsing `
    -Headers @{
        'x-api-key' = $aiApiKey
     } `
    -Body @{
        'timespan' = 'PT60M'
        'query' = 'traces | where timestamp >= ago(30m)'
     }
).Content

$content | ConvertFrom-Json

它產生一個空結果:

tables
------
{}

Azure 門戶執行 KQL 查詢我得到正確的結果。

我錯過了什么嗎? 任何幫助都非常感謝。

此致。

賈科莫 SS

$content | ConvertFrom-Json $content | ConvertFrom-JsonPSCustomObject 所以它顯示了你提到的結果:

在此處輸入圖像描述

您可以使用$s = $content | ConvertFrom-Json之類的代碼。 $s = $content | ConvertFrom-Json ,然后使用$s.tables.rows$s.tables.columns顯示詳細信息。

或者只使用$content ,然后您可以看到正確的 output:

在此處輸入圖像描述

請考慮編寫自己的邏輯來解析結果,而不是直接使用ConvertFrom-Json

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM