Log to Application Insights from Microsoft Flow or Logic Apps
jlattimer
24,558
If you haven’t checked out Azure Application Insights yet you might want to give it a look. It’s got a lot to offer in terms of logging, monitoring, alerting, multi-colored charts and graphs, etc. Microsoft provides libraries for several languages to make logging things easier but ultimately you’re just making HTTP requests to a public endpoint.
There isn't a connector which lets you write to Application Insights but logging can be done fairly easily with a HTTP Action. I’d suggest referencing the telemetry API to figure out what options are available and how data needs to be structured as my examples won’t contain everything available.
Method: POST
Uri: https://dc.services.visualstudio.com/v2/track
In each request body:
Body:
Body:
Body:
Body:
Recommended replacements, doesn’t need to follow this format exactly
if(equals(outputs('Test_HTTP')['statusCode'], 200),true, false)
The Azure Function to calculate duration looks like this:
And that’s about it, you should start seeing results in your Application Insights instance.
https://github.com/jlattimer/MSFlowAppInsights
There isn't a connector which lets you write to Application Insights but logging can be done fairly easily with a HTTP Action. I’d suggest referencing the telemetry API to figure out what options are available and how data needs to be structured as my examples won’t contain everything available.
Overview
All the requests will be:Method: POST
Uri: https://dc.services.visualstudio.com/v2/track
In each request body:
- Replace “time” with the Flow utcNow() function
- Replace "00000000-0000-0000-0000-000000000000" with your Application Insights key
- Replace “properties” with any custom key/value pairs you wish to track
Trace
Diagnostic log messagesBody:
- Replace “message” with whatever you want to trace
Event
User actions and other eventsBody:
- Replace “name” with the name of the event
- Replace inside “measurements” with a measurement name (string) and value (numeric) or set to null if not using
Metric
Performance measurements such as queue lengths not related to specific eventsBody:
- Replace inside “metrics” with a metric name (string), kind (integer), value (double) – see API for additional details
Dependency
Logging the duration and frequency of calls to external components that your app depends onBody:
Recommended replacements, doesn’t need to follow this format exactly
- Replace “id” with an id of some sort - Application Insights libraries have a way of generating an id if you care to track it down
- Replace “name” with the HTTP verb and Url Absolute Path
- Replace “resultCode” with the HTTP Status Code
- Replace “duration” with the elapsed time
- Replace “success” with true/false
- Replace “data” with the HTTP verb and Url
- Replace “target” with Url Host
- Replace “type” with something describing the type of request
if(equals(outputs('Test_HTTP')['statusCode'], 200),true, false)
The Azure Function to calculate duration looks like this:
And that’s about it, you should start seeing results in your Application Insights instance.
https://github.com/jlattimer/MSFlowAppInsights
*This post is locked for comments