啟用 Azure App Service 應用程式的 Profiler

Application Insights Profiler 會預先安裝為 Azure App Service 執行階段的一部分。 您可以使用基本服務層級或更高層級,針對在 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] 下,選取 [開啟]

    若您稍早選擇 [基本] 集合層級,則會停用 [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

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

針對區域雲端啟用 Profiler

目前唯一需要修改端點的區域是 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 ID 時,Profiler 才支援 Microsoft Entra 驗證。

若要啟用 Microsoft Entra ID 以進行設定檔內嵌:

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

    1. 系統指派的受控識別文件 (部分機器翻譯)

    2. 使用者指派的受控識別文件 (部分機器翻譯)

  2. 在您的 Application Insights 資源中設定並啟用 Microsoft Entra ID

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

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

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

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

停用 Profiler

若要為個別應用程式的執行個體停止或重新啟動 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 資料夾來防止刪除。

下一步