|
| 1 | +--- |
| 2 | +title: Visualize your traces |
| 3 | +titleSuffix: Azure AI Studio |
| 4 | +description: This article provides instructions on how to visualize your traces. |
| 5 | +manager: scottpolly |
| 6 | +ms.service: azure-ai-studio |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 11/19/2024 |
| 9 | +ms.reviewer: amipatel |
| 10 | +ms.author: lagayhar |
| 11 | +author: lgayhardt |
| 12 | +--- |
| 13 | + |
| 14 | +# Visualize your traces |
| 15 | + |
| 16 | +[!INCLUDE [feature-preview](../../includes/feature-preview.md)] |
| 17 | + |
| 18 | +After instrumenting your application to log traces, let's walkthrough how you can view your traces in both local and cloud solutions to debug your application. |
| 19 | + |
| 20 | +## View your traces for local debugging |
| 21 | + |
| 22 | +To enable traces locally, you have two options: |
| 23 | + |
| 24 | +1. Using **Prompty**, you can trace your application with the **Azure AI Inference SDK**, which offers enhanced visibility and simplified troubleshooting for LLM-based applications. This method follows the OpenTelemetry specification, capturing and visualizing the internal execution details of any AI application, thereby enhancing the overall development experience. To learn more, see [Debugging Prompty](https://prompty.ai/docs/getting-started/debugging-prompty). |
| 25 | +2. **Aspire Dashboard** : A free & open-source OpenTelemetry dashboard for deep insights into your apps on your local development machine. To learn more, see [Aspire Dashboard](https://aspiredashboard.com/#start ). |
| 26 | + |
| 27 | +## View your traces in Azure AI Foundry portal |
| 28 | + |
| 29 | +Before you can log to Azure AI Foundry portal, attach an Application Insights resource to your project. |
| 30 | + |
| 31 | +1. Navigate to your project in [Azure AI Foundry portal](https://ai.azure.com/). |
| 32 | +1. Select the **Tracing** page on the left hand side. |
| 33 | +1. Select **Create New** to attach a new Application Insights resource to your project. |
| 34 | +1. Supply a name and select **Create**. |
| 35 | + |
| 36 | +:::image type="content" source="../../media/trace/visualize/tracing-setup-overview.gif" alt-text="Animation of going to tracing and creating an Application Insight resource." lightbox="../../media/trace/visualize/tracing-setup-overview.gif"::: |
| 37 | + |
| 38 | +Next, install the `opentelemetry` SDK: |
| 39 | + |
| 40 | +```python |
| 41 | +%pip install azure-monitor-opentelemetry |
| 42 | +``` |
| 43 | + |
| 44 | +Now enable tracing with output to the console: |
| 45 | + |
| 46 | +```python |
| 47 | +import os |
| 48 | +from azure.monitor.opentelemetry import configure_azure_monitor |
| 49 | + |
| 50 | +os.environ['AZURE_TRACING_GEN_AI_CONTENT_RECORDING_ENABLED'] = 'true' |
| 51 | +# Enable Azure Monitor tracing |
| 52 | +application_insights_connection_string = project.telemetry.get_connection_string() |
| 53 | +if not application_insights_connection_string: |
| 54 | + print("Application Insights was not enabled for this project.") |
| 55 | + print("Enable it via the 'Tracing' tab in your AI Studio project page.") |
| 56 | + exit() |
| 57 | + |
| 58 | +configure_azure_monitor(connection_string=application_insights_connection_string) |
| 59 | +``` |
| 60 | + |
| 61 | +Finally, run an inferencing call. The call is logged to Azure AI Studio. This code prints a link to the traces. |
| 62 | + |
| 63 | +```python |
| 64 | +response = chat.complete( |
| 65 | + model="gpt-4o-mini", |
| 66 | + messages=[ |
| 67 | + {"role": "system", "content": "You are an AI assistant that is a travel planning expert especially with National Parks."}, |
| 68 | + {"role": "user", "content": "Hey, can you recommend me trails I should go on when I visit Mount Rainier?"}, |
| 69 | + ] |
| 70 | +) |
| 71 | + |
| 72 | +print("View traces at:") |
| 73 | +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']}") |
| 74 | +``` |
| 75 | + |
| 76 | +Select the link and begin viewing traces in Azure AI Studio! |
| 77 | + |
| 78 | +### Debug and filter traces |
| 79 | + |
| 80 | +In your project, you can filter your traces as you see fit. |
| 81 | + |
| 82 | +By selecting a trace, I can step through each span and identify issues while observing how my application is responding. |
| 83 | + |
| 84 | +:::image type="content" source="../../media/trace/visualize/debug-filter-tracing.gif" alt-text="Animation of filtering traces in the portal." lightbox="../../media/trace/visualize/debug-filter-tracing.gif"::: |
| 85 | + |
| 86 | +### Update your attached Application Insights resource |
| 87 | + |
| 88 | + To update the Application Insights resource that is attached to your project, go to **Manage data source** and **Edit** to switch to a new Application Insights resource. |
| 89 | + |
| 90 | +:::image type="content" source="../../media/trace/visualize/tracing-manage-data-source.png" alt-text="Screenshot of manage data sources pop-up highlighting the edit button." lightbox="../../media/trace/visualize/tracing-manage-data-source.png"::: |
| 91 | + |
| 92 | +## View your traces in Azure Monitor |
| 93 | + |
| 94 | +If you logged traces using the previous code snippet, then you're all set to view your traces in Azure Monitor Application Insights. You can open in Application Insights from **Manage data source** and use the **End-to-end transaction details view** to further investigate. |
| 95 | + |
| 96 | +For more information on how to send Azure AI Inference traces to Azure Monitor and create Azure Monitor resource, see [Azure Monitor OpenTelemetry documentation](/azure/azure-monitor/app/opentelemetry-enable). |
| 97 | + |
| 98 | +### View your generative AI spans and traces |
| 99 | + |
| 100 | +From Azure AI studio project, you can also open your custom dashboard that provides you with insights specifically to help you monitor your generative AI application. |
| 101 | + |
| 102 | +In this Azure Workbook, you can view your Gen AI spans and jump into the Azure Monitor **End-to-end transaction details view** view to deep dive and investigate. |
| 103 | + |
| 104 | +Learn more about using this workbook to monitor your application, see [Azure Workbook documentation](/azure/azure-monitor/visualize/workbooks-create-workbook). |
| 105 | + |
| 106 | +## Related content |
| 107 | + |
| 108 | +- [Trace your application with Azure AI Inference SDK](./trace-local-sdk.md) |
0 commit comments