AI: TelemetryChannel found a telemetry item without an InstrumentationKey. This is a required field and must be set in either your config file or at application startup.

takeolexus 80 Reputation points
2023-07-22T11:41:20.9733333+00:00

I have the below code in Program.cs (Blazor Server).

string APP_INSIGHTS = builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"] ?? "";
builder.Logging.AddApplicationInsights(
        configureTelemetryConfiguration: (config) =>
            config.ConnectionString = APP_INSIGHTS,
            configureApplicationInsightsLoggerOptions: (options) => { }
    );

I am receiving the follow error in my azure Application Insights when I call server or every 15 minutes.

AI: TelemetryChannel found a telemetry item without an InstrumentationKey. This is a required field and must be set in either your config file or at application startup.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,680 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,321 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RevelinoB 2,465 Reputation points
    2023-07-22T17:18:20.16+00:00

    Hi Takeolexus,

    The error you are encountering indicates that a telemetry item is being sent to Application Insights without an Instrumentation Key. The Instrumentation Key is a unique identifier that links the telemetry data to the correct Application Insights resource.

    In the code you provided, it seems that you are trying to configure Application Insights in a Blazor Server application using the builder.Logging.AddApplicationInsights method. However, it appears that the Instrumentation Key is not being set properly, resulting in the error you see.

    To fix this, let's check a few things. First, make sure the APPLICATIONINSIGHTS_CONNECTION_STRING in your config file (you know, the appsettings.json one) has the correct Instrumentation Key for your Application Insights resource.

    Also, make sure the key name in your code (APPLICATIONINSIGHTS_CONNECTION_STRING) matches the one in the config file. These little typos can be sneaky!

    And hey, if you have separate config files for different environments, just double-check the Instrumentation Key in each of them.

    Now, if the value isn't being set properly for some reason, you can always set it directly in the code. But remember, it's better to keep sensitive stuff like the Instrumentation Key in config files, not code.

    To set it in the code, you can do something like this:

    string instrumentationKey = "YOUR_INSTRUMENTATION_KEY";
    builder.Logging.AddApplicationInsights(configureTelemetryConfiguration: (config) =>
    {
        config.InstrumentationKey = instrumentationKey;
    }, configureApplicationInsightsLoggerOptions: (options) => { });
    
    

    Just replace "YOUR_INSTRUMENTATION_KEY" with your actual Instrumentation Key.

    That's it! Once you make sure the Instrumentation Key is set correctly, your telemetry data will find its way to the right Application Insights resource without a hitch.

    I hope this helps?


  2. takeolexus 80 Reputation points
    2023-07-23T00:14:48.69+00:00

    I was able to solve with below code.

    string APP_INSIGHTS = builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"] ?? "";
    
    var options = new ApplicationInsightsServiceOptions { ConnectionString = APP_INSIGHTS };
    
    builder.Services.AddApplicationInsightsTelemetry(options: options);