Skip to content

Commit 725ae79

Browse files
committed
[APIM] Update emit custom metrics details
1 parent 19e834f commit 725ae79

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: dlepow
88
ms.service: api-management
99
ms.tgt_pltfrm: na
1010
ms.topic: article
11-
ms.date: 10/27/2021
11+
ms.date: 04/03/2023
1212
ms.author: danlep
1313

1414
---
@@ -55,9 +55,14 @@ To use Application Insights, [create an instance of the Application Insights ser
5555
5656
## Enable Application Insights logging for your API
5757

58+
Use the following steps to enable Application Insights logging for an API. You can also enable Application Insights logging for all APIs.
59+
5860
1. Navigate to your **Azure API Management service instance** in the **Azure portal**.
5961
1. Select **APIs** from the menu on the left.
6062
1. Click on your API, in this case **Demo Conference API**. If configured, select a version.
63+
64+
> [!TIP]
65+
> To enable logging for all APIs, select **All APIs**.
6166
1. Go to the **Settings** tab from the top bar.
6267
1. Scroll down to the **Diagnostics Logs** section.
6368
:::image type="content" source="media/api-management-howto-app-insights/apim-app-insights-api-1.png" alt-text="App Insights logger":::
@@ -66,8 +71,8 @@ To use Application Insights, [create an instance of the Application Insights ser
6671
1. Input **100** as **Sampling (%)** and select the **Always log errors** checkbox.
6772
1. Leave the rest of the settings as is. For details about the settings, see [Diagnostic logs settings reference](diagnostic-logs-reference.md).
6873

69-
> [!WARNING]
70-
> Overriding the default **Number of payload bytes to log** value **0** may significantly decrease the performance of your APIs.
74+
> [!WARNING]
75+
> Overriding the default **Number of payload bytes to log** value **0** may significantly decrease the performance of your APIs.
7176
7277
1. Select **Save**.
7378
1. Behind the scenes, a [Diagnostic](/rest/api/apimanagement/current-ga/diagnostic/create-or-update) entity named `applicationinsights` is created at the API level.
@@ -83,7 +88,7 @@ You can specify loggers on different levels:
8388
+ A logger for all APIs
8489

8590
Specifying *both*:
86-
- By default, the single API logger (more granular level) will override the one for all APIs.
91+
- By default, the single API logger (more granular level) overrides the one for all APIs.
8792
- If the loggers configured at the two levels are different, and you need both loggers to receive telemetry (multiplexing), please contact Microsoft Support.
8893

8994
## What data is added to Application Insights
@@ -97,15 +102,41 @@ Application Insights receives:
97102
| *Exception* | For every failed request: <ul><li>Failed because of a closed client connection</li><li>Triggered an *on-error* section of the API policies</li><li>Has a response HTTP status code matching 4xx or 5xx</li></ul> |
98103
| *Trace* | If you configure a [trace](trace-policy.md) policy. <br /> The `severity` setting in the `trace` policy must be equal to or greater than the `verbosity` setting in the Application Insights logging. |
99104

100-
### Emit custom metrics
101-
You can emit custom metrics by configuring the [`emit-metric`](emit-metric-policy.md) policy.
105+
> [!NOTE]
106+
> 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.
102107
103-
To make Application Insights pre-aggregated metrics available in API Management, you'll need to manually enable custom metrics in the service.
104-
1. Use the [`emit-metric`](emit-metric-policy.md) policy with the [Create or Update API](/rest/api/apimanagement/current-ga/api-diagnostic/create-or-update).
105-
1. Add `"metrics":true` to the payload, along with any other properties.
108+
## Emit custom metrics
109+
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.
106110

107111
> [!NOTE]
108-
> 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.
112+
> Custom metrics are a preview feature of Azure Monitor and subject to limitations.
113+
114+
To emit custom metrics, perform the following configuration steps.
115+
116+
1. Enable **Custom metrics (Preview)** with custom dimensions in your Application Insights instance.
117+
118+
1. Navigate to your Application Insights instance in the portal.
119+
1. In the left menu, select **Usage and estimated costs**.
120+
1. Select **Custom metrics (Preview)** > **With dimensions**.
121+
1. Select **OK**.
122+
123+
1. Add the `"metrics": true` property to the `applicationInsights` diagnostic entity that's configured in API Management. Currently you must add this property using the API Management [Diagnostic - Create or Update](learn.microsoft.com/rest/api/apimanagement/current-ga/diagnostic/create-or-update) REST API. For example:
124+
125+
```http
126+
PUT https://management.azure.com/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ApiManagement/service/{APIManagementServiceName}/diagnostics/applicationinsights
127+
128+
{
129+
[...]
130+
{
131+
"properties": {
132+
"loggerId": "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ApiManagement/service/{APIManagementServiceName}/loggers/{ApplicationInsightsLoggerName}",
133+
"metrics": true
134+
[...]
135+
}
136+
}
137+
```
138+
1. Ensure that the Application Insights logger is configured at the scope you intend to emit custom metrics (either all APIs, or a single API). For more information, see [Enable Application Insights logging for your API](#enable-application-insights-logging-for-your-api), earlier in this article
139+
1. Configure the `emit-metric` policy at a scope where Application Insights logging is configured (either all APIs, or a single API) and is enabled for custom metrics. For policy details, see the [`emit-metric`](emit-metric-policy.md) policy reference.
109140
110141
## Performance implications and log sampling
111142

0 commit comments

Comments
 (0)