Skip to content

Commit 24fffdd

Browse files
authored
Merge pull request #1859 from aahill/agents
[Azure AI Svcs] Tracing article
2 parents 2343906 + 1d0dc15 commit 24fffdd

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: 'How to enable tracing in Azure AI Agents'
3+
titleSuffix: Azure AI services
4+
description: Learn how to trace your AI agent's executions for debugging and evaluation.
5+
services: cognitive-services
6+
manager: nitinme
7+
ms.service: azure
8+
ms.topic: conceptual
9+
ms.date: 12/03/2024
10+
author: aahill
11+
ms.author: aahi
12+
---
13+
14+
# Tracing using Application Insights
15+
16+
Determining the reasoning behind your agent's executions is important for troubleshooting and debugging. However, it can be difficult for complex agents for a number of reasons:
17+
* There could be a high number of steps involved in generating a response, making it hard to keep track of all of them.
18+
* The sequence of steps might vary based on user input.
19+
* The inputs/outputs at each stage might be long and deserve more detailed inspection.
20+
* Each step of an agent's runtime might also involve nesting. For example, an agent might invoke a tool, which uses another process, which then invokes another tool. If you notice strange or incorrect output from a top-level agent run, it might be difficult to determine exactly where in the execution the issue was introduced.
21+
22+
Tracing solves this by allowing you to clearly see the inputs and outputs of each primitive involved in a particular agent run, in the order in which they were invoked.
23+
24+
## Creating an Application Insights resource
25+
26+
Tracing lets you analyze your agent's performance and behavior by using OpenTelemetry and adding an Application Insights resource to your Azure AI Foundry project.
27+
28+
To add an Application Insights resource, navigate to the **Tracing** tab in the [AI Foundry portal](https://ai.azure.com/), and create a new resource if you don't already have one.
29+
30+
:::image type="content" source="../media/ai-foundry-tracing.png" alt-text="A screenshot of the tracing screen in the AI Foundry portal." lightbox="../media/ai-foundry-tracing.png":::
31+
32+
Once created, you can get an Application Insights connection string, configure your agents, and observe the full execution path of your agent through Azure Monitor. Typically you want to enable tracing before you create an agent.
33+
34+
## Trace an agent
35+
36+
First, use `pip install` to install OpenTelemetry and the Azure SDK tracing plugin.
37+
38+
```bash
39+
pip install opentelemetry
40+
pip install azure-core-tracing-opentelemetry
41+
```
42+
43+
You will also need an exporter to send results to your observability backend. You can print traces to the console or use a local viewer such as [Aspire Dashboard](/dotnet/aspire/fundamentals/dashboard/standalone?tabs=bash). To connect to Aspire Dashboard or another OpenTelemetry compatible backend, install the OpenTelemetry Protocol (OTLP) exporter.
44+
45+
```bash
46+
pip install opentelemetry-exporter-otlp
47+
```
48+
49+
Once you have the packages installed, you can use one the following Python samples to implement tracing with your agents. Samples that use console tracing display the results locally in the console. Samples that use Azure Monitor send the traces to the Azure Monitor in the [AI Foundry portal](https://ai.azure.com/), in the **Tracing** tab in the left navigation menu for the portal.
50+
51+
> [!NOTE]
52+
> There is a known bug in the agents tracing functionality. The bug will cause the agent's function tool to call related info (function names and parameter values, which could contain sensitive information) to be included in the traces even when content recording is not enabled.
53+
54+
55+
**Using Azure Monitor**
56+
* [Basic agent example](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/samples/agents/sample_agents_basics_with_azure_monitor_tracing.py)
57+
* [Agent example with function calling](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/samples/agents/sample_agents_functions_with_azure_monitor_tracing.py)
58+
* [Example with a stream event handler](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_azure_monitor_tracing.py)
59+
60+
**Using console tracing**
61+
* [Basic agent example](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/samples/agents/sample_agents_basics_with_console_tracing.py)
62+
* [Agent example with function calling](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/samples/agents/sample_agents_functions_with_console_tracing.py)
63+
* [Example with a stream event handler](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-projects/samples/agents/sample_agents_stream_eventhandler_with_console_tracing.py)
64+
65+
495 KB
Loading

articles/ai-services/agents/toc.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ items:
2020
items:
2121
- name: Agents
2222
href: concepts/agents.md
23+
- name: Tracing with Application Insights
24+
href: concepts/tracing.md
2325
- name: How-to
2426
items:
2527
- name: Tools
@@ -34,16 +36,14 @@ items:
3436
href: how-to/tools/bing-grounding.md
3537
- name: File search
3638
href: how-to/tools/file-search.md
37-
- name: Use licenced data
39+
- name: Use licensed data
3840
href: how-to/tools/licensed-data.md
3941
- name: Action tools
4042
items:
41-
- name: Function calling
42-
items:
43-
- name: Agent function calling
44-
href: how-to/tools/function-calling.md
45-
- name: Logic app function calling
46-
href: how-to/tools/agent-logic-apps.md
43+
- name: Agent function calling
44+
href: how-to/tools/function-calling.md
45+
- name: Logic app function calling
46+
href: how-to/tools/agent-logic-apps.md
4747
- name: Responsible AI
4848
items:
4949
- name: Overview

0 commit comments

Comments
 (0)