microsoft / ApplicationInsights-dotnet

ApplicationInsights-dotnet
MIT License
565 stars 287 forks source link

AI: Server telemetry channel was not initialized #756

Closed rdagumampan closed 6 years ago

rdagumampan commented 6 years ago

Hi AI Team,

I am trying to instrument my service using AI but I am not getting the server metrics in the server. This TRACE message shows up in the "Search" in AI portal but I can't figure why or how to fix this. The only thing we did special is to override the cloudRoleName using customer initializer so we can see multiple instances of same service in the single application map.

Trace Message

AI: Server telemetry channel was not initialized. So persistent storage is turned off. You need to call ServerTelemetryChannel.Initialize(). Currently monitoring will continue but if telemetry cannot be sent it will be dropped. 

AI Portal

Live Metrics shows the server is listed but CPU, RAM etc.. is N/A Server performance metrics - N/A, NOT OK Dependencies tracking - OK Custom events - OK

package.config

  <package id="Microsoft.ApplicationInsights" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.5.1" targetFramework="net461" />

Program.cs

//active telemery for application performance monitoring
TelemetryConfiguration.Active.TelemetryInitializers.Add(new ServiceNameInitializer(serviceSettings.ServiceName));
TelemetryConfiguration.Active.DisableTelemetry = !serviceSettings.TelemetryAiEnabled;
TelemetryConfiguration.Active.InstrumentationKey = serviceSettings.TelemetryAiInstrumentationKey;

ServiceNameInitializer

    public class ServiceNameInitializer : ITelemetryInitializer
    {
        private readonly string _serviceName;
        public ServiceNameInitializer(string serviceName)
        {
            _serviceName = serviceName;
        }

        public void Initialize(ITelemetry telemetry)
        {
            telemetry.Context.Cloud.RoleName = _serviceName;
        }
    }

Additional Info:

I use Serilog sinks into AI and this perhaps explains why the server shows up in the Live Metrics maybe the Server Telemetry actually never worked in my case?

When I run the same service on my local machine, the server perf counters (RAM, CPU, etc) appears in AI portal.

SergeyKanzhelev commented 6 years ago

What the framework version an application compiled with and running on? Can you post ApplicationInsights.config?

From the look of an issue I think it is this: https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/328 Telemetry disabled, but live metrics do not respect the setting so you got confused.

The only worrisome thing here is why channel wasn't initialized.

fisica3 commented 6 years ago

Hello, I'm having similar issues, I added in my code a Telemetry.TrackEvent("Message"); code and works fine, but the message about "telemetry channel was not initialized" was always there, even before my customization.

This is my ApplicationInsights.config as Visual Studio 2017 added: ApplicationInsights.txt

SergeyKanzhelev commented 6 years ago

We figured out that this problem most likely caused by Application Insights Profiler, not Application Insights itself. There is no workaround except waiting for an update for Azure Web App extension.

@pharring do you have an estimation for this to be fixed?

AmeetAB commented 6 years ago

Hi, is there an update on this? We're experiencing this as well on our production api

SergeyKanzhelev commented 6 years ago

As far as I know the issue is fixed in code. It's the matter of deployment. @pharring any updates?

pharring commented 6 years ago

Yes, it's already in the latest Application Insights site extension. Please upgrade the site extension via the Azure Portal or the Kudu endpoint for your web app.

skyflyer commented 5 years ago

Hi guys! I know this issue is closed, but I believe I might be hitting the same issue on AppService. I have not enabled any extensions specifically and that's what azure portal says. On the Kudu webpage though, I see a webjob: ApplicationInsightsProfiler3

I also see TRACE error messages in AppInsights and I have all of my components configured to log to AI via Serilog. The trace message I'm seeing:

AI: Server telemetry channel was not initialized. So persistent storage is turned off. You need to call ServerTelemetryChannel.Initialize(). Currently monitoring will continue but if telemetry cannot be sent it will be dropped.

And I have configured Serilog like this:

                        var configuration = new TelemetryConfiguration() {
                            InstrumentationKey = hostingContext.Configuration.GetValue<string>("ApplicationInsights:InstrumentationKey"),
                            TelemetryChannel = new ServerTelemetryChannel() { 
                                DeveloperMode = hostingContext.HostingEnvironment.IsDevelopment()
                            }
                        };
                        loggerConfiguration.WriteTo.ApplicationInsightsEvents(configuration);

The log messages from the apps are showing up in AI, so it is working, but I'm not sure if I should instantiate ServerTelemetryChannel and call initialize and then pass that into TelemetryConfiguration.

I don't know how to check the version of AI extension in Azure AppService (since it says none are installed) and Kudu says the same (none are installed).

pharring commented 5 years ago

As the message says, you need to call Initialize on ServerTelemetryChannel before it can be used. i.e.

    var telemetryChannel = new ServerTelemetryChannel { 
        DeveloperMode = hostingContext.HostingEnvironment.IsDevelopment()
    };

    var configuration = new TelemetryConfiguration {
        InstrumentationKey = hostingContext.Configuration.GetValue<string>("ApplicationInsights:InstrumentationKey"),
        TelemetryChannel = telemetryChannel
    };

    telemetryChannel.Initialize(configuration);
    loggerConfiguration.WriteTo.ApplicationInsightsEvents(configuration);
skyflyer commented 5 years ago

Thanks @pharring!