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
Copy file name to clipboardExpand all lines: articles/api-management/api-management-debug-policies.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ This article describes how to debug API Management policies using the [Azure API
26
26
27
27
## Restrictions and limitations
28
28
29
-
* This feature uses the built-in (service-level) all-access subscription (display name "Built-in all-access subscription") for debugging. The [**Allow tracing**](api-management-howto-api-inspector.md#verify-allow-tracing-setting) setting must be enabled in this subscription.
29
+
* This feature uses the built-in (service-level) all-access subscription (display name "Built-in all-access subscription") for debugging.
Copy file name to clipboardExpand all lines: articles/api-management/api-management-howto-api-inspector.md
+60-22Lines changed: 60 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ services: api-management
5
5
author: dlepow
6
6
ms.service: api-management
7
7
ms.topic: tutorial
8
-
ms.date: 03/26/2024
8
+
ms.date: 05/05/2024
9
9
ms.author: danlep
10
10
ms.custom: devdivchpfy22
11
11
---
@@ -19,8 +19,9 @@ This tutorial describes how to inspect (trace) request processing in Azure API M
19
19
In this tutorial, you learn how to:
20
20
21
21
> [!div class="checklist"]
22
-
> * Trace an example call
22
+
> * Trace an example call in the test console
23
23
> * Review request processing steps
24
+
> * Enable tracing for an API
24
25
25
26
:::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":::
26
27
@@ -32,18 +33,10 @@ In this tutorial, you learn how to:
32
33
+ Complete the following quickstart: [Create an Azure API Management instance](get-started-create-service-instance.md).
33
34
+ Complete the following tutorial: [Import and publish your first API](import-and-publish.md).
34
35
35
-
## Verify allow tracing setting
36
-
37
-
To trace request processing, you must enable the **Allow tracing** setting for the subscription used to debug your API. To check in the portal:
38
-
39
-
1. Navigate to your API Management instance and select **Subscriptions** to review the settings.
40
-
41
-
:::image type="content" source="media/api-management-howto-api-inspector/allow-tracing-1.png" alt-text="Screenshot showing how to allow tracing for subscription." lightbox="media/api-management-howto-api-inspector/allow-tracing-1.png":::
42
-
1. If tracing isn't enabled for the subscription you're using, select the subscription and enable **Allow tracing**.
1. Sign in to the [Azure portal](https://portal.azure.com), and navigate to your API Management instance.
49
42
1. Select **APIs**.
@@ -56,10 +49,6 @@ To trace request processing, you must enable the **Allow tracing** setting for t
56
49
57
50
1. Select **Trace**.
58
51
59
-
* If your subscription doesn't already allow tracing, you're prompted to enable it if you want to trace the call.
60
-
* You can also choose to send the request without tracing.
61
-
62
-
:::image type="content" source="media/api-management-howto-api-inspector/06-debug-your-apis-01-trace-call-1.png" alt-text="Screenshot showing configure API tracing." lightbox="media/api-management-howto-api-inspector/06-debug-your-apis-01-trace-call-1.png":::
63
52
64
53
## Review trace information
65
54
@@ -79,18 +68,66 @@ To trace request processing, you must enable the **Allow tracing** setting for t
79
68
> [!TIP]
80
69
> Each step also shows the elapsed time since the request is received by API Management.
81
70
82
-
1. On the **Message** tab, the **ocp-apim-trace-location** header shows the location of the trace data stored in Azure blob storage. If needed, go to this location to retrieve the trace. Trace data can be accessed for up to 24 hours.
83
71
84
-
:::image type="content" source="media/api-management-howto-api-inspector/response-message-1.png" alt-text="Trace location in Azure Storage":::
72
+
## Enable tracing for an API
73
+
74
+
You can enable tracing for an API when making requests to API Management using `curl`, a REST client such as Visual Studio Code with the REST Client extension, or a client app.
75
+
76
+
Enable tracing by the following steps using calls to the API Management REST API.
77
+
78
+
> [!NOTE]
79
+
> The following 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.
80
+
81
+
1. Obtain trace credentials by calling the [List debug credentials](/rest/api/apimanagement/gateway/list-debug-credentials) API. Pass the gateway ID in the URI, or use "managed" for the instance's managed gateway in the cloud. For example, to obtain trace credentials for the managed gateway, use a call similar to the following:
82
+
83
+
```http
84
+
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/managed/listDebugCredentials?api-version=2023-05-01-preview
85
+
```
86
+
87
+
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.
88
+
89
+
```json
90
+
{
91
+
"credentialsExpireAfter": PT1H,
92
+
"apiId": "<API resource ID>",
93
+
"purposes: ["tracing"]
94
+
}
95
+
```
96
+
97
+
The token credential is returned in the response, similar to the following:
98
+
99
+
```json
100
+
{
101
+
"token": "aid=api-name&p=tracing&ex=......."
102
+
}
103
+
```
104
+
105
+
1. 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 demo conference API, use a call similar to the following:
1. Depending on the token, the response contains different headers:
111
+
* If the token is valid, the response includes an `Apim-Trace-Id` header whose value is the trace ID.
112
+
* If the token is expired, the response includes an `Apim-Debug-Authorization-Expired` header with information about expiration date.
113
+
* If the token was obtained for wrong API, the response includes an `Apim-Debug-Authorization-WrongAPI` header with an error message.
114
+
115
+
1. To retrieve the trace, pass the trace ID obtained in the previous step to the [List trace](/rest/api/apimanagement/gateway/list-trace) API for the gateway. For example, to retrieve the trace for the managed gateway, use a call similar to the following:
85
116
86
-
## Enable tracing using Ocp-Apim-Trace header
117
+
```http
118
+
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/managed/listTrace?api-version=2023-05-01-preview
119
+
```
87
120
88
-
When making requests to API Management using `curl`, a REST client such as Postman, or a client app, enable tracing by adding the following request headers:
121
+
In the request body, pass the trace ID obtained in the previous step.
89
122
90
-
***Ocp-Apim-Trace** - set value to `true`
91
-
***Ocp-Apim-Subscription-Key** - set value to the key for a tracing-enabled subscription that allows access to the API
123
+
```json
124
+
{
125
+
"traceId": "<trace ID>"
126
+
}
127
+
```
128
+
129
+
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.
92
130
93
-
The response includes the **Ocp-Apim-Trace-Location** header, with a URL to the location of the trace data in Azure blob storage.
94
131
95
132
For information about customizing trace information, see the [trace](trace-policy.md) policy.
96
133
@@ -101,6 +138,7 @@ In this tutorial, you learned how to:
Copy file name to clipboardExpand all lines: articles/api-management/api-management-howto-create-subscriptions.md
+3-6Lines changed: 3 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,9 @@ When you publish APIs through Azure API Management, it's easy and common to secu
17
17
18
18
This article walks through the steps for creating subscriptions in the Azure portal.
19
19
20
+
> [!IMPORTANT]
21
+
> The **Allow tracing** setting in subscriptions to enable debug traces is deprecated. To improve security, tracing can now be enabled for specific API requests to API Management. [Learn more](api-management-howto-api-inspector.md#enable-tracing-for-an-api)
22
+
20
23
## Prerequisites
21
24
22
25
To take the steps in this article, the prerequisites are as follows:
@@ -31,12 +34,6 @@ To take the steps in this article, the prerequisites are as follows:
31
34
1. Navigate to your API Management instance in the [Azure portal](https://portal.azure.com).
32
35
1. In the left menu, under **APIs**, select **Subscriptions** > **Add subscription**.
33
36
1. Provide a **Name** and optional **Display name** of the subscription.
34
-
1. Optionally, select **Allow tracing** to enable tracing for debugging and troubleshooting APIs. [Learn more](api-management-howto-api-inspector.md)
Copy file name to clipboardExpand all lines: articles/api-management/trace-policy.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ ms.author: danlep
15
15
16
16
The `trace` policy adds a custom trace into the request tracing output in the test console, Application Insights telemetries, and/or resource logs.
17
17
18
-
- The policy adds a custom trace to the [request tracing](./api-management-howto-api-inspector.md) output in the test console when tracing is triggered, that is, `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.
18
+
- The policy adds a custom trace to the [request tracing](./api-management-howto-api-inspector.md) output in the test console when tracing is triggered.
19
19
- The policy creates a [Trace](../azure-monitor/app/data-model-complete.md#trace) telemetry in Application Insights, when [Application Insights integration](./api-management-howto-app-insights.md) is enabled and the `severity` specified in the policy is equal to or greater than the `verbosity` specified in the [diagnostic setting](./diagnostic-logs-reference.md).
20
20
- The policy adds a property in the log entry when [resource logs](./api-management-howto-use-azure-monitor.md#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](./diagnostic-logs-reference.md).
21
21
- The policy is not affected by Application Insights sampling. All invocations of the policy will be logged.
Copy file name to clipboardExpand all lines: articles/api-management/visual-studio-code-tutorial.md
+1-19Lines changed: 1 addition & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,7 +107,6 @@ You need a subscription key for your API Management instance to test the importe
107
107
1. In the Explorer pane, expand the **Operations** node under the *demo-conference-api* that you imported.
108
108
1. Select an operation such as *GetSpeakers*, and then right-click the operation and select **Test Operation**.
109
109
1. In the editor window, next to **Ocp-Apim-Subscription-Key**, replace `{{SubscriptionKey}}` with the subscription key that you copied.
110
-
1. Next to `Ocp-Apim-Trace`, enter `false`. This setting disables request tracing.
111
110
1. Select **Send request**.
112
111
113
112
:::image type="content" source="media/visual-studio-code-tutorial/test-api.png" alt-text="Screenshot of sending API request from Visual Studio Code.":::
@@ -126,24 +125,7 @@ Notice the following details in the response:
126
125
127
126
Optionally, you can get detailed request tracing information to help you debug and troubleshoot the API.
128
127
129
-
To trace request processing, first enable the **Allow tracing** setting for the subscription used to debug your API. For steps to enable this setting using the portal, see [Verify allow tracing setting](api-management-howto-api-inspector.md#verify-allow-tracing-setting). To limit unintended disclosure of sensitive information, tracing is allowed for only 1 hour.
130
-
131
-
After allowing tracing with your subscription, follow these steps:
132
-
133
-
1. In the Explorer pane, expand the **Operations** node under the *demo-conference-api* that you imported.
134
-
1. Select an operation such as *GetSpeakers*, and then right-click the operation and select **Test Operation**.
135
-
1. In the editor window, next to **Ocp-Apim-Subscription-Key**, replace `{{SubscriptionKey}}` with the subscription key that you want to use.
136
-
1. Next to `Ocp-Apim-Trace`, enter `true`. This setting enables tracing for this request.
137
-
1. Select **Send request**.
138
-
139
-
When the request succeeds, the backend response includes an **Ocp-APIM-Trace-Location** header.
140
-
141
-
:::image type="content" source="media/visual-studio-code-tutorial/test-api-tracing.png" alt-text="Screenshot of tracing location in the API test response in Visual Studio Code.":::
142
-
143
-
Select the link next to **Ocp-APIM-Trace-Location** to see Inbound, Backend, and Outbound trace information. The trace information helps you determine where problems occur after the request is made.
144
-
145
-
> [!TIP]
146
-
> When you test API operations, the API Management extension allows optional [policy debugging](api-management-debug-policies.md) (available only in the Developer service tier).
128
+
For steps to enable tracing for an API, see [Enable tracing for an API](api-management-howto-api-inspector.md#enable-tracing-for-an-api). To limit unintended disclosure of sensitive information, tracing by default is allowed for only 1 hour.
Copy file name to clipboardExpand all lines: includes/api-management-tracing-alert.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,10 @@
2
2
author: dlepow
3
3
ms.service: api-management
4
4
ms.topic: include
5
-
ms.date: 08/03/2022
5
+
ms.date: 05/05/2024
6
6
ms.author: danlep
7
7
---
8
-
> [!WARNING]
9
-
> *Only allow tracing on subscriptions intended for debugging purposes. Sharing subscription keys with tracing allowed with unauthorized users could lead to disclosure of sensitive information contained in tracing logs such as keys, access tokens, passwords, internal hostnames, and IP addresses.
10
-
> *In the test console, API Management automatically disables tracing 1 hour after it's enabled on a subscription.
11
-
8
+
> [!IMPORTANT]
9
+
> *API Management request tracing can no longer be enabled by setting the **Ocp-Apim-Trace** header in a request and using the value of the **Ocp-Apim-Trace-Location** header in the response to retrieve the trace.
10
+
> *To improve security, tracing is now 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 later in this tutorial.
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.
0 commit comments