Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling Heartbeats #1681

Closed
tommy-ly opened this issue Feb 13, 2020 · 5 comments
Closed

Disabling Heartbeats #1681

tommy-ly opened this issue Feb 13, 2020 · 5 comments
Assignees
Milestone

Comments

@tommy-ly
Copy link

Currently trying to disable heartbeats in my ASP.NET Core 3.1 web application with the following code in my startup:

var aiOptions = new ApplicationInsightsServiceOptions
{
    EnableHeartbeat = false,
    EnableAppServicesHeartbeatTelemetryModule = false
};

serviceCollection.AddApplicationInsightsTelemetry(aiOptions);

var config = new TelemetryConfiguration(key);
var diagnosticsTelemetryModule = new DiagnosticsTelemetryModule();
diagnosticsTelemetryModule.IsHeartbeatEnabled = false;
diagnosticsTelemetryModule.Initialize(config);

From what I can tell after reading the documentation the top half of the code (adding application insights telemetry) should have been enough. This didn't work which lead to me google further into the issue which someone had suggested initializing the diagnostics module (although I'm not sure how that works since we aren't actually doing anything with the module after instantiation).

After doing this I now get this error message every time it tries to do the heartbeat in my traces :

AI (Internal): [Microsoft-ApplicationInsights-Core] [msg=Log Error];[msg=Heartbeat pulse being sent without valid instance of HeartbeatProvider as its state]

Is there some simple setting I've missed in my startup?

Version Info

SDK Version : 2.12.0
.NET Version : Core 3.1
How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) : Manual
OS : Windows
Hosting Info (IIS/Azure WebApps/ etc) : IIS

@cijothomas
Copy link
Contributor

@tommy-ly The top half should be enough to disable heartbeats. I validated that it works. (i.e i can disable heartbeats)
Following is my full ConfigureService method in a .net core 3.1 app.

// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            var aiOptions = new ApplicationInsightsServiceOptions();
            aiOptions.EnableHeartbeat = false;
            aiOptions.InstrumentationKey = "cijokey";
            services.AddApplicationInsightsTelemetry(aiOptions);
        }

Please share the exact snippet you are using and we can investigate further. Doing new DiagnosticsTelemetryModule(); is NOT needed and wont have the effect you desire.

@cijothomas
Copy link
Contributor

Closing as correct solution is provided. Please reopen if there is a repro where the above is not working and we'll investigate.

@Nortown
Copy link

Nortown commented Mar 20, 2020

Hi experts,

I encountered the same issues:

AI (Internal): [Microsoft-ApplicationInsights-Core] [msg=Log Error];[msg=Heartbeat pulse being sent without valid instance of HeartbeatProvider as its state]

and attached my AppInsights config below. Just wondering did I misused any config here? Thanks.

public static void AddAppInsightServices(this IServiceCollection services, IConfiguration configuration)
{
    services.AddSingleton<ITelemetryInitializer, UserInfoTelemetryInitializer>();
    services.AddSingleton<ITelemetryInitializer, FabricTelemetryInitializer>(); 
    services.AddSingleton<ITelemetryModule, EventSourceTelemetryModule>();
    services.ConfigureTelemetryModule<EventSourceTelemetryModule>((module, options) => 
    {
        module.Sources.Add(new EventSourceListeningRequest { Name = "XXX" });
    });
    var aiOptions = new ApplicationInsightsServiceOptions
    {
        EnableHeartbeat = false,
        InstrumentationKey = configuration["APPINSIGHTS_INSTRUMENTATIONKEY"]
    };
    services.AddApplicationInsightsTelemetry(aiOptions);
}

And my project config is shown below:

<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
  <TargetFramework>net472</TargetFramework>
  <Platforms>AnyCPU;x64</Platforms>
  <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="Microsoft.ApplicationInsights" Version="2.11.0" />
  <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.2" />
  <PackageReference Include="Microsoft.ApplicationInsights.EventSourceListener" Version="2.11.0" />
  <PackageReference Include="Microsoft.ApplicationInsights.ServiceFabric" Version="2.3.1" />
  <PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
  <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
  <PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.11.0" />
  <PackageReference Include="Microsoft.IdentityModel.Protocols" Version="5.4.0" />
  <PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="5.4.0" />
  <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  <PackageReference Include="System.Net.Http" Version="4.3.4" />
  <PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
  <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
  <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.0.0" />
  <PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
  <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
</ItemGroup>

@cijothomas
Copy link
Contributor

@Nortown Nothing wrong in your code. There is a bug in the product which cases the Error log to be fired. The hearbeat is disabled, but the error log is produced every heart beat interval.

Reopening this issue and adding a fix for the same.

@cijothomas
Copy link
Contributor

Closing. Will be available in 2.14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants