Skip to content

Commit f4581a0

Browse files
Merge pull request #5555 from santiagxf/santiagxf-patch-1
Update trace-application.md
2 parents 65ef72d + 4d18d59 commit f4581a0

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

articles/ai-foundry/how-to/develop/trace-application.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ms.topic: how-to
1515

1616
Tracing provides deep visibility into execution of your application by capturing detailed telemetry at each execution step. Such helps diagnose issues and enhance performance by identifying problems such as inaccurate tool calls, misleading prompts, high latency, low-quality evaluation scores, and more.
1717

18-
This article explains how to implement tracing for AI applications using OpenAI SDK with OpenTelemetry in Azure AI Foundry.
18+
This article explains how to implement tracing for AI applications using **OpenAI SDK** with OpenTelemetry in Azure AI Foundry.
1919

2020
## Prerequisites
2121

@@ -28,9 +28,9 @@ You need the following to complete this tutorial:
2828

2929
## Enable tracing in your project
3030

31-
Azure AI Foundry stores traces in Azure Application Insight resources using OpenTelemetry. By default, new Azure AI Foundry resources don't provision these resources. You can connect them to an existing Azure Application Insights resource or create a new one from within the project. You do such configuration once per each Azure AI Foundry resource.
31+
Azure AI Foundry stores traces in Azure Application Insight resources using OpenTelemetry. By default, new Azure AI Foundry resources don't provision these resources. You can connect projects to an existing Azure Application Insights resource or create a new one from within the project. You do such configuration once per each Azure AI Foundry resource.
3232

33-
The following steps show how to configure:
33+
The following steps show how to configure your resource:
3434

3535
1. Go to [Azure AI Foundry portal](https://ai.azure.com) and navigate to your project.
3636

@@ -56,7 +56,7 @@ The following steps show how to configure:
5656
5757
3. Select **Create** to create the resource and connect it to the Azure AI Foundry resource.
5858

59-
4. Once the connection is configured, you are ready to use tracing in this project.
59+
4. Once the connection is configured, you are ready to use tracing in any project within the resource.
6060

6161
5. Go to the landing page of your project and copy the project's endpoint URI. You need it later in the tutorial.
6262

@@ -68,7 +68,7 @@ The following steps show how to configure:
6868

6969
## Instrument the OpenAI SDK
7070

71-
When developing using the OpenAI SDK you can instrument your code so traces are sent to Azure AI Foundry. Follow these steps:
71+
When developing with the OpenAI SDK, you can instrument your code so traces are sent to Azure AI Foundry. Follow these steps to instrument your code:
7272

7373
1. Install `azure-ai-projects`, `azure-monitor-opentelemetry`, and `opentelemetry-instrumentation-openai-v2` in your environment. The following example uses `pip`:
7474

@@ -84,7 +84,7 @@ When developing using the OpenAI SDK you can instrument your code so traces are
8484
OpenAIInstrumentor().instrument()
8585
```
8686

87-
1. Get the connection string to the Azure Application Insights resource to your project:
87+
1. Get the connection string to the Azure Application Insights resource associated with your project:
8888

8989
```python
9090
from azure.ai.projects import AIProjectClient
@@ -103,17 +103,17 @@ When developing using the OpenAI SDK you can instrument your code so traces are
103103
>
104104
> :::image type="content" source="../../media/how-to/develop/trace-application/tracing-copy-connection-string.png" alt-text="A screenshot showing how to copy the connection string to the underlying Azure Application Insights resource from a project." lightbox="../../media/how-to/develop/trace-application/tracing-copy-connection-string.png":::
105105

106-
1. Configure OpenTelemetry to send traces to the Azure Application Insights used by Azure AI Foundry:
106+
1. Configure OpenTelemetry to send traces to the Azure Application Insights:
107107

108108
```python
109109
from azure.monitor.opentelemetry import configure_azure_monitor
110110

111111
configure_azure_monitor(connection_string=connection_string)
112112
```
113113

114-
1. By default, OpenTelemetry doesn't capture inputs and outputs. Use the environment variable `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` to capture it. Ensure this environment variable is configured in the environment level where your code is running.
114+
1. By default, OpenTelemetry doesn't capture inputs and outputs. Use the environment variable `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` to capture them. Ensure this environment variable is configured in the environment level where your code is running.
115115

116-
1. Use the OpenAI SDK in the same way you are used to:
116+
1. Use the OpenAI SDK as usual:
117117

118118
```python
119119
client = project_client.get_azure_openai_client()
@@ -130,15 +130,15 @@ When developing using the OpenAI SDK you can instrument your code so traces are
130130

131131
:::image type="content" source="../../media/how-to/develop/trace-application/tracing-display-simple.png" alt-text="A screenshot showing how a simple chat completion request is displayed in the trace." lightbox="../../media/how-to/develop/trace-application/tracing-display-simple.png":::
132132

133-
1. It may be useful to capture sections of your code that mixes business logic with models when developing complex applications. You can do that by first getting an instance of the current tracer.
133+
1. It may be useful to capture sections of your code that mixes business logic with models when developing complex applications. OpenTelemetry uses the concept of spans to capture sections you're interested in. To start generating your own spans, get an instance of the current **tracer** object.
134134

135135
```python
136136
from opentelemetry import trace
137137

138138
tracer = trace.get_tracer(__name__)
139139
```
140140

141-
1. Then, use decorators in your method to capture specific scenarios in your code that you are interested in. The following example assesses if a list of claims with a list of contexts.
141+
1. Then, use decorators in your method to capture specific scenarios in your code that you are interested in. Such decorators generate spans automatically. The following code example instruments a method called `assess_claims_with_context` with iterates over a list of claims and verify if the claim is supported by the context using an LLM. All the calls made in this method are captured within the same span:
142142

143143
```python
144144
def build_prompt_with_context(claim: str, context: str) -> str:
@@ -171,7 +171,7 @@ When developing using the OpenAI SDK you can instrument your code so traces are
171171

172172
:::image type="content" source="../../media/how-to/develop/trace-application/tracing-display-decorator.png" alt-text="A screenshot showing how a method using a decorator is displayed in the trace." lightbox="../../media/how-to/develop/trace-application/tracing-display-decorator.png":::
173173

174-
1. You may also want to add extra information as attributes to the current span. Use the `trace` object to access it and include extra information. See how the `assess_claims_with_context` method has been modified to include an attribute:
174+
1. You may also want to add extra information to the current span. OpenTelemetry uses the concept of **attributes** for that. Use the `trace` object to access them and include extra information. See how the `assess_claims_with_context` method has been modified to include an attribute:
175175

176176
```python
177177
@tracer.start_as_current_span("assess_claims_with_context")
@@ -274,4 +274,4 @@ Configure tracing as follows:
274274

275275
## Next steps
276276

277-
* [Trace agents using Azure AI Foundry SDK](trace-agents-sdk.md)
277+
* [Trace agents using Azure AI Foundry SDK](trace-agents-sdk.md)

0 commit comments

Comments
 (0)