Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

VA/Skill App Insights Instrumentation Key not loaded #3365

Closed
lshade opened this issue May 14, 2020 · 5 comments
Closed

VA/Skill App Insights Instrumentation Key not loaded #3365

lshade opened this issue May 14, 2020 · 5 comments
Labels
Needs Triage Needs to be triaged for assignment Type: Bug Something isn't working

Comments

@lshade
Copy link

lshade commented May 14, 2020

What project is affected?

Virtual Assistant and Skill

What language is this in?

C#

What happens?

I haven't seen telemetry coming into App Insights for my VA and Skills.

I saw that this part of appsettings.json:

  "ApplicationInsights": {
    "InstrumentationKey": "<my key>"
  },

Needed to change to this in order to be loaded into BotSettingsBase.cs in Startup.cs

  "appInsights": {
    "InstrumentationKey": "<my key>"
  },

But even with that change, I'm not seeing the logs.

I think the problem could be that the IBotTelemetryClient telemetryClient in all of the dialogs has an empty string for the InstrumentationKey, but I don't see a way to manually set the InstrumentationKey for this.

What are the steps to reproduce this issue?

I have a VA and Skills running with v4.7.2

I made the above change to appsettings.json

This is what it looks like in the Startup.cs:

            // Configure telemetry
            services.AddApplicationInsightsTelemetry();
            services.AddSingleton<IBotTelemetryClient, BotTelemetryClient>(); 
            services.AddSingleton<ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();
            services.AddSingleton<ITelemetryInitializer, TelemetryBotIdInitializer>();
            services.AddSingleton<TelemetryInitializerMiddleware>();
            
            // Configure Logging Personal Information
            services.AddSingleton(sp =>
            {
                var telemetryClient = sp.GetService<IBotTelemetryClient>();
                return new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: true);
            });

Set a breakpoint in the MainDialog constructor where TelemetryClient = telemetryClient; and you'll see TelemetryClient.InstrumentationKey == ""

What were you expecting to happen?

Expected to see events in AppInsights like "WaterfallStep," etc

Can you share any logs, error output, etc.?

Any screenshots or additional context?

@lshade lshade added Needs Triage Needs to be triaged for assignment Type: Bug Something isn't working labels May 14, 2020
@lshade
Copy link
Author

lshade commented May 14, 2020

Actually, I see the logs when I add this back:

  "ApplicationInsights": {
    "InstrumentationKey": "<my key>"
  },

So I'm not sure if this is still an issue, but the key isn't getting loaded into BotSettingsBase properly, and I'm not sure why the TelemetryClient has an empty InstrumentationKey.

Thanks!

@xieofxie
Copy link
Contributor

Hmmm.. Actually AppInsights in BotSettingsBase is not used.

The telemetry is configured through services.AddApplicationInsightsTelemetry()

And this uses the

 "ApplicationInsights": {
    "InstrumentationKey": "<my key>"
  }

@lzc850612 should we rename or remove field AppInsights in BotSettingsBase to reduce confusion?

@lshade
Copy link
Author

lshade commented May 19, 2020

Update!

My issue also had to do with the fact that I'm replacing variables in my appsettings.json using Key Vault: "InstrumentationKey": "<Maintained_in_Key_Vault>"

It seems like services.AddApplicationInsightsTelemetry() wasn't taking the replaced value from Key Vault, and setting "<Maintained_in_Key_Vault>" as the InstrumentationKey.

The fix I found was to explicitly set it by having this in appsettings.json:

  "appInsights": {
    "InstrumentationKey": "<Maintained_in_Key_Vault>"
  },

And this in Startup.cs:

// Configure telemetry
services.AddApplicationInsightsTelemetry(instrumentationKey: settings.AppInsights.InstrumentationKey);

@xieofxie
Copy link
Contributor

Hmm.. key vault is not supported yet. They are proposing a pr now: microsoft/ApplicationInsights-dotnet#1850

@darrenj darrenj closed this as completed May 20, 2020
@cijothomas
Copy link

Hmm.. key vault is not supported yet. They are proposing a pr now: microsoft/ApplicationInsights-dotnet#1850

configuration from any source (keyvault etc) is supported even today. You just need to call AddApplicationInsights(configuration), where the passed configuration should contain the ikey. it can be bound to load from keyvault, or anything else.

The proposed PR is to make addapplicationinsights() take the user iconfiguration by default.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs Triage Needs to be triaged for assignment Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants