Skip to content

Commit 0d8f634

Browse files
Merge pull request #311007 from TimShererWithAquent/us543933-01
Freshness Edit: Azure API Management: Tutorial: Debug your APIs using request tracing
2 parents e5325b3 + 37d51f3 commit 0d8f634

4 files changed

Lines changed: 85 additions & 88 deletions

File tree

articles/api-management/api-management-howto-api-inspector.md

Lines changed: 81 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
---
2-
title: Tutorial - Debug APIs in Azure API Management using request tracing
2+
title: "Tutorial: Debug APIs in Azure API Management using request tracing"
33
description: Follow the steps of this tutorial to enable tracing and inspect request processing steps in Azure API Management.
44
services: api-management
55
author: dlepow
66
ms.service: azure-api-management
77
ms.topic: tutorial
8-
ms.date: 11/04/2024
8+
ms.date: 01/28/2026
99
ms.author: danlep
1010
ms.custom:
1111
- devdivchpfy22
1212
- sfi-image-nochange
13+
#customer intent: As a developer who works with Azure API Management, I need to understand request tracing in order to troubleshoot APIs.
1314
---
1415

1516
# Tutorial: Debug your APIs using request tracing
1617

1718
[!INCLUDE [api-management-availability-all-tiers](../../includes/api-management-availability-all-tiers.md)]
1819

19-
This tutorial describes how to inspect (trace) request processing in Azure API Management. Tracing helps you debug and troubleshoot your API.
20+
This tutorial describes how to inspect, or *trace*, request processing in Azure API Management. Tracing helps you debug and troubleshoot your API.
2021

2122
[!INCLUDE [api-management-workspace-try-it](../../includes/api-management-workspace-try-it.md)]
2223

2324
In this tutorial, you learn how to:
2425

2526
> [!div class="checklist"]
26-
> * Trace an example call in the test console
27-
> * Review request processing steps
28-
> * Enable tracing for an API
27+
> - Trace an example call in the test console
28+
> - Review request processing steps
29+
> - Enable tracing for an API
2930
3031
:::image type="content" source="media/api-management-howto-api-inspector/api-inspector-002.png" alt-text="Screenshot showing the API inspector." lightbox="media/api-management-howto-api-inspector/api-inspector-002.png":::
3132

3233
## Prerequisites
3334

34-
+ Learn the [Azure API Management terminology](api-management-terminology.md).
35-
+ Complete the following quickstart: [Create an Azure API Management instance](get-started-create-service-instance.md).
36-
+ Complete the following tutorial: [Import and publish your first API](import-and-publish.md).
37-
35+
- Learn the [Azure API Management terminology](api-management-terminology.md).
36+
- Complete the following quickstart: [Create an Azure API Management instance](get-started-create-service-instance.md).
37+
- Complete the following tutorial: [Import and publish your first API](import-and-publish.md).
3838

3939
[!INCLUDE [api-management-tracing-alert](../../includes/api-management-tracing-alert.md)]
4040

41-
## Trace a call in the portal
41+
## Trace a call in the Azure portal
4242

4343
Follow these steps to trace an API request in the test console in the portal. This example assumes that you [imported](import-and-publish.md) a sample API in a previous tutorial. You can follow similar steps with a different API that you imported.
4444

@@ -49,30 +49,28 @@ Follow these steps to trace an API request in the test console in the portal. Th
4949
1. Select the **Find pet by ID** operation.
5050
1. In the *petId* **Query parameter**, enter *1*.
5151
1. Optionally check the value for the **Ocp-Apim-Subscription-Key** header used in the request by selecting the "eye" icon.
52-
> [!TIP]
53-
> You can override the value of **Ocp-Apim-Subscription-Key** by retrieving a key for another subscription in the portal. Select **Subscriptions**, and open the context menu (**...**) for another subscription. Select **Show/hide keys** and copy one of the keys. You can also regenerate keys if needed. Then, in the test console, select **+ Add header** to add an **Ocp-Apim-Subscription-Key** header with the new key value.
5452

55-
1. Select **Trace**.
53+
> [!TIP]
54+
>
55+
> You can override the value of **Ocp-Apim-Subscription-Key** by retrieving a key for another subscription in the Azure portal. Select **Subscriptions**, and open the context menu (**...**) for another subscription. Select **Show/hide keys** and copy one of the keys. You can also regenerate keys if needed. Then, in the test console, select **+ Add header** to add an **Ocp-Apim-Subscription-Key** header with the new key value.
5656
57+
1. Select **Trace**.
5758

5859
## Review trace information
5960

6061
1. After the call completes, go to the **Trace** tab in the **HTTP response**.
61-
1. Select any of the following links to jump to detailed trace info: **Inbound**, **Backend**, **Outbound**, **On error**.
62-
63-
:::image type="content" source="media/api-management-howto-api-inspector/response-trace-1.png" alt-text="Review response trace":::
64-
65-
* **Inbound** - Shows the original request API Management received from the caller and the policies applied to the request. For example, if you added policies in [Tutorial: Transform and protect your API](transform-api.md), they appear here.
66-
67-
* **Backend** - Shows the requests API Management sent to the API backend and the response it received.
62+
1. Select any of the following links to jump to detailed trace information: **Inbound**, **Backend**, **Outbound**, **On error**.
6863

69-
* **Outbound** - Shows the policies applied to the response before sending back to the caller.
64+
:::image type="content" source="media/api-management-howto-api-inspector/response-trace-1.png" alt-text="Screenshot showing the review response trace.":::
7065

71-
* **On error** - Shows the errors that occurred during the processing of the request and the policies applied to the errors.
72-
73-
> [!TIP]
74-
> Each step also shows the elapsed time since the request is received by API Management.
66+
- **Inbound**. Shows the original request API Management received from the caller and the policies applied to the request. For example, if you added policies in [Tutorial: Transform and protect your API](transform-api.md), they appear here.
67+
- **Backend**. Shows the requests API Management sent to the API backend and the response it received.
68+
- **Outbound**. Shows the policies applied to the response before sending back to the caller.
69+
- **On error**. Shows the errors that occurred during the processing of the request and the policies applied to the errors.
7570

71+
> [!TIP]
72+
>
73+
> Each step also shows the elapsed time since API Management receives the request.
7674
7775
## Enable tracing for an API
7876

@@ -86,79 +84,76 @@ The following high level steps are required to enable tracing for a request to A
8684
Detailed steps follow.
8785

8886
> [!NOTE]
89-
> * These steps require API Management REST API version 2023-05-01-preview or later. You must be assigned the Contributor or higher role on the API Management instance to call the REST API.
90-
> * For information about authenticating to the REST API, see [Azure REST API reference](/rest/api/azure).
87+
>
88+
> - These steps require API Management REST API version 2023-05-01-preview or later. You must be assigned the Contributor or higher role on the API Management instance to call the REST API.
89+
> - For information about authenticating to the REST API, see [Azure REST API reference](/rest/api/azure).
9190
92-
1. **Obtain a debug token** - Call the API Management gateway's [List debug credentials](/rest/api/apimanagement/gateway/list-debug-credentials) API. In the URI, enter "managed" for the instance's managed gateway in the cloud, or the gateway ID for a self-hosted gateway. For example, to obtain trace credentials for the instance's managed gateway, use a request similar to the following:
91+
1. **Obtain a debug token**. Call the API Management gateway's [List debug credentials](/rest/api/apimanagement/gateway/list-debug-credentials) API. In the URI, enter *managed* for the instance's managed gateway in the cloud, or the gateway ID for a self-hosted gateway. For example, to obtain trace credentials for the instance's managed gateway, use a request similar to the following example:
9392

94-
```http
95-
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/managed/listDebugCredentials?api-version=2023-05-01-preview
96-
```
93+
```http
94+
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/managed/listDebugCredentials?api-version=2023-05-01-preview
95+
```
9796

98-
In the request body, pass the full resource ID of the API that you want to trace, and specify `purposes` as `tracing`. By default the token credential returned in the response expires after 1 hour, but you can specify a different value in the payload. Note that the expiry time is limited to a maximum of 1 hour. For example:
99-
100-
```json
101-
{
102-
"credentialsExpireAfter": "PT1H",
103-
"apiId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}",
104-
"purposes": ["tracing"]
105-
}
106-
```
97+
In the request body, pass the full resource ID of the API that you want to trace. Specify `purposes` as `tracing`. By default, the token credential returned in the response expires after 1 hour. You can specify a different value in the payload. The expiry time is limited to a maximum of 1 hour. For example:
10798

108-
> [!NOTE]
109-
> The `apiId` can only be pulled from the full resource ID, not the name displayed in the portal.
99+
```json
100+
{
101+
"credentialsExpireAfter": "PT1H",
102+
"apiId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}",
103+
"purposes": ["tracing"]
104+
}
105+
```
110106

111-
Get apiId:
107+
> [!NOTE]
108+
> The `apiId` can only be pulled from the full resource ID, not the name displayed in the Azure portal.
112109
110+
Get apiId:
113111

114-
```azurecli
115-
az apim api list --resource-group <resource-group> --service-name <service-name> -o table
116-
```
112+
```azurecli
113+
az apim api list --resource-group <resource-group> --service-name <service-name> -o table
114+
```
117115
118-
The debug credential is returned in the response, similar to the following:
116+
The debug credential is returned in the response, similar to the following example:
119117

120-
```json
121-
{
122-
"token": "aid=api-name&......."
123-
}
124-
```
118+
```json
119+
{
120+
"token": "aid=api-name&......."
121+
}
122+
```
125123

126-
1. **Add the token value in a request header** - To enable tracing for a request to the API Management gateway, send the token value in an `Apim-Debug-Authorization` header. For example, to trace a call to the Petstore API that you imported in a previous tutorial, you might use a request similar to the following:
124+
1. **Add the token value in a request header**. To enable tracing for a request to the API Management gateway, send the token value in an `Apim-Debug-Authorization` header. For example, to trace a call to the Petstore API that you imported in a previous tutorial, you might use a request similar to the following example:
127125

128-
```bash
129-
curl -v https://apim-hello-world.azure-api.net/pet/1 HTTP/1.1 \
130-
-H "Ocp-Apim-Subscription-Key: <subscription-key>" \
131-
-H "Apim-Debug-Authorization: aid=api-name&......."
132-
```
126+
```bash
127+
curl -v https://apim-hello-world.azure-api.net/pet/1 HTTP/1.1 \
128+
-H "Ocp-Apim-Subscription-Key: <subscription-key>" \
129+
-H "Apim-Debug-Authorization: aid=api-name&......."
130+
```
133131

134-
1. **Evaluate the response** - The response can contain one of the following headers depending on the state of the debug token:
135-
* If the debug token is valid, the response includes an `Apim-Trace-Id` header whose value is the trace ID, similar to the following:
132+
1. **Evaluate the response**. The response can contain one of the following headers depending on the state of the debug token:
136133

137-
```http
138-
Apim-Trace-Id: 0123456789abcdef....
139-
```
140-
141-
* If the debug token is expired, the response includes an `Apim-Debug-Authorization-Expired` header with information about expiration date.
142-
* If the debug token was obtained for a different API, the response includes an `Apim-Debug-Authorization-WrongAPI` header with an error message.
134+
| Header in response | Explanation |
135+
|:-------------------|:------------|
136+
| `Apim-Trace-Id` | Debug token valid. The value is the trace ID, such as: `Apim-Trace-Id: 0123456789abcdef....` |
137+
| `Apim-Debug-Authorization-Expired` | Token is expired. Header includes information about expiration date. |
138+
| `Apim-Debug-Authorization-WrongAPI` | Token obtained for a different API. Header includes an error message. |
143139

144-
1. **Retrieve the trace** - Pass the trace ID obtained in the previous step to the gateway's [List trace](/rest/api/apimanagement/gateway/list-trace) API. For example, to retrieve the trace for the managed gateway, use a request similar to the following:
140+
1. **Retrieve the trace**. Pass the trace ID obtained in the previous step to the gateway's [List trace](/rest/api/apimanagement/gateway/list-trace) API. For example, to retrieve the trace for the managed gateway, use a request similar to the following example:
145141

146-
```http
147-
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/managed/listTrace?api-version=2023-05-01-preview
148-
```
142+
```http
143+
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/managed/listTrace?api-version=2023-05-01-preview
144+
```
149145

150-
In the request body, pass the trace ID obtained in the previous step.
146+
In the request body, pass the trace ID obtained in the previous step.
151147

152-
```json
153-
{
154-
"traceId": "0123456789abcdef...."
155-
}
156-
```
148+
```json
149+
{
150+
"traceId": "0123456789abcdef...."
151+
}
152+
```
157153

158-
The response body contains the trace data for the previous API request to the gateway. The trace is similar to the trace you can see by tracing a call in the portal's test console.
154+
The response body contains the trace data for the previous API request to the gateway. The trace is similar to the trace you can see by tracing a call in the portal's test console.
159155

160-
161-
### Example `.http` file for VS Code REST Client extension
156+
### Example http file for VS Code REST Client extension
162157

163158
To help automate these steps with the [Visual Studio Code REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension, you can use the following example `.http` file:
164159

@@ -224,14 +219,16 @@ Content-Type: application/json
224219

225220
For information about customizing trace information, see the [trace](trace-policy.md) policy.
226221

227-
## Next steps
222+
## Summary
228223

229224
In this tutorial, you learned how to:
230225

231226
> [!div class="checklist"]
232-
> * Trace an example call in the test console
233-
> * Review request processing steps
234-
> * Enable tracing for an API
227+
> - Trace an example call in the test console
228+
> - Review request processing steps
229+
> - Enable tracing for an API
230+
231+
## Next step
235232

236233
Advance to the next tutorial:
237234

-73.1 KB
Loading
-27.4 KB
Loading

includes/api-management-tracing-alert.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
author: dlepow
33
ms.service: azure-api-management
44
ms.topic: include
5-
ms.date: 11/04/2024
5+
ms.date: 01/28/2026
66
ms.author: danlep
77
---
88
> [!IMPORTANT]
9-
> * API Management no longer supports subscriptions for tracing or the **Ocp-Apim-Trace** header.
10-
> * To improve API security, tracing can now be enabled at the level of an individual API by obtaining a time-limited token using the API Management REST API, and passing the token in a request to the gateway. For details, see [Enable tracing of an API](../articles/api-management/api-management-howto-api-inspector.md#enable-tracing-for-an-api).
11-
> * Take care when enabling tracing, as it can expose sensitive information in the trace data. Ensure that you have appropriate security measures in place to protect the trace data.
9+
> - API Management no longer supports subscriptions for tracing or the **Ocp-Apim-Trace** header.
10+
> - To improve API security, tracing can now be enabled at the level of an individual API. Obtain a time-limited token using the API Management REST API, and pass the token in a request to the gateway. For details, see [Enable tracing of an API](../articles/api-management/api-management-howto-api-inspector.md#enable-tracing-for-an-api).
11+
> - Take care when enabling tracing. It can expose sensitive information in the trace data. Ensure that you have appropriate security measures in place to protect the trace data.

0 commit comments

Comments
 (0)