監視 Azure Static Web Apps

啟用 Application Insights 來監視 API 要求、失敗和追蹤資訊。

重要

Application Insights 具有 Azure Static Web Apps 的獨立定價模型

注意

搭配 Azure Static Web Apps 使用 Application Insights 需要具有 API 的應用程式

新增監視功能

使用下列步驟,將 Application Insights 監視新增至靜態 Web 應用程式。

  1. 在Azure 入口網站中開啟靜態 Web Apps 實例。

  2. 從功能表中選取 [Application Insights ]。

  3. 選取 [啟用 Application Insights] 旁 [ ]。

  4. 選取 [儲存]。

Add Application Insights to Azure Static Web Apps

建立 Application Insights 實例之後,它會在用來將服務連結在一起的 Azure Static Web Apps 實例中建立相關聯的應用程式設定。

注意

如果您想要追蹤 Web 應用程式的不同功能如何使用端對端用戶端,您可以在 JavaScript 程式碼中插入追蹤呼叫。 如需詳細資訊,請參閱 適用于網頁的 Application Insights。

存取資料

  1. 從靜態 Web 應用程式中的 [ 概觀 ] 視窗中,選取 [資源群組 ] 旁 的連結。

  2. 從清單中,選取前面加上與靜態 Web 應用程式相同名稱的 Application Insights 實例。

下表醒目提示入口網站中的幾個位置,您可以用來檢查應用程式 API 端點的各個層面。

注意

如需 Application Insights 使用方式的詳細資訊,請參閱 App Insights 概觀

類型 功能表位置 描述
失敗 調查 > 失敗 檢閱失敗的要求。
伺服器要求 調查 > 效能 檢閱個別 API 要求。
記錄 監視 > 記錄 與編輯器互動以查詢交易記錄。
計量 監視 > 計量 與設計工具互動,以使用各種計量建立自訂圖表。

追蹤

使用下列步驟來檢視應用程式中的追蹤。

  1. 選取 [監視] 底下的 [ 記錄 ]。

  2. 將滑鼠停留在 [查詢 ] 視窗中的任何卡片上。

  3. 選取 [載入編輯器 ]。

  4. 將產生的查詢取代為 。 traces

  5. 選取執行

View Application Insights traces

限制記錄

在某些情況下,您可能會想要限制記錄,同時仍擷取錯誤和警告的詳細資料。 若要這樣做,您可以對 Azure Functions 應用程式的 host.json 檔案進行下列變更

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
              "isEnabled": true
            },
            "enableDependencyTracking": false
        },
        "logLevels": {
            "default": "Warning"
        }
    }
}

下一步