Skip to content

Commit d3ade15

Browse files
committed
edit pass: deploy-and-monitor-flows
1 parent 2ab445c commit d3ade15

File tree

3 files changed

+168
-186
lines changed

3 files changed

+168
-186
lines changed
Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: How to enable tracing and collect feedback for a flow deployment
2+
title: Enable Tracing and Collect Feedback for a Flow Deployment
33
titleSuffix: Azure AI Foundry
4-
description: This article provides instructions on how to enable tracing and collect feedback for a flow deployment in Azure AI Foundry portal.
4+
description: This article provides instructions on how to enable tracing and collect feedback for a flow deployment in the Azure AI Foundry portal.
55
manager: scottpolly
66
ms.service: azure-ai-foundry
77
ms.custom:
@@ -17,64 +17,63 @@ author: lgayhardt
1717

1818
[!INCLUDE [feature-preview](../../includes/feature-preview.md)]
1919

20-
After deploying a Generative AI APP in production, you might want to enhance your understanding and optimize performance. Trace data for each request, aggregated metrics, and user feedback play critical roles.
20+
After you deploy a generative AI application in production, you might want to enhance your understanding and optimize performance. Trace data for each request, aggregated metrics, and user feedback play critical roles.
2121

22-
In this article, you learn to enable tracing, collect aggregated metrics, and collect user feedback during inference time of your flow deployment.
22+
In this article, you learn to enable tracing, collect aggregated metrics, and collect user feedback during the inference time of your flow deployment.
2323

2424
> [!NOTE]
2525
> For an improved way to perform continuous monitoring of deployed applications (other than prompt flow), consider using [Azure AI online evaluation](../online-evaluation.md).
2626
2727
## Prerequisites
2828

29-
- The Azure CLI and the Azure Machine Learning extension to the Azure CLI.
29+
- The Azure CLI and the Azure Machine Learning extension to the Azure CLI.
3030
- An Azure AI Foundry project. If you don't already have a project, you can [create one here](../../how-to/create-projects.md).
31-
- An Application Insights. If you don't already have an Application Insights resource, you can [create one here](/azure/azure-monitor/app/create-workspace-resource).
32-
- Azure role-based access controls are used to grant access to operations in Azure Machine Learning. To perform the steps in this article, you must have **Owner** or **Contributor** permissions on the selected resource group. For more information, see [Role-based access control in Azure AI Foundry portal](../../concepts/rbac-ai-studio.md).
31+
- An Application Insights resource. If you don't already have an Application Insights resource, you can [create one here](/azure/azure-monitor/app/create-workspace-resource).
32+
- Azure role-based access controls are used to grant access to operations in Azure Machine Learning. To perform the steps in this article, you must have Owner or Contributor permissions on the selected resource group. For more information, see [Role-based access control in the Azure AI Foundry portal](../../concepts/rbac-ai-studio.md).
3333

3434
## Deploy a flow for real-time inference
3535

36-
After you test your flow properly, either a flex flow or a DAG flow, you can deploy the flow in production. In this article, we use [Deploy a flow for real-time inference](../../how-to/flow-deploy.md) as example. For flex flows, you need to [prepare the `flow.flex.yaml` file instead of `flow.dag.yaml`](https://microsoft.github.io/promptflow/how-to-guides/develop-a-flex-flow/index.html).
36+
After you test your flow properly (either a flex flow or a DAG flow), you can deploy the flow in production. In this article, we use [Deploy a flow for real-time inference](../../how-to/flow-deploy.md) as the example. For flex flows, you need to [prepare the `flow.flex.yaml` file instead of `flow.dag.yaml`](https://microsoft.github.io/promptflow/how-to-guides/develop-a-flex-flow/index.html).
3737

38-
You can also [deploy to other platforms, such as Docker container, Kubernetes cluster, and more](https://microsoft.github.io/promptflow/how-to-guides/deploy-a-flow/index.html).
38+
You can also [deploy to other platforms, such as Docker container and Kubernetes cluster](https://microsoft.github.io/promptflow/how-to-guides/deploy-a-flow/index.html).
3939

40-
> [!NOTE]
41-
> You need to use the latest prompt flow base image to deploy the flow, so that it supports the tracing and feedback collection API.
40+
Use the latest prompt flow base image to deploy the flow so that it supports the tracing and feedback collection API.
4241

4342
## Enable trace and collect system metrics for your deployment
4443

45-
If you're using Azure AI Foundry portal to deploy, you can turn on **Application Insights diagnostics** in the **Advanced settings** > **Deployment** step in the deployment wizard, in which way the tracing data and system metrics are collected to the project linked to Application Insights.
44+
If you're using the Azure AI Foundry portal to deploy, select **Deployment** > **Application Insights diagnostics** > **Advanced settings** in the deployment wizard. In this way, the tracing data and system metrics are collected to the project linked to Application Insights.
4645

47-
If you're using the SDK or CLI, you can add a property `app_insights_enabled: true` in the deployment yaml file that collects data to the project linked to application insights.
46+
If you're using the SDK or the CLI, add the `app_insights_enabled: true` property in the deployment yaml file that collects data to the project linked to Application Insights.
4847

4948
```yaml
5049
app_insights_enabled: true
5150
```
5251
53-
You can also specify other Application Insights by an environment variable `APPLICATIONINSIGHTS_CONNECTION_STRING` in the deployment yaml file as following. You can find the connection string of your Application Insights in the Overview page in Azure portal.
52+
You can also specify other application insights by the environment variable `APPLICATIONINSIGHTS_CONNECTION_STRING` in the deployment yaml file. You can find the connection string for Application Insights on the **Overview** page in the Azure portal.
5453

5554
```yaml
5655
environment_variables:
5756
APPLICATIONINSIGHTS_CONNECTION_STRING: <connection_string>
5857
```
5958

6059
> [!NOTE]
61-
> If you only set `app_insights_enabled: true` but your project doesn't have a linked Application Insights resource, your deployment won't fail but there will be no data collected.
60+
> If you set only `app_insights_enabled: true` but your project doesn't have a linked Application Insights resource, your deployment won't fail but no data is collected.
6261
>
63-
> If you specify both `app_insights_enabled: true` and the previous environment variable at the same time, the tracing data and metrics will be sent to the project linked to application insights. Hence, if you want to specify a different Application Insights, you only need to keep the environment variable.
62+
> If you specify both `app_insights_enabled: true` and the previous environment variable at the same time, the tracing data and metrics are sent to the project linked to Application Insights. If you want to specify different application insights, keep the environment variable only.
6463
>
65-
> If you deploy to other platforms, you can also use the environment variable `APPLICATIONINSIGHTS_CONNECTION_STRING: <connection_string>` to collect trace data and metrics to specified Application Insights.
64+
> If you deploy to other platforms, you can also use the environment variable `APPLICATIONINSIGHTS_CONNECTION_STRING: <connection_string>` to collect trace data and metrics to the application insights that you specified.
6665

6766
## View tracing data in Application Insights
6867

69-
Traces record specific events or the state of an application during execution. It can include data about function calls, variable values, system events and more. Traces help breakdown an application's components into discrete inputs and outputs, which is crucial for debugging and understanding an application. You can learn more from [here](https://opentelemetry.io/docs/concepts/signals/traces/) on traces. The trace data follows [OpenTelemetry specification](https://opentelemetry.io/docs/specs/otel/).
68+
Traces record specific events or the state of an application during execution. It can include data about function calls, variable values, and system events. Traces help to break down an application's components into discrete inputs and outputs. This process is crucial for debugging and understanding an application. To learn more about traces, see [this website](https://opentelemetry.io/docs/concepts/signals/traces/). The trace data follows the [OpenTelemetry specification](https://opentelemetry.io/docs/specs/otel/).
7069

71-
You can view the detailed trace in the specified Application Insights. The following screenshot shows an example of an event of a deployed flow containing multiple nodes. In Application Insights -> Investigate -> Transaction search, and you can select each node to view its detailed trace.
70+
You can view the detailed trace in the application insights that you specified. The following screenshot shows an example of an event of a deployed flow that contains multiple nodes. Select **Application Insights** > **Investigate** > **Transaction search**, and then select each node to view its detailed trace.
7271

73-
The **Dependency** type events record calls from your deployments. The name of that event is the name of the flow folder. Learn more about [Transaction search and diagnostics in Application Insights](/azure/azure-monitor/app/transaction-search-and-diagnostics).
72+
The **Dependency** type event records calls from your deployments. The name of the event is the name of the flow folder. To learn more, see [Transaction search and diagnostics in Application Insights](/azure/azure-monitor/app/transaction-search-and-diagnostics).
7473

7574
## View system metrics in Application Insights
7675

77-
| Metrics Name | Type | Dimensions | Description |
76+
| Metrics name | Type | Dimensions | Description |
7877
|--------------------------------------|-----------|-------------------------------------------|---------------------------------------------------------------------------------|
7978
| token_consumption | counter | - flow <br> - node<br> - llm_engine<br> - token_type: `prompt_tokens`: LLM API input tokens; `completion_tokens`: LLM API response tokens; `total_tokens` = `prompt_tokens + completion tokens` | OpenAI token consumption metrics |
8079
| flow_latency | histogram | flow, response_code, streaming, response_type | request execution cost, response_type means whether it's full/firstbyte/lastbyte|
@@ -85,17 +84,16 @@ The **Dependency** type events record calls from your deployments. The name of t
8584
| rpc_request | counter | flow, node, api_call, exception | rpc count |
8685
| flow_streaming_response_duration | histogram | flow | streaming response sending cost, from sending first byte to sending last byte |
8786

88-
You can find the workspace default Application Insights in your workspace overview page in Azure portal.
89-
90-
1. Open the Application Insights, and select **Usage and estimated costs** from the left navigation. Select **Custom metrics (Preview)**, and select **With dimensions**, and save the change.
91-
1. Select **Metrics** tab in the left navigation. Select **promptflow standard metrics** from the **Metric Namespace**, and you can explore the metrics from the **Metric** dropdown list with different aggregation methods.
87+
You can find the workspace default Application Insights metrics on your workspace overview page in the Azure portal.
9288

89+
1. Open Application Insights and select **Usage and estimated costs** on the left pane. Select **Custom metrics (Preview)** > **With dimensions**, and save the change.
90+
1. Select the **Metrics** tab on the left pane. From **Metric Namespace**, select **promptflow standard metrics**. You can explore the metrics from the **Metric** dropdown list with different aggregation methods.
9391

9492
## Collect feedback and send to Application Insights
9593

96-
Prompt flow serving provides a new `/feedback` API to help customer collect the feedback, the feedback payload can be any json format data, PF serving just helps customer save the feedback data to a trace span. Data will be saved to the trace exporter target customer configured. It also supports OpenTelemetry standard trace context propagation, saying it will respect the trace context set in the request header and use that as the request parent span context. You can leverage the distributed tracing functionality to correlate the feedback trace to its chat request trace.
94+
Prompt flow serving provides a new `/feedback` API to help customers collect the feedback. The feedback payload can be any JSON format data. Prompt flow serving helps the customer save the feedback data to a trace span. Data is saved to the trace exporter target that the customer configured. Prompt flow serving also supports OpenTelemetry standard trace context propagation. It respects the trace context set in the request header and uses that context as the request parent span context. You can use the distributed tracing functionality to correlate the feedback trace to its chat request trace.
9795

98-
Following is sample code showing how to score a flow deployed managed endpoint enabled tracing and send the feedback to the same trace span of scoring request. The flow has inputs `question` and `chat_history`, and output `answer`. After scoring the endpoint, we collect a feedback and send to Application Insights specified when deploying the flow.
96+
The following sample code shows how to score a flow deployed to a managed endpoint that was enabled for tracing and send the feedback to the same trace span of a scoring request. The flow has the inputs `question` and `chat_history`. The output is `answer`. After the endpoint is scored, feedback is collected and sent to application insights that are specified when you deploy the flow.
9997

10098
```python
10199
import urllib.request
@@ -107,12 +105,12 @@ from opentelemetry.baggage.propagation import W3CBaggagePropagator
107105
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
108106
from opentelemetry.sdk.trace import TracerProvider
109107
110-
# Initialize your tracer
108+
# Initialize your tracer.
111109
tracer = trace.get_tracer("my.genai.tracer")
112110
trace.set_tracer_provider(TracerProvider())
113111
114-
# Request data goes here
115-
# The example below assumes JSON formatting which may be updated
112+
# Request data goes here.
113+
# The example below assumes JSON formatting, which might be updated
116114
# depending on the format your endpoint expects.
117115
data = {
118116
"question": "hello",
@@ -123,13 +121,13 @@ body = str.encode(json.dumps(data))
123121
124122
url = 'https://basic-chat-endpoint-0506.eastus.inference.ml.azure.com/score'
125123
feedback_url = 'https://basic-chat-endpoint-0506.eastus.inference.ml.azure.com/feedback'
126-
# Replace this with the primary/secondary key, AMLToken, or Microsoft Entra ID token for the endpoint
124+
# Replace this with the primary/secondary key, AMLToken, or Microsoft Entra ID token for the endpoint.
127125
api_key = ''
128126
if not api_key:
129127
raise Exception("A key should be provided to invoke the endpoint")
130128
131129
# The azureml-model-deployment header will force the request to go to a specific deployment.
132-
# Remove this header to have the request observe the endpoint traffic rules
130+
# Remove this header to have the request observe the endpoint traffic rules.
133131
headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ api_key), 'azureml-model-deployment': 'basic-chat-deployment' }
134132
135133
try:
@@ -145,10 +143,10 @@ try:
145143
result = response.read()
146144
print(result)
147145
148-
# Now you can process the answer and collect feedback
149-
feedback = "thumbdown" # Example feedback (modify as needed)
146+
# Now you can process the answer and collect feedback.
147+
feedback = "thumbdown" # Example feedback (modify as needed).
150148
151-
# Make another request to save the feedback
149+
# Make another request to save the feedback.
152150
feedback_body = str.encode(json.dumps(feedback))
153151
feedback_req = urllib.request.Request(feedback_url, feedback_body, headers)
154152
urllib.request.urlopen(feedback_req)
@@ -157,19 +155,19 @@ try:
157155
except urllib.error.HTTPError as error:
158156
print("The request failed with status code: " + str(error.code))
159157
160-
# Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
158+
# Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure.
161159
print(error.info())
162160
print(error.read().decode("utf8", 'ignore'))
163161
164162
```
165163

166164
You can view the trace of the request along with feedback in Application Insights.
167165

168-
## Advanced usage: export trace to custom OpenTelemetry collector service
166+
## Advanced usage: Export trace to custom OpenTelemetry collector service
169167

170-
In some cases, you might want to export the trace data to your deployed OTel collector service, enabled by setting "OTEL_EXPORTER_OTLP_ENDPOINT". Use this exporter when you want to customize your own span processing logic and your own trace persistent target.
168+
In some cases, you might want to export the trace data to your deployed OpenTelemetry collector service. To enable this service, set `OTEL_EXPORTER_OTLP_ENDPOINT`. Use this exporter when you want to customize your own span processing logic and your own trace persistent target.
171169

172170
## Related content
173171

174-
- [Get started building a chat app using the prompt flow SDK](../../quickstarts/get-started-code.md)
175-
- [Work with projects in VS Code](vscode.md)
172+
- [Get started building a chat app by using the prompt flow SDK](../../quickstarts/get-started-code.md)
173+
- [Work with projects in Visual Studio Code](vscode.md)

0 commit comments

Comments
 (0)