啟用 Azure App 服務 應用程式的分析工具

Application Insights Profiler 已預先安裝為Azure App 服務執行時間的一部分。 您可以使用基本服務層級或更新版本,在 App Service 上執行 ASP.NET 和 ASP.NET Core 應用程式執行 Profiler。 請遵循這些步驟,即使您在建置時將 Application Insights SDK 包含在應用程式中也一樣。

若要在 Linux 上啟用 Profiler,請逐步解 說 ASP.NET Core Azure Linux Web 應用程式指示

注意

Application Insights Profiler 的無程式碼安裝遵循 .NET Core 支援原則。 如需支援執行時間的詳細資訊,請參閱 .NET Core 支援原則

必要條件

確認 [永遠開啟] 設定已啟用

  1. 在Azure 入口網站中,移至您的 App Service 實例。

  2. 左窗格的 [設定] 下,選取 [ 組態 ]。

    Screenshot that shows selecting Configuration on the left pane.

  3. 選取 [ 一般設定] 索引標籤。

  4. 確認已選取 [ 永遠開啟 > ]。

    Screenshot that shows the General tab on the Configuration pane showing that Always On is enabled.

  5. 如果您進行變更,請選取 [ 儲存 ]。

啟用 Application Insights 和 Profiler

下列各節說明如何為相同的訂用帳戶或不同的訂用帳戶啟用 Application Insights。

針對相同訂用帳戶中的 Application Insights 和 App Service

如果您的 Application Insights 資源位於與 App Service 實例相同的訂用帳戶中:

  1. 左窗格的 [設定] 下,選取 [Application Insights ]。

    Screenshot that shows selecting Application Insights on the left pane.

  2. 在 [Application Insights] 底下 ,選取 [ 啟用 ]。

  3. 確認您已將 Application Insights 資源連線到您的應用程式。

    Screenshot that shows enabling Application Insights on your app.

  4. 根據您的應用程式,向下捲動並選取 .NET .NET Core 索引標籤。

  5. 確認已選取 [ 建議 的集合層級 > ]。

  6. 在 [分析工具] 底下 ,選取 [開啟 ]。

    如果您稍早選擇 基本 集合層級,則會停用 Profiler 設定。

  7. 選取 [ 套用 > 是 ] 以確認。

    Screenshot that shows enabling Profiler on your app.

針對不同訂用帳戶中的 Application Insights 和 App Service

如果您的 Application Insights 資源與您的 App Service 實例位於不同的訂用帳戶中,您必須為 App Service 實例建立應用程式設定,以手動啟用 Profiler。 您可以使用範本或其他方式自動建立這些設定。 以下是啟用 Profiler 所需的設定。

應用程式設定
APPINSIGHTS_INSTRUMENTATIONKEY Application Insights 資源的 iKey
APPINSIGHTS_PROFILERFEATURE_VERSION 1.0.0
DiagnosticServices_EXTENSION_VERSION ~3

使用下列方式設定這些值:

啟用區域雲端的分析工具

目前,唯一需要端點修改的區域是 Azure Government 由 21Vianet 運作的 Microsoft Azure。

應用程式設定 美國政府雲端 中國雲端
ApplicationInsightsProfilerEndpoint https://profiler.monitor.azure.us https://profiler.monitor.azure.cn
ApplicationInsightsEndpoint https://dc.applicationinsights.us https://dc.applicationinsights.azure.cn

啟用設定檔擷取的 Microsoft Entra 驗證

Application Insights Profiler 支援 Microsoft Entra 驗證進行設定檔擷取。 若要擷取應用程式的所有設定檔,您的應用程式必須經過驗證,並將必要的應用程式設定提供給 Profiler 代理程式。

當您在應用程式中使用 Application Insights SDK 參考和設定 Microsoft Entra 識別碼 時,Profiler 僅支援 Microsoft Entra 驗證。

若要啟用設定檔擷取的 Microsoft Entra 識別碼:

  1. 建立和新增受控識別,以向 App Service 驗證 Application Insights 資源:

    1. 系統指派的受控識別檔

    2. 使用者指派的受控識別檔

  2. 在 Application Insights 資源中設定並啟用 Microsoft Entra 識別碼

  3. 新增下列應用程式設定,讓 Profiler 代理程式知道要使用的受控識別。

    • 針對系統指派的身分識別:

      應用程式設定
      APPLICATIONINSIGHTS_AUTHENTICATION_STRING Authorization=AAD
    • 針對使用者指派的身分識別:

      應用程式設定
      APPLICATIONINSIGHTS_AUTHENTICATION_STRING Authorization=AAD;ClientId={Client id of the User-Assigned Identity}

停用分析工具

若要停止或重新開機個別應用程式實例的 Profiler:

  1. 左窗格的 [設定 ] 下,選取 [WebJobs ]。

    Screenshot that shows selecting web jobs on the left pane.

  2. 選取名為 ApplicationInsightsProfiler3 的 Webjob。

  3. 選取 [停止]。

    Screenshot that shows selecting stop for stopping the webjob.

  4. 選取 確認。

我們建議您在所有應用程式上都啟用 Profiler,以便儘早發現任何效能問題。

您可以使用 WebDeploy 將變更部署至 Web 應用程式時,刪除 Profiler 的檔案。 您可以排除 部署期間刪除App_Data 資料夾,以防止刪除。

下一步