Skip to content

Commit d183bc5

Browse files
Merge pull request #233348 from dlepow/emit
[APIM] Update emit custom metrics details
2 parents c17adb8 + 3ba69c1 commit d183bc5

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

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

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ author: dlepow
77

88
ms.service: api-management
99
ms.tgt_pltfrm: na
10-
ms.topic: article
11-
ms.date: 10/27/2021
10+
ms.topic: how-to
11+
ms.date: 04/03/2023
1212
ms.author: danlep
13+
ms.custom: engagement-fy23
1314

1415
---
1516

@@ -55,9 +56,14 @@ To use Application Insights, [create an instance of the Application Insights ser
5556
5657
## Enable Application Insights logging for your API
5758

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

69-
> [!WARNING]
70-
> Overriding the default **Number of payload bytes to log** value **0** may significantly decrease the performance of your APIs.
75+
> [!WARNING]
76+
> Overriding the default **Number of payload bytes to log** value **0** may significantly decrease the performance of your APIs.
7177
7278
1. Select **Save**.
7379
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 +89,7 @@ You can specify loggers on different levels:
8389
+ A logger for all APIs
8490

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

8995
## What data is added to Application Insights
@@ -97,15 +103,41 @@ Application Insights receives:
97103
| *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> |
98104
| *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. |
99105

100-
### Emit custom metrics
101-
You can emit custom metrics by configuring the [`emit-metric`](emit-metric-policy.md) policy.
106+
> [!NOTE]
107+
> 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.
102108
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.
109+
## Emit custom metrics
110+
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.
106111

107112
> [!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.
113+
> Custom metrics are a preview feature of Azure Monitor and subject to limitations.
114+
115+
To emit custom metrics, perform the following configuration steps.
116+
117+
1. Enable **Custom metrics (Preview)** with custom dimensions in your Application Insights instance.
118+
119+
1. Navigate to your Application Insights instance in the portal.
120+
1. In the left menu, select **Usage and estimated costs**.
121+
1. Select **Custom metrics (Preview)** > **With dimensions**.
122+
1. Select **OK**.
123+
124+
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](/rest/api/apimanagement/current-ga/diagnostic/create-or-update) REST API. For example:
125+
126+
```http
127+
PUT https://management.azure.com/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ApiManagement/service/{APIManagementServiceName}/diagnostics/applicationinsights
128+
129+
{
130+
[...]
131+
{
132+
"properties": {
133+
"loggerId": "/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.ApiManagement/service/{APIManagementServiceName}/loggers/{ApplicationInsightsLoggerName}",
134+
"metrics": true
135+
[...]
136+
}
137+
}
138+
```
139+
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.
140+
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.
109141
110142
## Performance implications and log sampling
111143

0 commit comments

Comments
 (0)