Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [draft] add TelemetryLoggerMiddleware to runtime #2423

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion BotProject/Templates/CSharp/BotProject.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
Expand Down Expand Up @@ -31,6 +31,7 @@
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.8.0" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.8.0" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.8.0" />
<PackageReference Include="Microsoft.Bot.Builder.StreamingExtensions" Version="4.6.0-preview-191021-1" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this a 4.6.0 preview package? shouldn't it be 4.8.0?

<PackageReference Include="Microsoft.Bot.Connector" Version="4.8.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.66">
Expand Down
2 changes: 1 addition & 1 deletion BotProject/Templates/CSharp/BotSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class BotSettings

public CosmosDbPartitionedStorageOptions CosmosDb { get; set; }

public TelemetryConfiguration AppInsights { get; set; }
public TelemetryConfiguration ApplicationInsights { get; set; }

public class BlobStorageConfiguration
{
Expand Down
5 changes: 0 additions & 5 deletions BotProject/Templates/CSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
builder.AddJsonFile("appsettings.deployment.json", optional: true, reloadOnChange: true);
}

if (!env.IsDevelopment())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you removing this?

currently we don't have an user secret inside the botruntime, app password and luis authoring key are stored in file(appsettings)

{
builder.AddUserSecrets<Startup>();
}

builder.AddEnvironmentVariables()
.AddCommandLine(args);
})
Expand Down
26 changes: 15 additions & 11 deletions BotProject/Templates/CSharp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,19 @@
using System;
using System.IO;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder.ApplicationInsights;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.BotFramework;
using Microsoft.Bot.Builder.Dialogs.Adaptive;
using Microsoft.Bot.Builder.Dialogs.Debugging;
using Microsoft.Bot.Builder.Dialogs.Declarative;
using Microsoft.Bot.Builder.Dialogs.Declarative.Resources;
using Microsoft.Bot.Builder.Dialogs.Declarative.Types;
using Microsoft.Bot.Builder.Integration.ApplicationInsights.Core;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.Integration.AspNet.Core.Skills;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Microsoft.Bot.Builder.ComposerBot.Json
{
Expand Down Expand Up @@ -57,14 +51,16 @@ public void ConfigureServices(IServiceCollection services)
services.AddHttpClient<BotFrameworkClient, SkillHttpClient>();
services.AddSingleton<ChannelServiceHandler, SkillHandler>();

services.AddApplicationInsightsTelemetry();

// Load settings
var settings = new BotSettings();
Configuration.Bind(settings);

IStorage storage = null;

// Configure storage for deployment
if (!string.IsNullOrEmpty(settings.CosmosDb.AuthKey))
if (!string.IsNullOrEmpty(settings?.CosmosDb?.AuthKey))
{
storage = new CosmosDbPartitionedStorage(settings.CosmosDb);
}
Expand Down Expand Up @@ -93,11 +89,19 @@ public void ConfigureServices(IServiceCollection services)
HostContext.Current.Set<IConfiguration>(Configuration);

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

if (!string.IsNullOrEmpty(settings?.ApplicationInsights?.InstrumentationKey))
{
var telemetryConfig = new TelemetryConfiguration(settings?.ApplicationInsights?.InstrumentationKey);
var telemetryClient = new TelemetryClient(telemetryConfig);
adapter.Use(new TelemetryLoggerMiddleware(new BotTelemetryClient(telemetryClient), true));
}

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

if (!string.IsNullOrEmpty(settings.BlobStorage.ConnectionString) && !string.IsNullOrEmpty(settings.BlobStorage.Container))
if (!string.IsNullOrEmpty(settings?.BlobStorage?.ConnectionString) && !string.IsNullOrEmpty(settings?.BlobStorage?.Container))
{
adapter.Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container)));
}
Expand Down Expand Up @@ -131,7 +135,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseWebSockets();

app.UseNamedPipes();
app.UseRouting()
.UseEndpoints(endpoints =>
{
Expand Down