Skip to main content
Create functions in Application Insights through REST API
  1. Posts/

Create functions in Application Insights through REST API

·140 words·1 min
Christoph Petersen
Author
Christoph Petersen

I’ve learned about a “hidden feature” recently that enables some cool scenarios. Log Analytics or Azure Data Explorer aficionados will probably know all about functions already but for Application Insights this has not been documented yet and is not visible through the Azure portal.

List all functions
#

GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Insights/components/{applicationName}/analyticsItems?api-version=2015-05-01&includeContent=true&scope=shared&type=function

Create or update function
#

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Insights/components/{applicationName}/analyticsItems/item?api-version=2015-05-01

Request Body
#

NameRequiredTypeDescription
scopetruestring
typetruestring
nametruestringName of the function. Function name must begin with a letter and contain only letters, numbers and underscores.
contenttruestringQuery that is executed when the function is calledpropertiestrueobjectFunction properties (e.g. alias)

Sample
#

Request

PUT https://management.azure.com/subscriptions/my-subscription-id/resourceGroups/my-resource-group/providers/Microsoft.Insights/components/my-application/analyticsItems/item?api-version=2015-05-01

Request body

{
    "scope": "shared",
    "type": "function",
    "name": "myfunction",
    "content": "traces | count",
    "properties": {
        "functionAlias": "myfunction"
    }
}

Delete function
#

DELETE https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Insights/components/{applicationName}/analyticsItems/item?api-version=2015-05-01&includeContent=true&scope=shared&type=function&name={functionName}

Sample
#

Request

DELETE https://management.azure.com/subscriptions/my-subscription-id/resourceGroups/my-resource-group/providers/Microsoft.Insights/components/my-application/analyticsItems/item?api-version=2015-05-01&includeContent=true&scope=shared&type=function&name=myfunction

Related

Data volume estimation for Log Analytics

·274 words·2 mins
[UPDATE 02/12/2019] There has been changes to the way Log Analytics tracks usage data. Check out the post on the updated mechanisms.

Alert on requests/s for Azure App Service

·184 words·1 min
A customer of mine had the following rule configured: It was his expectation that this rule would be triggered when in the last five minutes at some point more that 200 requests/s were being made to the App Service. Unfortunately this is not the case. The rule will sum the number of requests for the last five minutes and if that number is > 200 the rule will trigger.