Skip to content

Commit f37ee1f

Browse files
author
gitName
committed
[APIM] Policy mgt in VSCode ext
1 parent c997888 commit f37ee1f

File tree

4 files changed

+100
-30
lines changed

4 files changed

+100
-30
lines changed

articles/api-management/TOC.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@
263263
href: set-edit-policies.md
264264
- name: Author policies using Microsoft Copilot in Azure
265265
href: /azure/copilot/author-api-management-policies?toc=%2Fazure%2Fapi-management%2Ftoc.json&bc=/azure/api-management/breadcrumb/toc.json
266-
- name: Debug policies in VS Code
266+
- name: Create and debug policies in VS Code
267267
href: api-management-debug-policies.md
268268
- name: Policy expressions
269269
href: api-management-policy-expressions.md

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

Lines changed: 99 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,141 @@
11
---
2-
title: Debug Azure API Management policies in Visual Studio Code | Microsoft Docs
3-
description: Learn how to debug Azure API Management Policies using the Azure API Management Visual Studio Code extension
2+
title: Create and debug Azure API Management policies in VS Code
3+
description: Learn how to create, understand, and debug Azure API Management Policies with Copilot assistance using the Azure API Management Visual Studio Code extension.
44
author: dlepow
55
ms.service: azure-api-management
66
ms.topic: how-to
7-
ms.date: 09/22/2020
7+
ms.date: 03/27/2025
88
ms.author: danlep
9+
ms.collection: ce-skilling-ai-copilot
910
---
1011

11-
# Debug Azure API Management policies in Visual Studio Code
12+
# Create, understand, and debug Azure API Management policies in Visual Studio Code
1213

13-
[!INCLUDE [api-management-availability-developer](../../includes/api-management-availability-developer.md)]
14+
<!-- Confirm SKU availability for this feature. -->
1415

15-
[Policies](api-management-policies.md) in Azure API Management provide powerful capabilities that help API publishers address cross-cutting concerns such as authentication, authorization, throttling, caching, and transformation. Policies are a collection of statements that are executed sequentially on the request or response of an API.
16+
[!INCLUDE [api-management-availability-all-tiers](../../includes/api-management-availability-all-tiers.md)]
1617

17-
This article describes how to debug API Management policies using the [Azure API Management Extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-apimanagement).
18+
This article explains how to use the [Azure API Management Extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-apimanagement) to create, understand, and debug Azure API Management policies with AI assistance from [GitHub Copilot for Azure](/azure/developer/github-copilot-azure/introduction).
19+
20+
Azure API Management policies are a sequence of statements that address cross-cutting concerns like authentication, authorization, throttling, caching, and transformation, applied to API requests or responses.
1821

1922
## Prerequisites
2023

21-
* Create an API Management Developer-tier instance by following this [quickstart](get-started-create-service-instance.md) first.
24+
* [Visual Studio Code](https://code.visualstudio.com/) and the latest version of [Azure API Management Extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-apimanagement).
25+
26+
* The following extensions are needed for the specified scenarios:
27+
28+
* [GitHub Copilot for Azure extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azure-github-copilot) - to create and explain policies
29+
* [REST Client extension](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) - to debug policies
2230

23-
* Install [Visual Studio Code](https://code.visualstudio.com/) and the latest version of [Azure API Management Extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-apimanagement).
31+
<!-- Assume we need a step to install GH Copilot ext? -->
32+
33+
* An API Management instance. If you need to create one, see this [quickstart](vscode-create-service-instance.md).
34+
35+
<!-- Still can't use extension to create instance in v2 tiers? -->
2436

2537
* Import an API to your API Management instance. For example steps, see [Tutorial: Use the API Management Extension for Visual Studio Code to import and manage APIs](visual-studio-code-tutorial.md).
2638

2739
## Restrictions and limitations
2840

29-
* This feature uses the built-in (service-level) all-access subscription (display name "Built-in all-access subscription") for debugging.
41+
* Policy debugging uses the built-in (service-level) all-access subscription (display name "Built-in all-access subscription") .
42+
43+
[!INCLUDE [api-management-tracing-alert](../../includes/api-manaement-tracing-alert.md)]
44+
45+
## Create polices using GitHub Copilot
46+
The Azure API Management extension integrates with GitHub Copilot for Azure to help you create a draft of a policy. With AI assistance, create and edit policies in a user-friendly way.
47+
48+
To create a policy:
49+
50+
1. Open the API Management extension in Visual Studio Code.
51+
1. Select the API Management instance you want to work with.
52+
1. Select the policy scope that you want to work with.
53+
* To create a policy that applies to all APIs in the instance, select **Global Policy**.
54+
* To create a policy that applies to a specific API, under **APIs**, select the API, and then select **Policy**.
55+
1. In the policy editor window that appears, right-click and select **Copilot** > **Draft APIM Policies**. The Copilot Chat window appears.
56+
1. In the Copilot Chat window, enter a prompt in natural language to create a policy. Examples:
57+
58+
```copilot-prompt
59+
@azure I want to limit requests to 100 calls per minute
60+
```
61+
62+
```copilot-prompt
63+
@azure Create a policy that sets the backend URL to https://mybackend.contoso.com and adds a header to the request
64+
```
65+
1. Copilot generates a policy draft in the chat window. You can refine the prompt if you want Copilot to change the output.
66+
67+
1. When you're ready, select the **Copy** button to copy the policy to the clipboard, or select **Apply in Editor** to insert the policy in the editor window. If you are satisfied with the change in the policy XML, select **Keep**.
68+
69+
:::image type="content" source="media/api-management-debug-policies/draft-policy.gif" alt-text="Animation showing drafting of an API Management policy in VS Code.":::
3070
31-
[!INCLUDE [api-management-tracing-alert](../../includes/api-management-tracing-alert.md)]
71+
> [!TIP]
72+
> Check in the **Problems** window for explanation of any issues in the policy XML.
73+
74+
## Explain a policy using GitHub Copilot
75+
76+
Copilot can help explain an existing policy in your API Management instance.
77+
78+
To receive an explanation:
79+
80+
1. Open the API Management extension in Visual Studio Code.
81+
1. Select the API Management instance you want to work with.
82+
1. Select the policy scope that you want to work with.
83+
* To explain a policy that applies to all APIs in the instance, select **Global Policy**.
84+
* To explain a policy that applies to a specific API, under **APIs**, select the API, and then select **Policy**.
85+
1. In the policy editor window that appears, right-click and select **Copilot** > **Explain APIM Policies**.
86+
1. An overview and explanation of policies in the policy XML document are generated in the Copilot Chat window.
87+
88+
:::image type="content" source="media/api-management-debug-policies/draft-policy.gif" alt-text="Animation showing explanation of an API Management policy in VS Code.":::
3289
33-
## Initiate a debugging session
90+
## Debug policies using the VS Code extension
3491
35-
1. Launch Visual Studio Code
36-
2. Navigate to the API Management extension under Azure extensions
37-
3. Find the API Management instance to debug
38-
4. Find the API and operation to debug
39-
5. Right click on the operation and select **Start policy debugging**
92+
The Azure API Management extension for Visual Studio Code provides a debugging experience that allows you to step through the policy pipeline or set a breakpoint when you send a request to the gateway.
4093
41-
At this point, the extension will try to initiate and establish a debugging session with the API Management gateway.
94+
> [!IMPORTANT]
95+
> Policy debugging in the Visual Studio Code extension is only supported in the API Management Developer tier.
4296
43-
![initiate debugging](media/api-management-debug-policies/initiate-debugging-session.png)
97+
### Initiate a debugging session
4498
45-
## Send a test request
46-
When the debugging session is established, the extension will open a new editor that allows us to create and send a test HTTP request to this operation leveraging the [REST Client extension](https://marketplace.visualstudio.com/items?itemName=humao.rest-client).
99+
1. Open the API Management extension in Visual Studio Code.
100+
3. Select the API Management instance to debug.
101+
4. Select the API and operation to debug.
102+
5. Right click on the operation and select **Start Policy Debugging**.
103+
104+
At this point, the extension starts to establish a debugging session with the API Management gateway. Check the progress in the **Debug Console** windows.
105+
106+
:::image type="content" source="media/api-management-debug-policies/initiate-debugging-session.png" alt-text="Screenshot if initiating a policy debugging session in Visual Studio Code.":::
107+
108+
> [!NOTE]
109+
> Starting a debugging session also enables request tracing during the session, to help you diagnose and solve issues.
110+
111+
### Send a test request
112+
113+
When the debugging session is established, the REST Client extension opens a new editor that allows you to create and send a test HTTP request to the gateway.
47114
48115
You will notice the **Ocp-Apim-Debug** header has already been added to the request. This header is required and the value must be set to the service-level, all-access subscription key to trigger the debugging functionality in the API Management gateway.
49116
50-
Modify the HTTP request in the editor according to your test scenario. Then click **send request** to send the test request to the API Management gateway.
117+
Modify the HTTP request in the editor according to your test scenario. Then click **Send Request** to send the test request to the API Management gateway.
118+
51119
52-
![send a test request](media/api-management-debug-policies/rest-client.png)
120+
:::image type="content" source="media/api-management-debug-policies/rest-client.png" alt-text="Screenshot of sending a test request in Visual Studio Code.":::
53121
54-
## Debug policies
55-
After the test HTTP request is sent, the extension will open the debugging window showing the effective policies of this operation and stop at the first effective policy.
122+
### Debug policies
123+
After the test HTTP request is sent, the extension opens the debugging window, which shows the effective policies of this operation and stop at the first effective policy.
56124
57-
![debug policies](media/api-management-debug-policies/main-window.png)
125+
:::image type="content" source="media/api-management-debug-policies/main-window.png" alt-text="Screenshot of the debugging window in Visual Studio Code.":::
58126
59127
To follow the policy pipeline, you can single-step through individual policies or set a breakpoint at a policy and step directly to that policy.
60128
61-
In the **Variables** panel, you can inspect values of system-created and user-created variables. In the **Breakpoints** panel, you can see the list of all breakpoints that have been set. In the **Call Stack** panel, you can see the current effective policy scope.
129+
* In the **Variables** panel, inspect values of system-created and user-created variables.
130+
* In the **Breakpoints** panel, view the list of all breakpoints that have been set.
131+
* In the **Call Stack** panel, view the current effective policy scope.
62132
63133
If there is an error during policy execution, you will see the details of the error at the policy where it happened.
64134
65-
![exceptions](media/api-management-debug-policies/exception.png)
135+
:::image type="content" source="media/api-management-debug-policies/exception.png" alt-text="Screenshot of a policy exception in Visual Studio Code.":::
66136
67137
> [!TIP]
68-
> Remember to exit the debug session by clicking the **Stop** button when you are finished.
138+
> Exit the debugging session by clicking the **Stop** button when you are finished.
69139
70140
71141
## Related content
1.91 MB
Loading
2.5 MB
Loading

0 commit comments

Comments
 (0)