Lab 5 Trace & Observe Agents
Introduction¶
Tracing helps you understand and debug your agent's behavior by showing the sequence of steps, inputs, and outputs during execution. In Azure AI Foundry, tracing lets you observe how your agent processes requests, calls tools, and generates responses. You can use the Azure AI Foundry portal or integrate with OpenTelemetry and Application Insights to collect and analyze trace data, making it easier to troubleshoot and optimize your agent.
Lab Exercise¶
- Open the
app.py
file. -
Change the
AZURE_TELEMETRY_ENABLED
variable toTrue
to enable tracing:AZURE_TELEMETRY_ENABLED = True
Note
This setting enables telemetry for your agent. In the
initialize
function inapp.py
, the telemetry client is configured to send data to Azure Monitor.if AZURE_TELEMETRY_ENABLED: configure_azure_monitor(connection_string=await self.project_client.telemetry.get_connection_string())
tbd
Run the Agent App¶
- Press F5 to run the app.
- Select Preview in Editor to open the agent app in a new editor tab.
Start a Conversation with the Agent¶
Copy and paste the following prompt into the agent app to start a conversation:
Write an executive report that analysis the top 5 product categories and compares performance of the online store verses the average for the physical stores.
View Traces¶
You can view the traces of your agent's execution in the Azure AI Foundry portal or by using OpenTelemetry. The traces will show the sequence of steps, tool calls, and data exchanged during the agent's execution. This information is crucial for debugging and optimizing your agent's performance.
Using Azure AI Foundry Portal¶
To view traces in the Azure AI Foundry portal, follow these steps:
- Navigate to the **Azure AI Foundry portal.
- Select your project.
- Select the Tracing tab in the left-hand menu.
- Here, you can see the traces generated by your agent.
Drilling Down into Traces¶
- You may need to click on the Refresh button to see the latest traces as traces may take a few moments to appear.
- Select the trace named
Zava Agent Initialization
to view the details. - Select the
creare_agent Zava DIY Sales Agent
trace to view the details of the agent creation process. In theInput & outputs
section, you'll see the Agent instructions. - Next, select the
Zava Agent Chat Request: Write an executive...
trace to view the details of the chat request. In theInput & outputs
section, you'll see the user input and the agent's response.