Skip to content

Commit 0681455

Browse files
committed
scaffold updates
1 parent fd59e0a commit 0681455

File tree

1 file changed

+221
-14
lines changed

1 file changed

+221
-14
lines changed

articles/api-management/api-management-howto-app-insights.md

Lines changed: 221 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,52 @@
11
---
2-
title: Integrate Azure API Management with Azure Application Insights
2+
title: Integrate Azure API Management with Application Insights
33
titleSuffix: Azure API Management
44
description: Learn how to log and view events from Azure API Management in Azure Application Insights.
5-
services: api-management
65
author: dlepow
76

87
ms.service: api-management
9-
ms.tgt_pltfrm: na
108
ms.topic: how-to
11-
ms.date: 06/02/2023
9+
ms.date: 08/25/2023
1210
ms.author: danlep
1311
ms.custom: engagement-fy23
14-
1512
---
1613

1714
# How to integrate Azure API Management with Azure Application Insights
1815

1916
You can easily integrate Azure Application Insights with Azure API Management. Azure Application Insights is an extensible service for web developers building and managing apps on multiple platforms. In this guide, you will:
20-
* Walk through every step of the Application Insights integration into API Management.
17+
* Walk through Application Insights integration into API Management.
2118
* Learn strategies for reducing performance impact on your API Management service instance.
2219

2320
## Prerequisites
2421

25-
You need an Azure API Management instance. [Create one](get-started-create-service-instance.md) first.
26-
27-
## Create an Application Insights instance
22+
* You need an Azure API Management instance. [Create one](get-started-create-service-instance.md) first.
2823

29-
To use Application Insights, [create an instance of the Application Insights service](/previous-versions/azure/azure-monitor/app/create-new-resource). To create an instance using the Azure portal, see [Workspace-based Application Insights resources](../azure-monitor/app/create-workspace-resource.md).
24+
* To use Application Insights, [create an instance of the Application Insights service](/previous-versions/azure/azure-monitor/app/create-new-resource). To create an instance using the Azure portal, see [Workspace-based Application Insights resources](../azure-monitor/app/create-workspace-resource.md).
3025

3126
> [!NOTE]
3227
> The Application Insights resource **can be** in a different subscription or even a different tenant than the API Management resource.
3328
34-
## Create a connection between Application Insights and API Management
29+
## Scenario overview
3530

36-
> [!NOTE]
37-
> If your Application Insights resource is in a different tenant, then you will have to create the logger using the [REST API](/rest/api/apimanagement/current-ga/logger/create-or-update)
31+
1. First, you create a connection between Application Insights and API Management
32+
33+
You can create a connection between Application Insights and your API Management using the Azure portal, the REST API, or related Azure tools. API Management configures a *logger* resource for the connection.
34+
35+
> [!NOTE]
36+
> If your Application Insights resource is in a different tenant, then you must create the logger using the [REST API](/rest/api/apimanagement/current-ga/logger/create-or-update).
37+
38+
> [!IMPORTANT]
39+
> Currently, in the portal, API Management only supports connections to Application Insights using an Application Insights instrumentation key. To use an Application Insights connection string or an API Management managed identity, use the REST API, Bicep, or ARM template to create the logger.
40+
>
41+
42+
1. Second, you enable Application Insights logging for your API or APIs.
43+
44+
In this article, you enable Application Insights logging for your API using the Azure portal. API Management configures a *diagnostic* resource for the API.
45+
46+
47+
## Create a connection using the Azure portal
48+
49+
Follow these steps to use the Azure portal to create a connection between Application Insights and API Management.
3850

3951
1. Navigate to your **Azure API Management service instance** in the **Azure portal**.
4052
1. Select **Application Insights** from the menu on the left.
@@ -49,11 +61,206 @@ To use Application Insights, [create an instance of the Application Insights ser
4961
:::image type="content" source="media/api-management-howto-app-insights/apim-app-insights-logger-2.png" alt-text="Screenshot that shows where to view the newly created Application Insights logger.":::
5062

5163
> [!NOTE]
52-
> Behind the scenes, a [Logger](/rest/api/apimanagement/current-ga/logger/create-or-update) entity is created in your API Management instance, containing the instrumentation key of the Application Insights instance.
64+
> Behind the scenes, a [logger](/rest/api/apimanagement/current-ga/logger/create-or-update) entity is created in your API Management instance, containing the instrumentation key of the Application Insights instance.
5365
5466
> [!TIP]
5567
> If you need to update the instrumentation key configured in the Application Insights logger, select the logger's row in the list (not the name of the logger). Enter the instrumentation key, and select **Save**.
5668
69+
## Create a connection using the REST API, Bicep, or ARM template
70+
71+
Follow these steps to use the REST API, Bicep, or ARM template to create a connection between Application Insights and API Management. You can configure a logger that uses a connection string, system-assigned identity, or user-assigned identity.
72+
73+
The following prerequisites are needed to configure a managed identity for API Management:
74+
75+
1. Enable a system-assigned or user-assigned [managed identity for API Management](api-management-howto-use-managed-service-identity.md) in your API Management instance.
76+
77+
* If you enable a user-assigned managed identity, take note of the identity's **Client ID**.
78+
79+
1. Assign the identity the **Monitoring Metrics Publisher** role, scoped to the Application Insights resource. To assign the role, use the [Azure portal](../active-directory/managed-identities-azure-resources/howto-assign-access-portal.md) or other Azure tools.
80+
81+
82+
### Logger with connection string credentials
83+
84+
Your connection string appears in the **Overview** section of your Application Insights resource.
85+
86+
#### [REST API](#tab/rest)
87+
88+
Use the API Management [REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) with the following request body.
89+
90+
```JSON
91+
{
92+
"properties": {
93+
"loggerType": "applicationInsights",
94+
"description": "adding a new logger with connection string",
95+
"credentials": {
96+
"connectionString":"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;..."
97+
}
98+
}
99+
}
100+
```
101+
102+
#### [Bicep](#tab/bicep)
103+
104+
Include a snippet similar to the following in your Bicep template.
105+
106+
```Bicep
107+
resource aiLoggerWithSystemAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-04-01-preview' = {
108+
name: 'ContosoLogger1'
109+
parent: '<APIManagementInstanceName>'
110+
properties: {
111+
loggerType: 'applicationInsights'
112+
description: 'Application Insights logger with system-assigned managed identity'
113+
credentials: {
114+
connectionString: 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...'
115+
}
116+
}
117+
}
118+
```
119+
120+
#### [ARM](#tab/arm)
121+
122+
Include a JSON snippet similar to the following in your Azure Resource Manager template.
123+
124+
```JSON
125+
{
126+
"type": "Microsoft.ApiManagement/service/loggers",
127+
"apiVersion": "2022-04-01-preview",
128+
"name": "ContosoLogger1",
129+
"properties": {
130+
"loggerType": "applicationInsights",
131+
"description": "Application Insights logger with system-assigned managed identity",
132+
"resourceId": "<ApplicationInsightsResourceID>",
133+
"credentials": {
134+
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;..."
135+
},
136+
}
137+
}
138+
```
139+
---
140+
141+
### Logger with system-assigned managed identity credentials
142+
143+
#### [REST API](#tab/rest)
144+
145+
Use the API Management [REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) with the following request body.
146+
147+
```JSON
148+
{
149+
"properties": {
150+
"loggerType": "applicationInsights",
151+
"description": "adding a new logger with system assigned managed identity",
152+
"credentials": {
153+
"connectionString":"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
154+
"identityClientId":"SystemAssigned"
155+
}
156+
}
157+
}
158+
159+
```
160+
161+
#### [Bicep](#tab/bicep)
162+
163+
Include a snippet similar to the following in your Bicep template.
164+
165+
```Bicep
166+
resource aiLoggerWithSystemAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-04-01-preview' = {
167+
name: 'ContosoLogger1'
168+
parent: '<APIManagementInstanceName>'
169+
properties: {
170+
loggerType: 'applicationInsights'
171+
description: 'Application Insights logger with system-assigned managed identity'
172+
credentials: {
173+
connectionString: 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...'
174+
identityClientId: 'systemAssigned'
175+
}
176+
}
177+
}
178+
```
179+
180+
#### [ARM](#tab/arm)
181+
182+
Include a JSON snippet similar to the following in your Azure Resource Manager template.
183+
184+
```JSON
185+
{
186+
"type": "Microsoft.ApiManagement/service/loggers",
187+
"apiVersion": "2022-04-01-preview",
188+
"name": "ContosoLogger1",
189+
"properties": {
190+
"loggerType": "applicationInsights",
191+
"description": "Application Insights logger with system-assigned managed identity",
192+
"resourceId": "<ApplicationInsightsResourceID>",
193+
"credentials": {
194+
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
195+
"identityClientId": "SystemAssigned"
196+
},
197+
}
198+
}
199+
```
200+
---
201+
### Logger with user-assigned managed identity credentials
202+
203+
For prerequisites, see [Configure API Management managed identity](#option-2-configure-api-management-managed-identity).
204+
205+
#### [REST API](#tab/PowerShell)
206+
207+
Use the API Management [REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) with the following request body.
208+
209+
```JSON
210+
{
211+
"properties": {
212+
"loggerType": "applicationInsights",
213+
"description": "adding a new logger with system assigned managed identity",
214+
"credentials": {
215+
"connectionString":"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
216+
"identityClientId":"<ClientID>"
217+
}
218+
}
219+
}
220+
221+
```
222+
223+
#### [Bicep](#tab/bicep)
224+
225+
Include a snippet similar the following in your Bicep template.
226+
227+
```Bicep
228+
resource aiLoggerWithUserAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-04-01-preview' = {
229+
name: 'ContosoLogger1'
230+
parent: '<APIManagementInstanceName>'
231+
properties: {
232+
loggerType: 'applicationInsights'
233+
description: 'Application Insights logger with user-assigned managed identity'
234+
credentials: {
235+
connectionString: 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...'
236+
identityClientId: '<ClientID>'
237+
}
238+
}
239+
}
240+
```
241+
242+
#### [ARM](#tab/arm)
243+
244+
Include a JSON snippet similar to the following in your Azure Resource Manager template.
245+
246+
```JSON
247+
{
248+
"type": "Microsoft.ApiManagement/service/loggers",
249+
"apiVersion": "2022-04-01-preview",
250+
"name": "ContosoLogger1",
251+
"properties": {
252+
"loggerType": "applicationInsights",
253+
"description": "Application Insights logger with user-assigned managed identity",
254+
"resourceId": "<ApplicationInsightsResourceID>",
255+
"credentials": {
256+
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
257+
"identityClientId": "<ClientID>"
258+
},
259+
}
260+
}
261+
```
262+
---
263+
57264
## Enable Application Insights logging for your API
58265

59266
Use the following steps to enable Application Insights logging for an API. You can also enable Application Insights logging for all APIs.

0 commit comments

Comments
 (0)