ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

Heartbeat doesn't work for short-running WorkerServices (<30 sec) - FlushAsync won't sent the heartbeat

Open 304NotModified opened this issue 2 years ago • 5 comments

Describe the bug

It seams that the heartbeat isn't working for applications that run shorter than 30 seconds, even when FlushAsync is called.

To Reproduce

  1. Create a console application that writes to the application insight traces
  2. Using this configuration:
         services.ConfigureTelemetryModule<DiagnosticsTelemetryModule>((module, _) =>
         {
             module.HeartbeatInterval = TimeSpan.FromSeconds(30);
             module.IsHeartbeatEnabled = true;
         });
         services.AddApplicationInsightsTelemetry(config);
    
  3. Flush for 30 seconds. In the finally
        await _myTelemetryClient.FlushAsync(CancellationToken.None);
        await Task.Delay(TimeSpan.FromSeconds(30));
    

Sometimes it's too late. The traces are sent really earlier (29 sec)

I tried lowering the HeartbeatInterval, but 30 seconds is the lowest possible value?

So the FlushAsync doesn't seem to send the heartbeat, that's the bug.

Is there a way to send the heartbeat manually?

Work around: await Task.Delay(TimeSpan.FromSeconds(45)); - we don't really like this. The job needs 5 seconds, and now 50 (10 times!)

Related: #1689, #407

304NotModified avatar Apr 03 '23 11:04 304NotModified

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar Jan 29 '24 00:01 github-actions[bot]

Yes indeed, im still waiting for a response...

304NotModified avatar Jan 30 '24 16:01 304NotModified

A fix is here: #2762

304NotModified avatar Feb 20 '24 13:02 304NotModified

@TimothyMothra could you please help me in getting a reaction/get the fix (https://github.com/microsoft/ApplicationInsights-dotnet/pull/2762) merged?

304NotModified avatar Feb 22 '24 14:02 304NotModified