Skip to content

Commit de074cc

Browse files
authored
Merge pull request #286330 from MicrosoftDocs/main
[Publishing] [Out of Band Publish] 09/06 - 16:00
2 parents 19b453a + c03f937 commit de074cc

File tree

4 files changed

+147
-128
lines changed

4 files changed

+147
-128
lines changed

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

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: dlepow
66

77
ms.service: azure-api-management
88
ms.topic: how-to
9-
ms.date: 07/11/2024
9+
ms.date: 09/04/2024
1010
ms.author: danlep
1111
ms.custom: engagement-fy23, devx-track-arm-template, devx-track-bicep
1212
---
@@ -20,7 +20,7 @@ You can easily integrate Azure Application Insights with Azure API Management. A
2020
* Learn strategies for reducing performance impact on your API Management service instance.
2121

2222
> [!NOTE]
23-
> In an API Management [workspace](workspaces-overview.md), a workspace owner can independently integrate Application Insights and enable Application Insights logging for the workspace's APIs. The general guidance to integrate a workspace with Application Insights is similar to the guidance for an API Management instance; however, configuration is scoped to the workspace only. Currently, you must integrate Application Insights in a workspace by configuring an instrumentation key or connection string.
23+
> In an API Management [workspace](workspaces-overview.md), a workspace owner can independently integrate Application Insights and enable Application Insights logging for the workspace's APIs. The general guidance to integrate a workspace with Application Insights is similar to the guidance for an API Management instance; however, configuration is scoped to the workspace only. Currently, you must integrate Application Insights in a workspace by configuring a connection string (recommended) or an instrumentation key.
2424
2525
> [!WARNING]
2626
> When using our [self-hosted gateway](self-hosted-gateway-overview.md), we do not guarantee all telemetry will be pushed to Azure Application Insights given it relies on [Application Insights' in-memory buffering](./../azure-monitor/app/telemetry-channels.md#built-in-telemetry-channels).
@@ -34,9 +34,9 @@ You can easily integrate Azure Application Insights with Azure API Management. A
3434
> [!NOTE]
3535
> The Application Insights resource **can be** in a different subscription or even a different tenant than the API Management resource.
3636
37-
* If you plan to configure a managed identity for API Management to use with Application Insights, you need to complete the following steps:
37+
* If you plan to configure managed identity credentials to use with Application Insights, complete the following steps:
3838

39-
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.
39+
1. Enable a system-assigned or user-assigned [managed identity for API Management](api-management-howto-use-managed-service-identity.md).
4040

4141
* If you enable a user-assigned managed identity, take note of the identity's **Client ID**.
4242

@@ -46,18 +46,18 @@ You can easily integrate Azure Application Insights with Azure API Management. A
4646

4747
The following are high level steps for this scenario.
4848

49-
1. First, you create a connection between Application Insights and API Management
49+
1. First, create a connection between Application Insights and API Management
5050

5151
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.
5252

53-
> [!NOTE]
54-
> If your Application Insights resource is in a different tenant, then you must create the logger using the [REST API](#create-a-connection-using-the-rest-api-bicep-or-arm-template) as shown in a later section of this article.
55-
5653
> [!IMPORTANT]
57-
> 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.
54+
> Currently, in the portal, API Management only supports connections to Application Insights using an Application Insights instrumentation key. For enhanced security, we recommend using an Application Insights connection string with an API Management managed identity. To configure connection string with managed identity credentials, use the [REST API](#create-a-connection-using-the-rest-api-bicep-or-arm-template) or related tools as shown in a later section of this article. [Learn more](../azure-monitor/app/sdk-connection-string.md) about Application Insights connection strings.
5855
>
5956
60-
1. Second, you enable Application Insights logging for your API or APIs.
57+
> [!NOTE]
58+
> If your Application Insights resource is in a different tenant, then you must create the logger using the [REST API](#create-a-connection-using-the-rest-api-bicep-or-arm-template) or related tools as shown in a later section of this article.
59+
60+
1. Second, enable Application Insights logging for your API or APIs.
6161

6262
In this article, you enable Application Insights logging for your API using the Azure portal. API Management configures a *diagnostic* resource for the API.
6363

@@ -66,6 +66,10 @@ The following are high level steps for this scenario.
6666

6767
Follow these steps to use the Azure portal to create a connection between Application Insights and API Management.
6868

69+
> [!NOTE]
70+
> Where possible, Microsoft recommends using connection string with managed identity credentials for enhanced security. To configure these credentials, use the [REST API](#create-a-connection-using-the-rest-api-bicep-or-arm-template) or related tools as shown in a later section of this article.
71+
72+
6973
1. Navigate to your **Azure API Management service instance** in the **Azure portal**.
7074
1. Select **Application Insights** from the menu on the left.
7175
1. Select **+ Add**.
@@ -87,28 +91,32 @@ Follow these steps to use the Azure portal to create a connection between Applic
8791
8892
## Create a connection using the REST API, Bicep, or ARM template
8993

90-
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.
94+
Follow these steps to use the REST API, Bicep, or ARM template to create an Application Insights logger for your API Management instance. You can configure a logger that uses connection string with managed identity credentials (recommended), or a logger that uses only a connection string.
9195

92-
### Logger with connection string credentials
96+
### Logger with connection string with managed identity credentials (recommended)
97+
98+
See the [prerequisites](#prerequisites) for using an API Management managed identity.
9399

94100
The Application Insights connection string appears in the **Overview** section of your Application Insights resource.
95101

102+
#### Connection string with system-assigned managed identity
103+
96104
#### [REST API](#tab/rest)
97105

98106
Use the API Management [Logger - Create or Update](/rest/api/apimanagement/current-preview/logger/create-or-update) REST API with the following request body.
99107

100-
If you are configuring the logger for a workspace, use the [Workspace Logger - Create or Update](/rest/api/apimanagement/workspace-logger/create-or-update?view=rest-apimanagement-2023-09-01-preview&preserve-view=true) REST API.
101-
102108
```JSON
103109
{
104110
"properties": {
105111
"loggerType": "applicationInsights",
106-
"description": "adding a new logger with connection string",
112+
"description": "Application Insights logger with system-assigned managed identity",
107113
"credentials": {
108-
"connectionString":"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;..."
114+
"connectionString":"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
115+
"identityClientId":"SystemAssigned"
109116
}
110117
}
111118
}
119+
112120
```
113121

114122
#### [Bicep](#tab/bicep)
@@ -121,9 +129,10 @@ resource aiLoggerWithSystemAssignedIdentity 'Microsoft.ApiManagement/service/log
121129
parent: '<APIManagementInstanceName>'
122130
properties: {
123131
loggerType: 'applicationInsights'
124-
description: 'Application Insights logger with connection string'
132+
description: 'Application Insights logger with system-assigned managed identity'
125133
credentials: {
126134
connectionString: 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...'
135+
identityClientId: 'systemAssigned'
127136
}
128137
}
129138
}
@@ -140,19 +149,17 @@ Include a JSON snippet similar to the following in your Azure Resource Manager t
140149
"name": "ContosoLogger1",
141150
"properties": {
142151
"loggerType": "applicationInsights",
143-
"description": "Application Insights logger with connection string",
152+
"description": "Application Insights logger with system-assigned managed identity",
144153
"resourceId": "<ApplicationInsightsResourceID>",
145154
"credentials": {
146-
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;..."
147-
},
155+
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
156+
"identityClientId": "SystemAssigned"
157+
}
148158
}
149159
}
150160
```
151161
---
152-
153-
### Logger with system-assigned managed identity credentials
154-
155-
See the [prerequisites](#prerequisites) for using an API Management managed identity.
162+
#### Connection string with user-assigned managed identity
156163

157164
#### [REST API](#tab/rest)
158165

@@ -162,10 +169,10 @@ Use the API Management [Logger - Create or Update](/rest/api/apimanagement/curre
162169
{
163170
"properties": {
164171
"loggerType": "applicationInsights",
165-
"description": "adding a new logger with system-assigned managed identity",
172+
"description": "Application Insights logger with user-assigned managed identity",
166173
"credentials": {
167174
"connectionString":"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
168-
"identityClientId":"SystemAssigned"
175+
"identityClientId":"<ClientID>"
169176
}
170177
}
171178
}
@@ -174,18 +181,18 @@ Use the API Management [Logger - Create or Update](/rest/api/apimanagement/curre
174181

175182
#### [Bicep](#tab/bicep)
176183

177-
Include a snippet similar to the following in your Bicep template.
184+
Include a snippet similar the following in your Bicep template.
178185

179186
```Bicep
180-
resource aiLoggerWithSystemAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-08-01' = {
187+
resource aiLoggerWithUserAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-08-01' = {
181188
name: 'ContosoLogger1'
182189
parent: '<APIManagementInstanceName>'
183190
properties: {
184191
loggerType: 'applicationInsights'
185-
description: 'Application Insights logger with system-assigned managed identity'
192+
description: 'Application Insights logger with user-assigned managed identity'
186193
credentials: {
187194
connectionString: 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...'
188-
identityClientId: 'systemAssigned'
195+
identityClientId: '<ClientID>'
189196
}
190197
}
191198
}
@@ -202,52 +209,55 @@ Include a JSON snippet similar to the following in your Azure Resource Manager t
202209
"name": "ContosoLogger1",
203210
"properties": {
204211
"loggerType": "applicationInsights",
205-
"description": "Application Insights logger with system-assigned managed identity",
212+
"description": "Application Insights logger with user-assigned managed identity",
206213
"resourceId": "<ApplicationInsightsResourceID>",
207214
"credentials": {
208215
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
209-
"identityClientId": "SystemAssigned"
216+
"identityClientId": "<ClientID>"
210217
}
211218
}
212219
}
213220
```
214221
---
215-
### Logger with user-assigned managed identity credentials
216222

217-
See the [prerequisites](#prerequisites) for using an API Management managed identity.
223+
### Logger with connection string credentials only
224+
225+
The Application Insights connection string appears in the **Overview** section of your Application Insights resource.
218226

219227
#### [REST API](#tab/rest)
220228

221229
Use the API Management [Logger - Create or Update](/rest/api/apimanagement/current-preview/logger/create-or-update) REST API with the following request body.
222230

231+
If you are configuring the logger for a workspace, use the [Workspace Logger - Create or Update](/rest/api/apimanagement/workspace-logger/create-or-update?view=rest-apimanagement-2023-09-01-preview&preserve-view=true) REST API.
232+
223233
```JSON
224234
{
225235
"properties": {
226236
"loggerType": "applicationInsights",
227-
"description": "adding a new logger with user-assigned managed identity",
237+
"description": "Application Insights logger with connection string",
228238
"credentials": {
229-
"connectionString":"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
230-
"identityClientId":"<ClientID>"
239+
"connectionString":"InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;..."
231240
}
232241
}
233242
}
234-
235243
```
236244

237245
#### [Bicep](#tab/bicep)
238246

239-
Include a snippet similar the following in your Bicep template.
247+
Include a snippet similar to the following in your Bicep template.
248+
249+
If you are configuring the logger for a workspace, create a `Microsoft.ApiManagement/service.workspace/loggers@2023-09-01-preview` resource instead.
250+
240251

241252
```Bicep
242-
resource aiLoggerWithUserAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-08-01' = {
253+
resource aiLoggerWithSystemAssignedIdentity 'Microsoft.ApiManagement/service/loggers@2022-08-01' = {
243254
name: 'ContosoLogger1'
244255
parent: '<APIManagementInstanceName>'
245256
properties: {
246257
loggerType: 'applicationInsights'
247-
description: 'Application Insights logger with user-assigned managed identity'
258+
description: 'Application Insights logger with connection string'
248259
credentials: {
249260
connectionString: 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...'
250-
identityClientId: '<ClientID>'
251261
}
252262
}
253263
}
@@ -257,24 +267,27 @@ resource aiLoggerWithUserAssignedIdentity 'Microsoft.ApiManagement/service/logge
257267

258268
Include a JSON snippet similar to the following in your Azure Resource Manager template.
259269

270+
If you are configuring the logger for a workspace, create a `Microsoft.ApiManagement/service.workspace/loggers` resource and set `apiVersion` to `2023-09-01-preview` instead.
271+
272+
260273
```JSON
261274
{
262275
"type": "Microsoft.ApiManagement/service/loggers",
263276
"apiVersion": "2022-08-01",
264277
"name": "ContosoLogger1",
265278
"properties": {
266279
"loggerType": "applicationInsights",
267-
"description": "Application Insights logger with user-assigned managed identity",
280+
"description": "Application Insights logger with connection string",
268281
"resourceId": "<ApplicationInsightsResourceID>",
269282
"credentials": {
270-
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;...",
271-
"identityClientId": "<ClientID>"
272-
}
283+
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://xxxx.applicationinsights.azure.com/;..."
284+
},
273285
}
274286
}
275287
```
276288
---
277289

290+
278291
## Enable Application Insights logging for your API
279292

280293
Use the following steps to enable Application Insights logging for an API. You can also enable Application Insights logging for all APIs.
@@ -328,7 +341,7 @@ Application Insights receives:
328341
> See [Application Insights limits](../azure-monitor/service-limits.md#application-insights) for information about the maximum size and number of metrics and events per Application Insights instance.
329342
330343
## Emit custom metrics
331-
You can emit [custom metrics](../azure-monitor/essentials/metrics-custom-overview.md) to Application Insights from your API Management instance. API Management emits custom metrics using the [emit-metric](emit-metric-policy.md) policy.
344+
You can emit [custom metrics](../azure-monitor/essentials/metrics-custom-overview.md) to Application Insights from your API Management instance. API Management emits custom metrics using policies such as [emit-metric](emit-metric-policy.md) and [azure-openai-emit-token-metric](azure-openai-emit-token-metric-policy.md). The following section uses the `emit-metric` policy as an example.
332345

333346
> [!NOTE]
334347
> Custom metrics are a [preview feature](../azure-monitor/essentials/metrics-custom-overview.md) of Azure Monitor and subject to [limitations](../azure-monitor/essentials/metrics-custom-overview.md#design-limitations-and-considerations).
@@ -362,7 +375,7 @@ To emit custom metrics, perform the following configuration steps.
362375
363376
### Limits for custom metrics
364377
365-
Azure Monitor imposes [usage limits](../azure-monitor/essentials/metrics-custom-overview.md#quotas-and-limits) for custom metrics that may affect your ability to emit metrics from API Management. For example, Azure Monitor currently sets a limit of 10 dimension keys per metric, and a limit of 50,000 total active time series per region in a subscription (within a 12 hour period).
378+
Azure Monitor imposes [usage limits](../azure-monitor/essentials/metrics-custom-overview.md#quotas-and-limits) for custom metrics that may affect your ability to emit metrics from API Management. For example, Azure Monitor currently sets a limit of 10 dimension keys per metric, and a limit of 50,000 total active time series per region in a subscription (within a 12 hour period).
366379
367380
These limits have the following implications for configuring custom metrics in API Management:
368381
@@ -404,4 +417,4 @@ Addressing the issue of telemetry data flow from API Management to Application I
404417
405418
+ Learn more about [Azure Application Insights](../azure-monitor/app/app-insights-overview.md).
406419
+ Consider [logging with Azure Event Hubs](api-management-howto-log-event-hubs.md).
407-
+ Learn about visualizing data from Application Insights using [Azure Managed Grafana](visualize-using-managed-grafana-dashboard.md)
420+
+ Learn about visualizing data from Application Insights using [Azure Managed Grafana](visualize-using-managed-grafana-dashboard.md)

0 commit comments

Comments
 (0)