Azure Application Insights – Live Metrics Stream Sample Telemetry

Hello Guys,

One of the best features of Azure Application Insights is [Live Metrics Stream] ( https://docs.microsoft.com/en-us/azure/azure-monitor/app/live-stream ) that allows us to have a real-time view of our servers.
The Azure team decided to implement mandatory authentication for viewing metrics in Live Stream some time ago.

Today’s post is about how to enable telemetry again, since the live stream continues to work for most users.

(Optional) – Enable Application Insights right in the code

If you enabled application insights directly on the azure portal and did not install the packages in your application, you will need to install the Microsoft.ApplicationInsights.AspNetCore package and enable the service on Startup.cs

public void ConfigureServices(IServiceCollection services)
{
	services.AddApplicationInsightsTelemetry();
}

Create an authentication key

In application insights we have the possibility to generate a KEY API so that we can read metrics and other operations. To view the logs again, we will need a key that supports authentication.

In the azure portal, select the Application Insights you want to create the key for, then select the API Access menu .

Click on Create API Key at the top and a name for your key, the most important option for our purpose is Authenticate SDK Control Channel .

Copy the generated key to some safe place, once the key is generated it is never shown on the Azure portal again, in case of loss we will have to generate a new key.

Authenticating the QuickPulseTelemetryModule module

Now that we have our authentication key, we have to configure the QuickPulseTelemetryModule module to read our key and authenticate.

In my appsettings.json I created a new entry with my key called APPLICATIONINSIGHTS_APIKEY, you can give it another name if you want.

In the ConfigureServices method add the following code:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddApplicationInsightsTelemetry();

            services.ConfigureTelemetryModule<QuickPulseTelemetryModule>((module, o) =>
            {
                module.AuthenticationApiKey = Configuration.GetValue("APPLICATIONINSIGHTS_APIKEY", string.Empty);
            });

            services.AddControllers();
        }

All done! Now just republish the application and we will have our telemetry active again in the live stream.

For more information about the live stream and how to customize the display filters, visit the official documentation:

https://docs.microsoft.com/pt-br/azure/azure-monitor/app/live-stream

About the Author:

Reference:

dos Santos, R. (2020). Azure Application Insights – Live Metrics Stream Sample Telemetry. Available at: https://rafaeldossantos.net/azure-application-insights-live-metrics-stream-sample-temeletry/ [Accessed: 21st January 2020].

Share this on...

Rate this Post:

Share:

Topics:

Azure

Tags: