| title | Azure API Management policy reference - trace | Microsoft Docs |
|---|---|
| description | Reference for the trace policy available for use in Azure API Management. Provides policy usage, settings, and examples. |
| services | api-management |
| author | dlepow |
| ms.service | azure-api-management |
| ms.topic | reference |
| ms.date | 07/23/2024 |
| ms.author | danlep |
[!INCLUDE api-management-availability-all-tiers]
The trace policy adds a custom trace into the request tracing output in the test console, Application Insights telemetries, and/or resource logs.
- The policy adds a custom trace to the request tracing output in the test console when tracing is triggered.
- The policy creates a Trace telemetry in Application Insights, when Application Insights integration is enabled and the
severityspecified in the policy is equal to or greater than theverbosityspecified in the diagnostic setting. - The policy adds a property in the log entry when resource logs are enabled and the severity level specified in the policy is at or higher than the verbosity level specified in the diagnostic setting.
- The policy is not affected by Application Insights sampling. All invocations of the policy will be logged.
[!INCLUDE api-management-tracing-alert]
[!INCLUDE api-management-policy-generic-alert]
<trace source="arbitrary string literal" severity="verbose | information | error">
<message>String literal or expressions</message>
<metadata name="string literal or expressions" value="string literal or expressions"/>
</trace>| Attribute | Description | Required | Default |
|---|---|---|---|
| source | String literal meaningful to the trace viewer and specifying the source of the message. Policy expressions aren't allowed. | Yes | N/A |
| severity | Specifies the severity level of the trace. Allowed values are verbose, information, error (from lowest to highest). Policy expressions aren't allowed. |
No | verbose |
| Name | Description | Required |
|---|---|---|
| message | A string or expression to be logged. Policy expressions are allowed. | Yes |
| metadata | Adds a custom property to the Application Insights Trace telemetry. | No |
| Attribute | Description | Required | Default |
|---|---|---|---|
| name | Name of the property. | Yes | N/A |
| value | Value of the property. | Yes | N/A |
- Policy sections: inbound, outbound, backend
- Policy scopes: global, workspace, product, API, operation
- Gateways: classic, v2, consumption, self-hosted, workspace
<trace source="PetStore API" severity="verbose">
<message>@((string)context.Variables["clientConnectionID"])</message>
<metadata name="Operation Name" value="New-Order"/>
</trace>[!INCLUDE api-management-policy-ref-next-steps]