You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
21
21
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.
23
23
24
24
> [!NOTE]
25
25
> For an improved way to perform continuous monitoring of deployed applications (other than prompt flow), consider using [Azure AI online evaluation](../online-evaluation.md).
26
26
27
27
## Prerequisites
28
28
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.
30
30
- 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).
33
33
34
34
## Deploy a flow for real-time inference
35
35
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).
37
37
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).
39
39
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.
42
41
43
42
## Enable trace and collect system metrics for your deployment
44
43
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.
46
45
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.
48
47
49
48
```yaml
50
49
app_insights_enabled: true
51
50
```
52
51
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.
> 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.
62
61
>
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.
64
63
>
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.
66
65
67
66
## View tracing data in Application Insights
68
67
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/).
70
69
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.
72
71
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).
74
73
75
74
## View system metrics in Application Insights
76
75
77
-
| Metrics Name | Type | Dimensions | Description |
76
+
| Metrics name | Type | Dimensions | Description |
| flow_streaming_response_duration | histogram | flow | streaming response sending cost, from sending first byte to sending last byte |
87
86
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.
92
88
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.
93
91
94
92
## Collect feedback and send to Application Insights
95
93
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.
97
95
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.
99
97
100
98
```python
101
99
import urllib.request
@@ -107,12 +105,12 @@ from opentelemetry.baggage.propagation import W3CBaggagePropagator
107
105
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
108
106
from opentelemetry.sdk.trace import TracerProvider
109
107
110
-
# Initialize your tracer
108
+
# Initialize your tracer.
111
109
tracer = trace.get_tracer("my.genai.tracer")
112
110
trace.set_tracer_provider(TracerProvider())
113
111
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
116
114
# depending on the format your endpoint expects.
117
115
data = {
118
116
"question": "hello",
@@ -123,13 +121,13 @@ body = str.encode(json.dumps(data))
print("The request failed with status code: " + str(error.code))
159
157
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.
161
159
print(error.info())
162
160
print(error.read().decode("utf8", 'ignore'))
163
161
164
162
```
165
163
166
164
You can view the trace of the request along with feedback in Application Insights.
167
165
168
-
## Advanced usage: export trace to custom OpenTelemetry collector service
166
+
## Advanced usage: Export trace to custom OpenTelemetry collector service
169
167
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.
171
169
172
170
## Related content
173
171
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