Skip to content

Commit fee65dc

Browse files
Freshness, in progress.
1 parent beacb78 commit fee65dc

3 files changed

Lines changed: 78 additions & 80 deletions

File tree

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

Lines changed: 78 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
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
@@ -23,18 +24,17 @@ This tutorial describes how to inspect (trace) request processing in Azure API M
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

@@ -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 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

60-
1. After the call completes, go to the **Trace** tab in the **HTTP response**.
61+
1. After the call completes, go to the **Trace*- tab in the **HTTP response**.
6162
1. Select any of the following links to jump to detailed trace info: **Inbound**, **Backend**, **Outbound**, **On error**.
6263

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.
64+
:::image type="content" source="media/api-management-howto-api-inspector/response-trace-1.png" alt-text="Screenshot showing the review response trace.":::
6865

69-
* **Outbound** - Shows the policies applied to the response before sending back to the caller.
70-
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,77 +84,77 @@ 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, 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. 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 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-
```
134+
- If the debug token is valid, the response includes an `Apim-Trace-Id` header whose value is the trace ID, similar to the following example:
135+
136+
```http
137+
Apim-Trace-Id: 0123456789abcdef....
138+
```
140139
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.
140+
- If the debug token is expired, the response includes an `Apim-Debug-Authorization-Expired` header with information about expiration date.
141+
- If the debug token was obtained for a different API, the response includes an `Apim-Debug-Authorization-WrongAPI` header with an error message.
143142
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:
143+
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:
145144
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-
```
145+
```http
146+
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/managed/listTrace?api-version=2023-05-01-preview
147+
```
149148

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

152-
```json
153-
{
154-
"traceId": "0123456789abcdef...."
155-
}
156-
```
151+
```json
152+
{
153+
"traceId": "0123456789abcdef...."
154+
}
155+
```
157156

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.
159-
157+
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.
160158

161159
### Example `.http` file for VS Code REST Client extension
162160

@@ -224,14 +222,14 @@ Content-Type: application/json
224222

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

227-
## Next steps
225+
## Next step
228226

229227
In this tutorial, you learned how to:
230228

231229
> [!div class="checklist"]
232-
> * Trace an example call in the test console
233-
> * Review request processing steps
234-
> * Enable tracing for an API
230+
> - Trace an example call in the test console
231+
> - Review request processing steps
232+
> - Enable tracing for an API
235233
236234
Advance to the next tutorial:
237235

-72.8 KB
Loading
-27.4 KB
Loading

0 commit comments

Comments
 (0)