Add Health Heartbeat to App Insights SDK
Proposal: Health Heartbeat
We would like to add a health 'heartbeat' to the Application Insights SDK. We believe that by adding this feature to the App Insights SDK we can enable more complete support scenarios for our customers.
The new information that the SDK will provide to the data stream will be very low cost, and have high value for supporting the use of Application Insights within a deployed service or application. All of the data associated with the health heartbeat would be stored in the customer's data store, adding to their overall monitoring costs but providing extra value with regards to maintenance and support.
Please comment on the proposal below, we are happy to hear feedback from the community!
Proposed new documentation regarding the Health Heartbeat:
Application Insights Diagnostics Telemetry
The
DiagnosticsTelemetryModuleworks at the Application Insights tooling level exclusively. The two things that it will emit will be (1) reporting errors in the Application Insights instrumentation code itself, and (2) report a 'health heartbeat' to aid in diagnostic efforts.When reporting errors, for example, if the code cannot access performance counters or if an
ITelemetryInitializerthrows an exception. Trace telemetry tracked by this module appears in the Diagnostic Search. Sends diagnostic data to dc.services.vsallin.net.+The health heartbeat monitoring information is set to send a minimal amount of data to track general health information on your application as it would pertain to the Application Insights tooling itself. It will log information like platform versions, SDK versions, and other such data, and is open to extension should your application have specific health-heartbeat requirements.
The data is sent at very infrequent intervals and is by default sent once every n (TBD: determine default n) seconds. All data would be stored with your application telemetry and can be queried and used for support or other purposes later.
Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModuleMicrosoft.ApplicationInsightsNuGet package. If you only install this package, theApplicationInsights.configfile is not automatically created
Proposed Enhancements
We will extend the functionality within the DiagnosticsTelemetryModule to include this health heartbeat functionality. The module have a new set of classes added that will:
-
Perform heartbeat actions on a timed schedule
- The user can configure the rate at which these heartbeat payloads are sent in the
ApplicationInsights.configfile.
- The user can configure the rate at which these heartbeat payloads are sent in the
-
Read a specific set of information on the running application that will be added as properties to the heartbeat message
- This will include adding any extended information that the user has provided that they want appended to the message
-
We will provide an interface & registration to the user of the system that will allow the addition of any further telemetry to the heartbeat message
- This will include pruning out message elements that the user wants excluded
- Configuration file elements will be added to allow the user to customize the payload of the health heartbeat to their liking.
-
Set the status of the message to 0 if all elements are successfully read, and no obvious failure conditions are met
- In the provided interface & registration for extending the health heartbeat for users, failure status can also be affected
-
Send the message to the App Insights component
-
One metric will be sent to every iKey named in
ApplicationInsights.config -
Allow the user to completely remove the functionality as well, by removing it from the
ApplicationInsights.configfile.
-
The Message & Payload
The message that will deliver this heartbeat will be an Application Insights metric type, where we will set the metric value to 0 for successful health heartbeat delivery, and increment this value by one for each field in the payload that represents a potentially unhealthy status.
The data that will be included in the health heartbeat by default will be the following...
Fields:
| Name | Type | Example Value | Description |
|---|---|---|---|
| osType | string | "Windows" | operating system of service/application instrumented |
| location | string | "EastUS" | string representing the location of the Azure region the VM is running in |
| name | string | "VM01" | name of the VM running this instance of your application |
| offer | string | "WIN10" | name of the VM image if it was deployed from the VM image gallery |
| platformFaultDomain | string | "0" | fault domain the VM image is running in |
| platformUpdateDomain | string | "0" | update domain the VM image is running |
| publisher | string | "Microsoft" | publisher of the VM image |
| sku | string | "10.0" | sku of the VM image |
| version | string | "7.3.2" | version of the VM image |
| vmId | string | "59a7f16f-a821-414b-abfe-da0fba8ab6b4" | id of the VM instance application is running on |
| vmSize | string | "Standard_DS2" | VM size application is running on |
| targetFramework | string | ".NET Framework 4.6.2" | The target framework the application was compiled against (to the best of our ability) |
| runtimeFramework | string | ".NET Framework 4.6.2" | Runtime framework version down to patch |
| appinsightsSdkVer | string | "The current Application Insights SDK elements present, and their version numbers |
Potential Fields (TBD to include these or not):
| Name | Type | Example Value | Description |
|---|---|---|---|
| version | string | "1.0" | The version of the health heartbeat packet 'schema' |
| time | time | 2017-03-22T12:34:59.12345Z | Timestamp of the heartbeat event in UTC |
| seqnum | int64 | 1004 | index for a specific message enumerating the order of health heartbeat events sent |
| unhealthyItem | string[] | "userField01","userfield02" | name of any user fields that are reporting 'unhealthy' status |
| processId | int | 7580 | The process id of the application as reported by the underlying OS |
Failure Status Evaluations
Failure status will be set based on the following criteria by default:
- A user extension is present that will affect the failure status
Interfaces Available for Extension
IHealthHeartbeatProperty will be implemented by consumers of the Telemetry client and named in the ApplicationInsights.config file.
- Users can supply a set of name-value pairs that will be appended to the payload of the health heartbeat message
- Users can indicate that any of their properties represent unhealthy conditions have been met in the payload they are adding to the message
Note, the DiagnosticsTelemetryModule will ensure no conflicting property names are appended into the payload. Upon encountering such collisions, the name of the module adding the property will be prepended to the property name. If collisions are still present after performing this, an incremented number will be added as the suffix of the property name until there are no collisions.
The class that implements the IHealthHeartbeatProperty will undergo a registration in the DiagnosticTelemetryModule and will be added to the payload upon successful registration. The user can also register their class during runtime if they wish, but will miss out on any health heartbeat metrics sent prior to calling RegisterHeartbeatPayload.
Configuration File Elements Added
We will add a section to the ApplicationInsights.config file that will allow the users to do the following:
- Change the cadence at which the health heartbeat message is sent
- Remove specific payload fields that are sent in the health heartbeat message
- Name the custom extensions that the user has created to alter/add payload information with, and that must be loaded at runtime
Updates:
- Added processId to the list of potential fields in the heartbeat payload requested by @cijothomas
A heartbeat monitor is something I need to implement for what I'm developing at the moment. What's the guesstimate ETA on this?
@aguvenli I'm currently new to the team and learning how to affect the SDK. I would put the ETA on getting a beta version of this in the 2-3 week range, shipped version after that.
edit: What would be interesting to have included in this for your scenario(s)?
Am rethinking the registration of user-defined payload extensions. Instead of naming them in the config file and having them get loaded at runtime via reflection, just have the user register them in their own code instead upon initialization.
Id add my vote to this. Currently building numerous windows services which id like to monitor their running state, which I believe this would allow?
@d3r3kk the ability to change the user-defined payload during runtime would provide me metrics on failure, i.e. what was the apps state before it doesn't call home again.
@d3r3kk a few comments/questions:
What's the advantage of doing this in the SDK versus letting apps do it themselves with, for example, a periodic timer calling _telemetryClient.TrackEvent("Heartbeat") ?
Is there going to be a special Azure Portal view for heart-beat events? What about support for live stream?
We already have "Availability" events. How does this compare?
How are you getting the values for the Azure-specific payload properties (location/offer/VMsize/fault-domain etc.)? Can they all be queried by running code in the user's app? Or is there some Azure fabric "magic" that can supply them?
I'm wondering whether this belongs in the base SDK at all. Is there anything in the proposal that requires access to base SDK internals? Perhaps it could be delivered as a separate Nuget package.
@pharring and @matt-shepherd thanks for the comments. I'll try to answer your queries the best I can, but ultimately @SergeyKanzhelev or @Dmitry-Matveev will have the best ideas for this feature, so I'll let them chime in if they wish as well.
What's the advantage of doing this in the SDK versus letting apps do it themselves...
I believe the idea is to provide everyone with a heartbeat item that they can make use of however they like, without having to implement anything on their own. Of course, we need to keep it simple and extensible while allowing the user full control at the same time.
Is there going to be a special Azure Portal view for heart-beat events? What about support for live stream?
I believe the idea is to support a feature on the portal eventually, but nothing specific has been discussed yet. @SergeyKanzhelev will have a better answer here I am sure. As for Live Metrics Stream, since the proposed payload is simply a MetricTelemetry item we can filter for this heartbeat specifically via the new filtering functionality (available in the LMS today).
We already have "Availability" events. How does this compare?
Availability events, if I am understanding them correctly, currently are only used to measure availability via the WebTest functionality we expose in the portal. I see this as a more of a 'pull' availability function where the proposal here would be more of a 'push' one, and would be generic in terms of type of application. Also, when we were discussing the implementation of this feature we felt that overloading this type might confuse existing UX elements that are looking for this type today.
How are you getting the values for the Azure-specific payload properties...
The intent here is to get the Azure-specific ones (when they are available) from the Azure Instance Metadata Service.
Can they all be queried by running code in the user's app...
Yes, as per the link above.
I'm wondering whether this belongs in the base SDK at all...
I think the primary focus here is the 'you get this for free' and it comes alongside/within the DiagnosticsTelemetryModule that is already in the base. The idea was that heartbeat data is immediately emitted and by default turned on (while still being controllable by the user) to help in user support scenarios, following the same idea behind the DiagnosticsTelemetryModule.
@d3r3kk thanks. Especially thanks for the links to the Azure Instance Metadata Service. I was unaware of it. Of course, that works only on Azure VMs and not on Azure App Service (I tried it) or on-prem machines.
Of course it's up to you what you put in the base SDK. My mental test for what goes there is "Does any reasonable implementation this require internal knowledge of types in the base SDK?" and, as I understand it, this proposal fails that test. Perhaps the fact that it uses the "vsallin.net" endpoint is sufficient grounds, though. I assume that endpoint is special - although I don't know what else it's used for.
I mentioned availability events because it seems like a heartbeat is a sort of availability signal - albeit originating from within the app itself, rather than triggered by an external health-check. I don't know how heavily they're used today, but perhaps they could serve an enhanced purpose.
Anyway, I don't mean to derail the proposal. These are just things to think about. Good luck with the proposal.
Here are some thoughts:
- I do not think we'll send anything to vsallin.net and the documentation is probably incorrect on this point. This used to be staging endpoint long time ago but diagnostic module should've been sending to dc.services.visualstudio.com or applicationinsights.io addresses.
- We need to be careful with the outgoing calls to fetch Azure information via external services - these calls will be monitored by our own Dependency collection and we might need to exclude those (and also differentiate between customer calls to that service and ours to keep only customer's calls).
- If we have a lot of Azure specific information retrieved in this way, we may want to check if other cloud providers expose similar functionality and leverage them / address point (2) for them as well.
- If we add OS / Name and other platform info into this event, we have a slight duplication as such information might be already present in all other telemetry items we collect.
- It might be better to go with the separate module if we plan to brand is as an extensible heartbeat the customer may want to use and extend instead of the internal heartbeat that our modules will need to use (we discussed it with @d3r3kk offline)
@pharring, the initial idea was to have a metric with custom dimensions for the internal SDK health tracking and heartbeat with the most common properties and add ability for any SDK module (like Quick Pulse) to add to this information and change state of this particular SDK instance from healthy to broken. The higher the value of the metric, the more issues SDK is having. This goes in hand with some internal monitoring tools being widely used in MSFT as far as I know. This slightly differentiates heartbeat approach from the availability telemetry.
With heartbeat, one can answer the questions like the following in our UI or analytics:
- Does SDK stop populating data if everything is calm?
- Are any of my SDKs misconfigured (does not solve the wrong iKey case :) )?
That should also help support engineers to access the customer environment and SDK states quickly. There was one more aspect to it (people asked for it offline) which I'm not certain is easy to address - use this telemetry to analyze if some issue has been fixed with the rollout of new SDK or similar self-monitoring approaches. So, that's still under the discussion at this point. Hope this helps!
Thanks @Dmitry-Matveev and @pharring for your feedback and comments. I am still ramping up my knowledge of this SDK and any feedback I can get from folks who know it better serves to make me more efficient at learning the important bits, faster.
I am still putting the code into a branch on my own forked repo to gain a better understanding of the SDK itself as well as the extension and how to best implement. I'm leaning a bit towards an extension module at the moment as including it within the base SDK doesn't seem to lend itself well to configuration that I want exposed.
From @Dmitry-Matveev comments:
- I do not think we'll send anything to vsallin.net...
I will put that as an item to resolve when I go about updating the documentation for this feature.
- We need to be careful with the outgoing calls to fetch Azure information via external services...
Ah yes I understand. Once I get to the part where I am querying for heartbeat payload data I will pay very close attention to this issue, hopefully I can provide a solution to anyone extending the feature as well in this regard (ie. What if someone wants to ping some website or make a request to some other service as part of the payload? We might want to allow them a simple way to 'mask' those call too?).
- If we have a lot of Azure specific information retrieved in this way, we may want to check if other(s)...
Agreed. Will keep that in mind.
- If we add OS / Name and other platform info into this event, we have a slight duplication...
Interesting. I will look to see how we gather that information elsewhere then and try and keep things consistent, and perhaps start a conversation on the value of adding that info to this payload.
- It might be better to go with the separate module...
As stated above, I'm still evaluating this and leaning somewhat towards the modularization idea. Will have a better idea in the next couple of days.
@d3r3kk You mentioned that this will be done through the DiagnosticsTelemetryModule. Is that a module that the user has to add explicitly to their config, or does it automatically and always get added?
Is the usage pattern such that customers would generally not have this module, but if something goes wrong, they would be encouraged to update their config, add this module and get more health information than they had before?
Does this proposal intend to change how telemetry is collected today? Today, AI SDK usage is monitored through fields (like sdkVersion) in every telemetry item's TelemetryContext. Can we use data gathered by this proposal to understand usage patterns instead?
My motivation for asking these questions is that I am evaluating what is the right option to monitor usage of Telemetry Initializers provided by Application Insights for Service Fabric Sdk. I initially thought about, using the internal Sdk Version field but that field already has a value filled in by the TelemetryModule that generated the telemetry - I don't want to blindly replace it in my TelemetryInitializer.
Health Heartbeat is a very good idea. We need this so much.
Our application ( a .net exe) runs at a lot of organizations non-stop as a windows service. It uses App Insights. Our requirement is finding out if the application stops running at any location. So if on one of our customers' servers application is not running e.g. because of a faulty update, we want to find out as soon as possible so we can respond.
Will this be possible with this feature?
@nizarq DiagnosticsTelemetryModule is added by default.
https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/220
@d3r3kk Once we are are done with the initial implementation, I guess you are planning to add other properties like os, vmsize etc. Could you also collect process-id as well as part of this? This was originally discussed here: https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/620
Thanks for the great questions all! Let me see if I can answer them...
From @nizarq:
Is the usage pattern such that customers would generally not have this module, but if something goes wrong, they would be encouraged to update their config, add this module and get more health information than they had before?
Actually, my intention is that the health heartbeat would be automatically added (it sends very little data) and if you wish, you can turn it off. The user can control the data that will be sent with each heartbeat in that they can turn fields off if they don't want to see them, or if they would like to reduce data to the smallest possible footprint and still get a heartbeat. Also, the user can opt to add custom fields to the heartbeat pulse as they wish.
Does this proposal intend to change how telemetry is collected today?
No. This is simply an enhancement to what we have today.
Can we use data gathered by this proposal to understand usage patterns instead?
This is not the intention for this feature, no. You can use Application Insights to understand usage patterns in other ways and with some other features we've provided in Azure.
From @etm-admin:
...if on one of our customers' servers application is not running e.g. because of a faulty update, we want to find out as soon as possible so we can respond. Will this be possible with this feature?
This is one way you can make use of the Health Heartbeat feature, yes. You could set up alerts that detect when an app stops sending the heartbeat, and respond as necessary.
From @cijothomas:
I guess you are planning to add other properties like os, vmsize etc.
Yes, I am learning as I go and getting the feature ready to ship is my initial concern. Adding 'default' fields that the SDK would emit will come second.
Could you also collect process-id as well as part of this?
I think we might be able to accommodate this, it does seem useful and most likely this is the best place for something like this. When I get to implementing the various payload quantities I will investigate & incorporate this. (I've updated the spec to include it so we don't forget).
Heartbeat feature is in 2.5.0-beta2. Closing this issue. Follow-up issues can be created as necessary.