Emit custom metrics

APPLIES TO: All API Management tiers

The emit-metric policy sends custom metrics in the specified format to Application Insights.

Note

Note

Set the policy's elements and child elements in the order provided in the policy statement. Learn more about how to set or edit API Management policies.

Policy statement

<emit-metric name="name of custom metric" value="value of custom metric" namespace="metric namespace"> 
    <dimension name="dimension name" value="dimension value" /> 
</emit-metric> 

Attributes

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

Elements

Element Description Required
dimension Add one or more of these elements for each dimension included in the custom metric. Yes

dimension attributes

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

Default dimension names that may be used without value

  • API ID
  • Operation ID
  • Product ID
  • User ID
  • Subscription ID
  • Location ID
  • Gateway ID

Usage

Usage notes

  • You can configure at most 10 custom dimensions for this policy.

  • Invoking the emit-metric policy counts toward the usage limits for custom metrics per region in a subscription. Learn more

Example

The following example sends a custom metric to count the number of API requests along with user ID, client IP, and API ID as custom dimensions.

<policies>
  <inbound>
    <emit-metric name="Request" value="1" namespace="my-metrics"> 
        <dimension name="User ID" /> 
        <dimension name="Client IP" value="@(context.Request.IpAddress)" /> 
        <dimension name="API ID" /> 
    </emit-metric> 
  </inbound>
  <outbound>
  </outbound>
</policies>

For more information about working with policies, see: