Skip to content

Commit 2aa6a76

Browse files
committed
[APIM] v2 tracing
1 parent bd183ba commit 2aa6a76

File tree

5 files changed

+92
-27
lines changed

5 files changed

+92
-27
lines changed

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

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ services: api-management
55
author: dlepow
66
ms.service: api-management
77
ms.topic: tutorial
8-
ms.date: 08/08/2022
8+
ms.date: 03/26/2024
99
ms.author: danlep
1010
ms.custom: devdivchpfy22
1111
---
1212

1313
# Tutorial: Debug your APIs using request tracing
1414

15+
[!INCLUDE [api-management-availability-premium-dev-standard-basic-consumption](../../includes/api-management-availability-premium-dev-standard-basic-consumption.md)]
16+
1517
This tutorial describes how to inspect (trace) request processing in Azure API Management. Tracing helps you debug and troubleshoot your API.
1618

1719
In this tutorial, you learn how to:
@@ -22,20 +24,14 @@ In this tutorial, you learn how to:
2224
2325
:::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":::
2426

27+
[!INCLUDE [api-management-availability-tracing-v2-tiers](../../includes/api-management-availability-tracing-v2-tiers.md)]
28+
2529
## Prerequisites
2630

2731
+ Learn the [Azure API Management terminology](api-management-terminology.md).
2832
+ Complete the following quickstart: [Create an Azure API Management instance](get-started-create-service-instance.md).
2933
+ Complete the following tutorial: [Import and publish your first API](import-and-publish.md).
3034

31-
## Verify allow tracing setting
32-
33-
To trace request processing, you must enable the **Allow tracing** setting for the subscription used to debug your API. To check in the portal:
34-
35-
1. Navigate to your API Management instance and select **Subscriptions** to review the settings.
36-
37-
:::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":::
38-
1. If tracing isn't enabled for the subscription you're using, select the subscription and enable **Allow tracing**.
3935

4036
[!INCLUDE [api-management-tracing-alert](../../includes/api-management-tracing-alert.md)]
4137

@@ -52,10 +48,6 @@ To trace request processing, you must enable the **Allow tracing** setting for t
5248
5349
1. Select **Trace**.
5450

55-
* If your subscription doesn't already allow tracing, you're prompted to enable it if you want to trace the call.
56-
* You can also choose to send the request without tracing.
57-
58-
:::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":::
5951

6052
## Review trace information
6153

@@ -75,18 +67,66 @@ To trace request processing, you must enable the **Allow tracing** setting for t
7567
> [!TIP]
7668
> Each step also shows the elapsed time since the request is received by API Management.
7769
78-
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.
7970

80-
:::image type="content" source="media/api-management-howto-api-inspector/response-message-1.png" alt-text="Trace location in Azure Storage":::
71+
## Enable tracing using a REST client
72+
73+
You can enable tracing for an API when making requests to API Management using `curl`, a REST client such as VSCode with the REST Client extension, or a client app.
74+
75+
> [!IMPORTANT]
76+
> API Management request tracing is no longer 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.
77+
78+
Enable tracing by the following flow using calls to the API Management REST API.
79+
80+
> [!NOTE]
81+
> The following steps require API Management REST API version 2023-05-01-preview or later.
82+
83+
1. Obtain trace credentials by calling the [List debug credentials](/rest/api/apimanagement/gateway/list-debug-credentials) API. Pass the gateway resource ID in the URI, or use "managed" for the instance's managed gateway. for cloud in URI, and API that you want to trace in payload. For example:
84+
85+
```http
86+
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/{gatewayId}/listTrace?api-version=2023-05-01-preview
87+
/managed/listDebugCredentials?api-version=2023-05-01-preview
88+
```
89+
90+
Pass the full resource ID of the API in the payload, 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.
91+
92+
```json
93+
{
94+
"credentialsExpireAfter": PT1H,
95+
"apiId": "<API resource ID>",
96+
"purposes: ["tracing"]
97+
}
98+
```
99+
100+
The token credential is returned in the response, similar to the following:
101+
102+
```json
103+
{
104+
"token": "aid=api-name&p=tracing&ex=......."
105+
}
106+
```
107+
108+
1. To enable tracing, send the token value in an `Apim-Debug-Authorization` header of an API request.
109+
110+
* If the token is valid, the response contains an `Apim-Trace-Id` header whose value is the trace ID.
111+
* If the token is expired, the response contains an `Apim-Debug-Authorization-Expired` header with information about expiration date.
112+
* If the token was obtained for wrong API, the response contains an `Apim-Debug-Authorization-WrongAPI` header with an error message
113+
114+
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:
81115
82-
## Enable tracing using Ocp-Apim-Trace header
116+
```http
117+
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/gateways/managed/listTrace?api-version=2023-05-01-preview
118+
```
83119
84-
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:
120+
with body
85121
86-
* **Ocp-Apim-Trace** - set value to `true`
87-
* **Ocp-Apim-Subscription-Key** - set value to the key for a tracing-enabled subscription that allows access to the API
122+
```json
123+
{
124+
"traceId": "<trace ID>"
125+
}
126+
```
127+
128+
The response body contains the trace data for the previous API request to the gateway.
88129
89-
The response includes the **Ocp-Apim-Trace-Location** header, with a URL to the location of the trace data in Azure blob storage.
90130
91131
For information about customizing trace information, see the [trace](trace-policy.md) policy.
92132

articles/api-management/api-management-howto-create-subscriptions.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ author: dlepow
66

77
ms.service: api-management
88
ms.topic: how-to
9-
ms.date: 08/03/2022
9+
ms.date: 03/26/2024
1010
ms.author: danlep
1111
---
1212
# Create subscriptions in Azure API Management
1313

14+
[!INCLUDE [api-management-availability-all-tiers](../../includes/api-management-availability-all-tiers.md)]
15+
1416
When you publish APIs through Azure API Management, it's easy and common to secure access to those APIs by using subscription keys. Client applications that need to consume the published APIs must include a valid subscription key in HTTP requests when they make calls to those APIs. To get a subscription key for accessing APIs, a subscription is required. For more information about subscriptions, see [Subscriptions in Azure API Management](api-management-subscriptions.md).
1517

1618
This article walks through the steps for creating subscriptions in the Azure portal.
@@ -29,13 +31,13 @@ To take the steps in this article, the prerequisites are as follows:
2931
1. Navigate to your API Management instance in the [Azure portal](https://portal.azure.com).
3032
1. In the left menu, under **APIs**, select **Subscriptions** > **Add subscription**.
3133
1. Provide a **Name** and optional **Display name** of the subscription.
32-
1. Optionally, select **Allow tracing** to enable tracing for debugging and troubleshooting APIs. [Learn more](api-management-howto-api-inspector.md)
33-
34-
[!INCLUDE [api-management-tracing-alert](../../includes/api-management-tracing-alert.md)]
3534
1. Select a **Scope** of the subscription from the dropdown list. [Learn more](api-management-subscriptions.md#scope-of-subscriptions)
3635
1. Optionally, choose if the subscription should be associated with a **User** and whether to send a notification for use with the developer portal.
3736
1. Select **Create**.
3837

38+
> [!IMPORTANT]
39+
> The **Allow tracing** setting in subscriptions is deprecated. Tracing can now be enabled for specific APIs. [Learn more](api-management-howto-api-inspector.md)
40+
3941
:::image type="content" source="media/api-management-howto-create-subscriptions/create-subscription.png" alt-text="Screenshot showing how to create an API Management subscription in the portal.":::
4042

4143
After you create the subscription, it appears in the list on the **Subscriptions** page. Two API keys are provided to access the APIs. One key is primary, and one is secondary.

articles/api-management/trace-policy.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@ services: api-management
55
author: dlepow
66
ms.service: api-management
77
ms.topic: article
8-
ms.date: 12/08/2022
8+
ms.date: 03/18/2024
99
ms.author: danlep
1010
---
1111

1212
# Trace
1313

14+
[!INCLUDE [api-management-availability-all-tiers](../../includes/api-management-availability-all-tiers.md)]
15+
1416
The `trace` policy adds a custom trace into the request tracing output in the test console, Application Insights telemetries, and/or resource logs.
1517

16-
- 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.
1719
- 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).
1820
- 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).
1921
- The policy is not affected by Application Insights sampling. All invocations of the policy will be logged.
2022

2123
[!INCLUDE [api-management-tracing-alert](../../includes/api-management-tracing-alert.md)]
2224

25+
[!INCLUDE [api-management-availability-tracing-v2-tiers](../../includes/api-management-availability-tracing-v2-tiers.md)]
26+
2327
[!INCLUDE [api-management-policy-generic-alert](../../includes/api-management-policy-generic-alert.md)]
2428

2529
## Policy statement
@@ -69,6 +73,6 @@ The `trace` policy adds a custom trace into the request tracing output in the te
6973

7074
## Related policies
7175

72-
* [API Management advanced policies](api-management-advanced-policies.md)
76+
* [Logging](api-management-policies.md#logging)
7377

7478
[!INCLUDE [api-management-policy-ref-next-steps](../../includes/api-management-policy-ref-next-steps.md)]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
author: dlepow
3+
ms.service: api-management
4+
ms.topic: include
5+
ms.date: 03/06/2024
6+
ms.author: danlep
7+
---
8+
**APPLIES TO: All API Management tiers**
9+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
author: dlepow
3+
ms.service: api-management
4+
ms.topic: include
5+
ms.date: 03/26/2024
6+
ms.author: danlep
7+
---
8+
9+
> [!NOTE]
10+
> Currently, tracing in the test console isn't supported in the Basic v2 and Standard v2 tiers.

0 commit comments

Comments
 (0)