Skip to content

Commit 932e7df

Browse files
author
Miao Jiang
committed
Changes related to the new trace policy
1 parent 22bcd57 commit 932e7df

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

articles/api-management/api-management-advanced-policies.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This topic provides a reference for the following API Management policies. For i
3434
- [Set request method](#SetRequestMethod) - Allows you to change the HTTP method for a request.
3535
- [Set status code](#SetStatus) - Changes the HTTP status code to the specified value.
3636
- [Set variable](api-management-advanced-policies.md#set-variable) - Persists a value in a named [context](api-management-policy-expressions.md#ContextVariables) variable for later access.
37-
- [Trace](#Trace) - Adds a string into the [API Inspector](https://azure.microsoft.com/documentation/articles/api-management-howto-api-inspector/) output.
37+
- [Trace](#Trace) - Adds custom traces into the [API Inspector](https://azure.microsoft.com/documentation/articles/api-management-howto-api-inspector/) output, Application Insights telemetries, and Diagnostic Logs.
3838
- [Wait](#Wait) - Waits for enclosed [Send request](api-management-advanced-policies.md#SendRequest), [Get value from cache](api-management-caching-policies.md#GetFromCacheByKey), or [Control flow](api-management-advanced-policies.md#choose) policies to complete before proceeding.
3939

4040
## <a name="choose"></a> Control flow
@@ -909,29 +909,49 @@ Expressions used in the `set-variable` policy must return one of the following b
909909

910910
## <a name="Trace"></a> Trace
911911

912-
The `trace` policy adds a string into the [API Inspector](https://azure.microsoft.com/documentation/articles/api-management-howto-api-inspector/) output. The policy will execute only when tracing is triggered, i.e. `Ocp-Apim-Trace` request header is present and set to `true` and `Ocp-Apim-Subscription-Key` request header is present and holds a valid key associated with the admin account.
912+
The `trace` policy adds a custom trace into the API Inspector output, Application Insights telemetries, and/or Diagnostic Logs.
913+
914+
* The policy adds a custom trace to the [API Inspector](https://azure.microsoft.com/documentation/articles/api-management-howto-api-inspector/) output when tracing is triggered, i.e. `Ocp-Apim-Trace` request header is present and set to true and `Ocp-Apim-Subscription-Key` request header is present and holds a valid key that allows tracing.
915+
* The policy creates a [Trace](https://docs.microsoft.com/azure/azure-monitor/app/data-model-trace-telemetry) telemetry in Application Insights, when [Application Insights integration](https://docs.microsoft.com/azure/api-management/api-management-howto-app-insights) is enabled and the `severity` level specified in the policy is at or higher than the `verbosity` level specified in the diagnostic setting.
916+
* The policy adds a property in the log entry when [Diagnostic Logs](https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-use-azure-monitor#diagnostic-logs) is enabled and the severity level specified in the policy is at or higher than the verbosity level specified in the diagnostic setting.
917+
913918

914919
### Policy statement
915920

916921
```xml
917922

918-
<trace source="arbitrary string literal">
919-
<!-- string expression or literal -->
923+
<trace source="arbitrary string literal" severity="verbose|information|error">
924+
<message>String literal or expressions</message>
925+
<metadata name="string literal or expressions" value="string literal or expressions"/>
920926
</trace>
921927

922928
```
923929

930+
### <a name="traceExample"></a> Example
931+
932+
```xml
933+
<trace source="PetStore API" severity="verbose">
934+
<message>@((string)context.Variables["clientConnectionID"])</message>
935+
<metadata name="Operation Name" value="New-Order"/>
936+
</trace>
937+
```
938+
924939
### Elements
925940

926941
| Element | Description | Required |
927942
| ------- | ------------- | -------- |
928943
| trace | Root element. | Yes |
944+
| message | A string or expression to be logged. | Yes |
945+
| metadata | Adds a custom property to the Application Insights [Trace](https://docs.microsoft.com/en-us/azure/azure-monitor/app/data-model-trace-telemetry) telemetry. | No |
929946

930947
### Attributes
931948

932949
| Attribute | Description | Required | Default |
933950
| --------- | --------------------------------------------------------------------------------------- | -------- | ------- |
934951
| source | String literal meaningful to the trace viewer and specifying the source of the message. | Yes | N/A |
952+
| severity | Specifies the severity level of the trace. Allowed values are `verbose`, `information`, `error` (from lowest to highest). | No | Verbose |
953+
| name | Name of the property. | Yes | N/A |
954+
| value | Value of the property. | Yes | N/A |
935955

936956
### Usage
937957

articles/api-management/api-management-howto-app-insights.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ Before you can use Azure Application Insights, you first need to create an insta
7575
| Sampling (%) | decimal | Values from 0 to 100 (percent). <br/> Specifies what percentage of requests will be logged to Azure Application Insights. 0% sampling means zero requests logged, while 100% sampling means all requests logged. <br/> This setting is used for reducing performance implications of logging requests to Azure Application Insights (see the section below). |
7676
| Always log errors | boolean | If this setting is selected, all failures will be logged to Azure Application Insights, regardless of the **Sampling** setting. |
7777
| Basic Options: Headers | list | Specifies the headers that will be logged to Azure Application Insights for requests and responses. Default: no headers are logged. |
78-
| Basic Options: First bytes of body | integer | Specifies how many first bytes of the body are logged to Azure Application Insights for requests and responses. Default: body is not logged. |
78+
| Basic Options: First bytes of body | integer | Specifies how many first bytes of the body are logged to Azure Application Insights for requests and responses. Default: body is not logged. |
79+
| Advanced Options: Verbosity | | Specifies the verbosity level. Only custom traces with higher severity level will be logged. Default: Information. |
7980
| Advanced Options: Frontend Request | | Specifies whether and how *frontend requests* will be logged to Azure Application Insights. *Frontend request* is a request incoming to the Azure API Management service. |
8081
| Advanced Options: Frontend Response | | Specifies whether and how *frontend responses* will be logged to Azure Application Insights. *Frontend response* is a response outgoing from the Azure API Management service. |
8182
| Advanced Options: Backend Request | | Specifies whether and how *backend requests* will be logged to Azure Application Insights. *Backend request* is a request outgoing from the Azure API Management service. |

articles/api-management/api-management-policies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ This section provides a reference for the following API Management policies. For
4545
- [Set variable](api-management-advanced-policies.md#set-variable) - Persist a value in a named context variable for later access.
4646
- [Set request method](api-management-advanced-policies.md#SetRequestMethod) - Allows you to change the HTTP method for a request.
4747
- [Set status code](api-management-advanced-policies.md#SetStatus) - Changes the HTTP status code to the specified value.
48-
- [Trace](api-management-advanced-policies.md#Trace) - Adds a string into the [API Inspector](https://azure.microsoft.com/documentation/articles/api-management-howto-api-inspector/) output.
48+
- [Trace](api-management-advanced-policies.md#Trace) - Adds custom traces into the [API Inspector](https://azure.microsoft.com/documentation/articles/api-management-howto-api-inspector/) output, Application Insights telemetries, and Diagnostic Logs.
4949
- [Wait](api-management-advanced-policies.md#Wait) - Waits for enclosed [Send request](api-management-advanced-policies.md#SendRequest), [Get value from cache](api-management-caching-policies.md#GetFromCacheByKey), or [Control flow](api-management-advanced-policies.md#choose) policies to complete before proceeding.
5050
- [Authentication policies](api-management-authentication-policies.md#AuthenticationPolicies)
5151
- [Authenticate with Basic](api-management-authentication-policies.md#Basic) - Authenticate with a backend service using Basic authentication.

0 commit comments

Comments
 (0)