|
| 1 | +--- |
| 2 | +title: Visualize traces on Azure AI Foundry Tracing UI |
| 3 | +description: Learn how to visualize traces on Azure AI Foundry Tracing UI |
| 4 | +author: taochen |
| 5 | +ms.topic: conceptual |
| 6 | +ms.author: taochen |
| 7 | +ms.date: 09/12/2024 |
| 8 | +ms.service: semantic-kernel |
| 9 | +--- |
| 10 | + |
| 11 | +# Visualize traces on Azure AI Foundry Tracing UI |
| 12 | + |
| 13 | +[Azure AI Foundry](https://learn.microsoft.com/en-us/azure/ai-studio/) Tracing UI is a web-based user interface that allows you to visualize traces and logs generated by your applications. This article provides a step-by-step guide on how to visualize traces on Azure AI Foundry Tracing UI. |
| 14 | + |
| 15 | +> [!IMPORTANT] |
| 16 | +> Before you start, make sure you have completed the tutorial on [inspecting telemetry data with Application Insights](./telemetry-with-app-insights.md). |
| 17 | +
|
| 18 | +> [!IMPORTANT] |
| 19 | +> This feature is currently only available on Semantic Kernel Python. Support for other languages is coming soon. |
| 20 | +
|
| 21 | +Prerequisites: |
| 22 | + |
| 23 | +- An Azure AI Foundry project. Follow this [guide](https://learn.microsoft.com/en-us/azure/ai-studio/how-to/create-projects) to create one if you don't have one. |
| 24 | +- A serverless inference API. Follow this [guide](https://learn.microsoft.com/en-us/azure/ai-studio/how-to/deploy-models-serverless) to create one if you don't have one. |
| 25 | +- Alternatively, you can attach an Azure OpenAI resource to the project, in which case you don't need to create a serverless API. |
| 26 | + |
| 27 | +## Attach an Application Insights resource to the project |
| 28 | + |
| 29 | +Go to the Azure AI Foundry project, select the **Tracing** tab on the left blade, and use the drop down to attach the Application Insights resource you created in the previous tutorial then click **Connect**. |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +## Use the Azure AI Inference connector |
| 34 | + |
| 35 | +We are going to replace the chat completion service with the Azure AI Inference connector. This connector will automatically send traces that can be visualized on the Azure AI Foundry Tracing UI. |
| 36 | + |
| 37 | +```python |
| 38 | +from semantic_kernel.connectors.ai.azure_ai_inference import AzureAIInferenceChatCompletion |
| 39 | + |
| 40 | +# Create an Azure AI Inference chat completion service with environment variables |
| 41 | +kernel.add_service(AzureAIInferenceChatCompletion(ai_model_id="my-deployment", service_id="my-service-id")) |
| 42 | + |
| 43 | +# If you are using an Azure OpenAI endpoint, you can do the following instead. |
| 44 | +from azure.ai.inference.aio import ChatCompletionsClient |
| 45 | +from azure.identity.aio import DefaultAzureCredential |
| 46 | + |
| 47 | +kernel.add_service(AzureAIInferenceChatCompletion( |
| 48 | + ai_model_id="my-deployment", |
| 49 | + client=ChatCompletionsClient( |
| 50 | + endpoint=f"{str(endpoint).strip('/')}/openai/deployments/{deployment_name}", |
| 51 | + credential=DefaultAzureCredential(), |
| 52 | + credential_scopes=["https://cognitiveservices.azure.com/.default"], |
| 53 | + ), |
| 54 | +)) |
| 55 | +``` |
| 56 | + |
| 57 | +Run the script again. |
| 58 | + |
| 59 | +## Visualize traces on Azure AI Foundry Tracing UI |
| 60 | + |
| 61 | +After the script finishes running, head over to the Azure AI Foundry tracing UI. You will see a new trace in the trace UI. |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +> [!TIP] |
| 66 | +> It may take a few minutes for the traces to show up on the UI. |
| 67 | +
|
| 68 | +## Next steps |
| 69 | + |
| 70 | +Now that you have successfully visualize trace data with an Azure AI Foundry project, you can explore more features of Semantic Kernel that can help you monitor and diagnose your application: |
| 71 | + |
| 72 | +> [!div class="nextstepaction"] |
| 73 | +> [Advanced telemetry with Semantic Kernel](./telemetry-advanced.md) |
0 commit comments