共用方式為


將追蹤可視化

重要

本文中標示為 (預覽) 的項目目前處於公開預覽狀態。 此預覽版本沒有服務等級協定,不建議將其用於生產工作負載。 可能不支援特定功能,或可能已經限制功能。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款

檢測應用程式以記錄追蹤之後,讓我們逐步解說如何在本機和雲端解決方案中檢視追蹤,以偵錯您的應用程式。

檢視本機偵錯的追蹤

若要在本機啟用追蹤,您有兩個選項:

  1. 使用 Prompty,您可以使用 Azure AI 推斷 SDK 來追蹤應用程式,以提供增強的可見性和簡化 LLM 型應用程式的疑難解答。 此方法遵循 OpenTelemetry 規格,擷取和可視化任何 AI 應用程式的內部執行詳細數據,進而增強整體開發體驗。 若要深入瞭解,請參閱 偵錯提示。
  2. Aspire 儀錶板 :免費和開放原始碼的 OpenTelemetry 儀錶板,可讓您深入瞭解本機開發電腦上的應用程式。 若要深入瞭解,請參閱 Aspire 儀錶板

在 Azure AI Foundry 入口網站中檢視您的追蹤

您必須先將Application Insights資源附加至您的專案,才能登入 Azure AI Foundry 入口網站。

  1. 在 Azure AI Foundry 入口網站流覽至您的專案。
  2. 選取左側的 [ 追蹤 ] 頁面。
  3. 選取 [新建 ] 以將新的 Application Insights 資源附加至您的專案。
  4. 提供名稱,然後選取 [ 建立]。

移至追蹤和建立Application Insight資源的動畫。

接下來,安裝 opentelemetry SDK:

%pip install azure-monitor-opentelemetry

現在,使用輸出啟用主控台的追蹤:

import os
from azure.monitor.opentelemetry import configure_azure_monitor

os.environ['AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED'] = 'true'
# Enable Azure Monitor tracing
application_insights_connection_string = project.telemetry.get_connection_string()
if not application_insights_connection_string:
    print("Application Insights was not enabled for this project.")
    print("Enable it via the 'Tracing' tab in your Azure AI Foundry project page.")
    exit()
    
configure_azure_monitor(connection_string=application_insights_connection_string)

最後,執行推斷呼叫。 呼叫會記錄至 Azure AI Foundry。 此程式代碼會列印追蹤的連結。

response = chat.complete(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are an AI assistant that is a travel planning expert especially with National Parks."},
        {"role": "user", "content": "Hey, can you recommend me trails I should go on when I visit Mount Rainier?"},
    ]
)

print("View traces at:")
print(f"https://ai.azure.com/tracing?wsid=/subscriptions/{project.scope['subscription_id']}/resourceGroups/{project.scope['resource_group_name']}/providers/Microsoft.MachineLearningServices/workspaces/{project.scope['project_name']}")

選取連結並開始在 Azure AI Foundry 入口網站中檢視追蹤!

偵錯和篩選追蹤

在您的專案中,您可以視需要篩選追蹤。

藉由選取追蹤,我可以逐步執行每個範圍,並在觀察應用程式回應的方式時找出問題。

在入口網站中篩選追蹤的動畫。

更新附加的 Application Insights 資源

若要更新附加至專案的 Application Insights 資源,請移至 [管理數據源] 和 [編輯] 切換至新的 Application Insights 資源。

[管理數據源] 彈出視窗的螢幕快照,其中醒目提示 [編輯] 按鈕。

在 Azure 監視器中檢視您的追蹤

如果您使用先前的代碼段記錄追蹤,則您全都會設定為在 Azure 監視器 Application Insights 中檢視追蹤。 您可以從管理數據源在 Application Insights 中開啟 ,並使用端對端交易詳細數據檢視進一步調查。

如需如何將 Azure AI 推斷追蹤傳送至 Azure 監視器並建立 Azure 監視器資源的詳細資訊,請參閱 Azure 監視器 OpenTelemetry 檔

檢視您的產生的 AI 範圍和追蹤

從 Azure AI Foundry 專案,您也可以開啟自定義儀錶板,為您提供深入解析,以協助您監視您的產生 AI 應用程式。

在此 Azure 活頁簿中,您可以檢視您的 Gen AI 範圍,並跳至 Azure 監視器 端對端交易詳細數據檢視 ,以深入探討和調查。

深入瞭解使用此活頁簿來監視您的應用程式,請參閱 Azure 活頁簿檔