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
title: Integrate Azure API Management with Azure Application Insights
2
+
title: Integrate Azure API Management with Application Insights
3
3
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.
6
5
author: dlepow
7
6
8
7
ms.service: api-management
9
-
ms.tgt_pltfrm: na
10
8
ms.topic: how-to
11
-
ms.date: 06/02/2023
9
+
ms.date: 08/25/2023
12
10
ms.author: danlep
13
11
ms.custom: engagement-fy23
14
-
15
12
---
16
13
17
14
# How to integrate Azure API Management with Azure Application Insights
18
15
19
16
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.
21
18
* Learn strategies for reducing performance impact on your API Management service instance.
22
19
23
20
## Prerequisites
24
21
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.
26
23
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).
28
25
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.
30
28
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:
33
30
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
35
38
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.
38
60
39
61
1. Navigate to your **Azure API Management service instance** in the **Azure portal**.
40
62
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
45
67
* This setting regularly validates whether the API Management gateway endpoint is responding.
46
68
* Results appear in the **Availability** pane of the Application Insights instance.
47
69
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
+
49
72
:::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.":::
50
73
51
74
> [!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.
53
76
54
77
> [!TIP]
55
78
> 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**.
56
79
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",
0 commit comments