Skip to content

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

Open
@304NotModified

Description

@304NotModified

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions