How can I keep on logging after retirement of instrumentationkey and classic application insights?

135 Views Asked by At

I am confused. As clearly published by Microsoft, Classic Application Insights is retired as of today.

That is unfortunate but not the end of the world. There is an alternative: log analytics workspace. So how to do my logging now? Well, I found an answer here.

However, this alternative approach relies on the well-known instrumentation key. This is going to be retired in approximately a year. So that is not very future proof, is it?

So how should I do my logging to (to log analytics workspace) without relying on deprecated NuGet packages, deprecated technologies or "retirement announced" technology?

Please just give me a C# example of how to do this nowadays.

1

There are 1 best solutions below

6
Peter Bons On

So how should I do my logging to (to log analytics workspace) without relying on deprecated NuGet packages, deprecated technologies or "retirement announced" technology?

Just make sure you use an up to date version of the AI Skd. Then, connect to your workspace based Application Insights resource using the connection string instead of the instrumentation key. It is al explained in the docs:

Put the connection string in the app settings:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ApplicationInsights": {
    "ConnectionString": "Copy connection string from Application Insights Resource Overview"
  }
}

and inject the SDK:

// This method gets called by the runtime. Use this method to add services to the container.
var builder = WebApplication.CreateBuilder(args);

// The following line enables Application Insights telemetry collection.
builder.Services.AddApplicationInsightsTelemetry();

// This code adds other services for your application.
builder.Services.AddMvc();

var app = builder.Build();

We have migrated some classic AI resources to workspace based AI resources. It didn't cause much trouble as we just had to change the InstrumentationKey to the ConnectionString in the settings file or update our code to set the connection string instead of the instrumentation key:

 services.AddApplicationInsightsTelemetry(options =>
 {
     options.ConnectionString = "InstrumentationKey=xxx;IngestionEndpoint=https://westeurope-5.in.applicationinsights.azure.com/;LiveEndpoint=https://westeurope.livediagnostics.monitor.azure.com/";
 });

There is not much to it really.

If you still have AI resources that have to be updated go to that resource, click the warning message and follow the steps. No changes have to be done to the configuration of the applications sending telemetry when it comes to moving away from the classic to the workspace based resources:

enter image description here

or visit the docs regarding the migration.