title | description | services | author | ms.service | ms.topic | ms.date | ms.author | ms.custom |
---|---|---|---|---|---|---|---|---|
Azure API Management policy reference - emit-metric | Microsoft Docs |
Reference for the emit-metric policy available for use in Azure API Management. Provides policy usage, settings, and examples. |
api-management |
dlepow |
azure-api-management |
reference |
04/01/2025 |
danlep |
engagement-fy23 |
[!INCLUDE api-management-availability-all-tiers]
The emit-metric
policy sends custom metrics in the specified format to Application Insights.
[!INCLUDE api-management-policy-generic-alert]
[!INCLUDE api-management-custom-metrics-limits]
- Your API Management instance must be integrated with Application insights. For more information, see How to integrate Azure API Management with Azure Application Insights.
- Enable Application Insights logging for your APIs.
- Enable custom metrics with dimensions in Application Insights. For more information, see Emit custom metrics.
<emit-metric name="name of custom metric" value="value of custom metric" namespace="metric namespace">
<dimension name="dimension name" value="dimension value" />
</emit-metric>
Attribute | Description | Required | Default value |
---|---|---|---|
name | A string. Name of custom metric. Policy expressions aren't allowed. | Yes | N/A |
namespace | A string. Namespace of custom metric. Policy expressions aren't allowed. | No | API Management |
value | Value of custom metric expressed as a double. Policy expressions are allowed. | No | 1 |
Element | Description | Required |
---|---|---|
dimension | Add one or more of these elements for each dimension included in the custom metric. | Yes |
Attribute | Description | Required | Default value |
---|---|---|---|
name | A string or policy expression. Name of dimension. | Yes | N/A |
value | A string or policy expression. Value of dimension. Can only be omitted if name matches one of the default dimensions. If so, value is provided as per dimension name. |
No | N/A |
[!INCLUDE api-management-emit-metric-dimensions]
- Policy sections: inbound, outbound, backend, on-error
- Policy scopes: global, workspace, product, API, operation
- Gateways: classic, v2, consumption, self-hosted, workspace
- You can configure at most 10 custom dimensions for this policy.
The following example sends a custom metric to count the number of API requests along with API ID as a default dimension.
<policies>
<inbound>
<emit-metric name="Request" value="1" namespace="my-metrics">
<dimension name="API ID" />
</emit-metric>
</inbound>
<outbound>
</outbound>
</policies>
[!INCLUDE api-management-policy-ref-next-steps]