'Trying to add heartbeat for my console application

A discussion on github mentions that heartbeat is automatically sent when Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule& is added to the applicationinsights.config file. I want to create an alert in case the app hangs or crashes. Where can I track the heart beat on the AI instance? Also, currently its not sending anything . I am using .net framework 4.7.2. Am I configuring it wrong? I am not able to track the heartbeat on application insights instance. Where can I track it? Can someone provide a snippet for config file?



Solution 1:[1]

Currently, there is an issue involving this telemetry module AppServicesHeartbeatTelemetryModule .

Can someone provide a snippet for config file?

There is given a temporary workaround for WorkerServices.

  • Add application insights to worker service using services.AddApplicationInsightsTelemetryWorkerService().

  • Not only this DiagnosticsTelemetryModule adding to DI and also we need to configure it's heartbeat interval/module using the below snippet:

services.TryAddSingleton<ITelemetryModule, DiagnosticsTelemetryModule>();
                    services.ConfigureTelemetryModule<DiagnosticsTelemetryModule>((mod,opt) => mod.HeartbeatInterval = TimeSpan.FromSeconds(30));
                    services.AddApplicationInsightsTelemetryWorkerService();
  • The TelemetryConfiguration.Active is not recommended because Worker service is new SDK, its not touching .active or any other static singletons.

Where can I track it?

After Deploying, Look for "HeartbeatState" in customMetrics.

Note:

  • Disabling DiagnosticsTelemetryModule will cause the following settings to be ignored: EnableHeartbeat, EnableAzureInstanceMetadataTelemetryModule, EnableAppServicesHeartbeatTelemetryModule.
  • Enable Azure Monitor from the Portal.

References:

  1. Configuring or removing default TelemetryModules (HeartBeat Telemetry Issue)
  2. Enabling Hearbeat in App Services for .NET and .NET Core

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HariKrishnaRajoli-MT