diff --git a/runtime/dotnet/azurefunctions/Startup.cs b/runtime/dotnet/azurefunctions/Startup.cs index cb06174037..54e13dc967 100644 --- a/runtime/dotnet/azurefunctions/Startup.cs +++ b/runtime/dotnet/azurefunctions/Startup.cs @@ -24,6 +24,7 @@ using System.IO; using System.Reflection; using System.Text; +using Microsoft.Bot.Builder.ApplicationInsights; [assembly: FunctionsStartup(typeof(Microsoft.BotFramework.Composer.Functions.Startup))] @@ -86,9 +87,10 @@ public override void Configure(IFunctionsHostBuilder builder) services.AddSingleton(); // Register telemetry client, initializers and middleware - services.AddApplicationInsightsTelemetry(); + services.AddApplicationInsightsTelemetry(settings.ApplicationInsights.InstrumentationKey); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(sp => { var telemetryClient = sp.GetService(); @@ -130,12 +132,14 @@ public override void Configure(IFunctionsHostBuilder builder) IStorage storage = s.GetService(); UserState userState = s.GetService(); ConversationState conversationState = s.GetService(); + TelemetryInitializerMiddleware telemetryInitializerMiddleware = s.GetService(); var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(rootConfiguration)); adapter .UseStorage(storage) - .UseBotState(userState, conversationState); + .UseBotState(userState, conversationState) + .Use(telemetryInitializerMiddleware); // Configure Middlewares ConfigureTranscriptLoggerMiddleware(adapter, settings); diff --git a/runtime/dotnet/azurewebapp/Startup.cs b/runtime/dotnet/azurewebapp/Startup.cs index 6b22122668..243bdf60bb 100644 --- a/runtime/dotnet/azurewebapp/Startup.cs +++ b/runtime/dotnet/azurewebapp/Startup.cs @@ -10,6 +10,7 @@ using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.AI.Luis; using Microsoft.Bot.Builder.AI.QnA; +using Microsoft.Bot.Builder.ApplicationInsights; using Microsoft.Bot.Builder.Azure; using Microsoft.Bot.Builder.BotFramework; using Microsoft.Bot.Builder.Dialogs; @@ -82,14 +83,15 @@ public IStorage ConfigureStorage(BotSettings settings) return storage; } - public BotFrameworkHttpAdapter GetBotAdapter(IStorage storage, BotSettings settings, UserState userState, ConversationState conversationState, IServiceProvider s) + public BotFrameworkHttpAdapter GetBotAdapter(IStorage storage, BotSettings settings, UserState userState, ConversationState conversationState, IServiceProvider s, TelemetryInitializerMiddleware telemetryInitializerMiddleware) { var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(this.Configuration)); adapter .UseStorage(storage) .UseBotState(userState, conversationState) - .Use(new RegisterClassMiddleware(Configuration)); + .Use(new RegisterClassMiddleware(Configuration)) + .Use(telemetryInitializerMiddleware); // Configure Middlewares ConfigureTranscriptLoggerMiddleware(adapter, settings); @@ -137,9 +139,10 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton(); // Register telemetry client, initializers and middleware - services.AddApplicationInsightsTelemetry(); + services.AddApplicationInsightsTelemetry(settings.ApplicationInsights.InstrumentationKey); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(sp => { var telemetryClient = sp.GetService(); @@ -152,7 +155,7 @@ public void ConfigureServices(IServiceCollection services) return new TelemetryInitializerMiddleware(httpContextAccessor, telemetryLoggerMiddleware, settings.Telemetry.LogActivities); }); - IStorage storage = ConfigureStorage(settings); + var storage = ConfigureStorage(settings); services.AddSingleton(storage); var userState = new UserState(storage); @@ -169,7 +172,7 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton(resourceExplorer); - services.AddSingleton((s) => GetBotAdapter(storage, settings, userState, conversationState, s)); + services.AddSingleton((s) => GetBotAdapter(storage, settings, userState, conversationState, s, s.GetService())); services.AddSingleton(s => new ComposerBot(