Skip to content

Commit

Permalink
Register IBotTelemetryClient and add telemetry initializer middleware…
Browse files Browse the repository at this point in the history
… to the adapter pipeline
  • Loading branch information
garypretty committed May 6, 2020
1 parent 70b9715 commit 41b49d1
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions runtime/dotnet/azurewebapp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,16 @@ 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)
{
HostContext.Current.Set<IConfiguration>(Configuration);

var adapter = new BotFrameworkHttpAdapter(new ConfigurationCredentialProvider(this.Configuration));

adapter
.UseStorage(storage)
.UseState(userState, conversationState);
.UseStorage(storage)
.UseState(userState, conversationState)
.Use(telemetryInitializerMiddleware);

// Configure Middlewares
ConfigureTranscriptLoggerMiddleware(adapter, settings);
Expand Down Expand Up @@ -131,17 +132,13 @@ public void ConfigureServices(IServiceCollection services)
services.AddApplicationInsightsTelemetry();
services.AddSingleton<ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();
services.AddSingleton<ITelemetryInitializer, TelemetryBotIdInitializer>();
services.AddSingleton<TelemetryLoggerMiddleware>(sp =>
{
var telemetryClient = sp.GetService<IBotTelemetryClient>();
return new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: settings.Telemetry.LogPersonalInformation);
});
services.AddSingleton<TelemetryInitializerMiddleware>(sp =>
{
var httpContextAccessor = sp.GetService<IHttpContextAccessor>();
var telemetryLoggerMiddleware = sp.GetService<TelemetryLoggerMiddleware>();
return new TelemetryInitializerMiddleware(httpContextAccessor, telemetryLoggerMiddleware, settings.Telemetry.LogActivities);
});
services.AddSingleton<IBotTelemetryClient, BotTelemetryClient>();

var sp = services.BuildServiceProvider();
var telemetryClient = sp.GetService<IBotTelemetryClient>();
var telemetryLoggerMiddleware = new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: settings.Telemetry.LogPersonalInformation);
var httpContextAccessor = sp.GetService<IHttpContextAccessor>();
var telemetryInitializerMiddleware = new TelemetryInitializerMiddleware(httpContextAccessor, telemetryLoggerMiddleware, settings.Telemetry.LogActivities);

IStorage storage = ConfigureStorage(settings);

Expand All @@ -160,7 +157,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddSingleton(resourceExplorer);

services.AddSingleton<IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>((s) => GetBotAdapter(storage, settings, userState, conversationState, s));
services.AddSingleton<IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>((s) => GetBotAdapter(storage, settings, userState, conversationState, s, telemetryInitializerMiddleware));

services.AddSingleton<IBot>(s =>
new ComposerBot(
Expand All @@ -169,7 +166,7 @@ public void ConfigureServices(IServiceCollection services)
s.GetService<ResourceExplorer>(),
s.GetService<BotFrameworkClient>(),
s.GetService<SkillConversationIdFactoryBase>(),
s.GetService<IBotTelemetryClient>(),
telemetryClient,
rootDialog,
defaultLocale));
}
Expand Down

0 comments on commit 41b49d1

Please sign in to comment.