Skip to content

Commit 26d0417

Browse files
Merge pull request #249419 from dlepow/aiconnex
[APIM] Additional connection methods to Application Insights
2 parents 5197856 + 6fdffe0 commit 26d0417

File tree

1 file changed

+228
-17
lines changed

1 file changed

+228
-17
lines changed

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

Lines changed: 228 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,62 @@
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
4-
description: Learn how to log and view events from Azure API Management in Azure Application Insights.
5-
services: api-management
4+
description: Learn how to set up a connection to Application Insights and enable logging for APIs in your Azure API Management instance.
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.
22+
* You need an Azure API Management instance. [Create one](get-started-create-service-instance.md) first.
2623

27-
## Create an Application Insights instance
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).
2825

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).
26+
> [!NOTE]
27+
> The Application Insights resource **can be** in a different subscription or even a different tenant than the API Management resource.
3028
31-
> [!NOTE]
32-
> The Application Insights resource **can be** in a different subscription or even a different tenant than the API Management resource.
29+
* If you plan to configure a managed identity for API Management to use with Application Insights, you need to complete the following steps:
3330

34-
## Create a connection between Application Insights and API Management
31+
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.
32+
33+
* If you enable a user-assigned managed identity, take note of the identity's **Client ID**.
34+
35+
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.
36+
37+
## Scenario overview
3538

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)
39+
The following are high level steps for this scenario.
40+
41+
1. First, you create a connection between Application Insights and API Management
42+
43+
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.
44+
45+
> [!NOTE]
46+
> 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).
47+
48+
> [!IMPORTANT]
49+
> 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. [Learn more](../azure-monitor/app/sdk-connection-string.md) about Application Insights connection strings.
50+
>
51+
52+
1. Second, you enable Application Insights logging for your API or APIs.
53+
54+
In this article, you enable Application Insights logging for your API using the Azure portal. API Management configures a *diagnostic* resource for the API.
55+
56+
57+
## Create a connection using the Azure portal
58+
59+
Follow these steps to use the Azure portal to create a connection between Application Insights and API Management.
3860

3961
1. Navigate to your **Azure API Management service instance** in the **Azure portal**.
4062
1. Select **Application Insights** from the menu on the left.
@@ -45,15 +67,204 @@ To use Application Insights, [create an instance of the Application Insights ser
4567
* This setting regularly validates whether the API Management gateway endpoint is responding.
4668
* Results appear in the **Availability** pane of the Application Insights instance.
4769
1. Select **Create**.
48-
1. Check that the new Application Insights logger now appears in the list.
70+
1. Check that the new Application Insights logger now appears in the list.
71+
4972
:::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.":::
5073

5174
> [!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.
75+
> Behind the scenes, a logger entity is created in your API Management instance, containing the instrumentation key of the Application Insights instance.
5376
5477
> [!TIP]
5578
> 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**.
5679
80+
## Create a connection using the REST API, Bicep, or ARM template
81+
82+
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 managed identity, or user-assigned managed identity.
83+
84+
### Logger with connection string credentials
85+
86+
The Application Insights connection string appears in the **Overview** section of your Application Insights resource.
87+
88+
#### [REST API](#tab/rest)
89+
90+
Use the API Management [REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) with the following request body.
91+
92+
```JSON
93+
{
94+
"properties": {
95+
"loggerType": "applicationInsights",
96+
"description": "adding a new logger with connection string",
97+
"credentials": {
98+
"connectionString":"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;..."
99+
}
100+
}
101+
}
102+
```
103+
104+
#### [Bicep](#tab/bicep)
105+
106+
Include a snippet similar to the following in your Bicep template.
107+
108+
```Bicep
109+
resource aiLoggerWithSystemAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-08-01' = {
110+
name: 'ContosoLogger1'
111+
parent: '<APIManagementInstanceName>'
112+
properties: {
113+
loggerType: 'applicationInsights'
114+
description: 'Application Insights logger with connection string'
115+
credentials: {
116+
connectionString: 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...'
117+
}
118+
}
119+
}
120+
```
121+
122+
#### [ARM](#tab/arm)
123+
124+
Include a JSON snippet similar to the following in your Azure Resource Manager template.
125+
126+
```JSON
127+
{
128+
"type": "Microsoft.ApiManagement/service/loggers",
129+
"apiVersion": "2022-08-01",
130+
"name": "ContosoLogger1",
131+
"properties": {
132+
"loggerType": "applicationInsights",
133+
"description": "Application Insights logger with connection string",
134+
"resourceId": "<ApplicationInsightsResourceID>",
135+
"credentials": {
136+
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;..."
137+
},
138+
}
139+
}
140+
```
141+
---
142+
143+
### Logger with system-assigned managed identity credentials
144+
145+
See the [prerequisites](#prerequisites) for using an API Management managed identity.
146+
147+
#### [REST API](#tab/rest)
148+
149+
Use the API Management [REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) with the following request body.
150+
151+
```JSON
152+
{
153+
"properties": {
154+
"loggerType": "applicationInsights",
155+
"description": "adding a new logger with system-assigned managed identity",
156+
"credentials": {
157+
"connectionString":"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
158+
"identityClientId":"SystemAssigned"
159+
}
160+
}
161+
}
162+
163+
```
164+
165+
#### [Bicep](#tab/bicep)
166+
167+
Include a snippet similar to the following in your Bicep template.
168+
169+
```Bicep
170+
resource aiLoggerWithSystemAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-08-01' = {
171+
name: 'ContosoLogger1'
172+
parent: '<APIManagementInstanceName>'
173+
properties: {
174+
loggerType: 'applicationInsights'
175+
description: 'Application Insights logger with system-assigned managed identity'
176+
credentials: {
177+
connectionString: 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...'
178+
identityClientId: 'systemAssigned'
179+
}
180+
}
181+
}
182+
```
183+
184+
#### [ARM](#tab/arm)
185+
186+
Include a JSON snippet similar to the following in your Azure Resource Manager template.
187+
188+
```JSON
189+
{
190+
"type": "Microsoft.ApiManagement/service/loggers",
191+
"apiVersion": "2022-08-01",
192+
"name": "ContosoLogger1",
193+
"properties": {
194+
"loggerType": "applicationInsights",
195+
"description": "Application Insights logger with system-assigned managed identity",
196+
"resourceId": "<ApplicationInsightsResourceID>",
197+
"credentials": {
198+
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
199+
"identityClientId": "SystemAssigned"
200+
}
201+
}
202+
}
203+
```
204+
---
205+
### Logger with user-assigned managed identity credentials
206+
207+
See the [prerequisites](#prerequisites) for using an API Management managed identity.
208+
209+
#### [REST API](#tab/rest)
210+
211+
Use the API Management [REST API](/rest/api/apimanagement/current-preview/logger/create-or-update) with the following request body.
212+
213+
```JSON
214+
{
215+
"properties": {
216+
"loggerType": "applicationInsights",
217+
"description": "adding a new logger with user-assigned managed identity",
218+
"credentials": {
219+
"connectionString":"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
220+
"identityClientId":"<ClientID>"
221+
}
222+
}
223+
}
224+
225+
```
226+
227+
#### [Bicep](#tab/bicep)
228+
229+
Include a snippet similar the following in your Bicep template.
230+
231+
```Bicep
232+
resource aiLoggerWithUserAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-08-01' = {
233+
name: 'ContosoLogger1'
234+
parent: '<APIManagementInstanceName>'
235+
properties: {
236+
loggerType: 'applicationInsights'
237+
description: 'Application Insights logger with user-assigned managed identity'
238+
credentials: {
239+
connectionString: 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...'
240+
identityClientId: '<ClientID>'
241+
}
242+
}
243+
}
244+
```
245+
246+
#### [ARM](#tab/arm)
247+
248+
Include a JSON snippet similar to the following in your Azure Resource Manager template.
249+
250+
```JSON
251+
{
252+
"type": "Microsoft.ApiManagement/service/loggers",
253+
"apiVersion": "2022-08-01",
254+
"name": "ContosoLogger1",
255+
"properties": {
256+
"loggerType": "applicationInsights",
257+
"description": "Application Insights logger with user-assigned managed identity",
258+
"resourceId": "<ApplicationInsightsResourceID>",
259+
"credentials": {
260+
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
261+
"identityClientId": "<ClientID>"
262+
}
263+
}
264+
}
265+
```
266+
---
267+
57268
## Enable Application Insights logging for your API
58269

59270
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)