From 1e3ed6ea90cdbc0c8a590dac0576b171091f64ae Mon Sep 17 00:00:00 2001 From: Chris Ayers Date: Mon, 7 Oct 2019 19:36:46 -0400 Subject: [PATCH 1/2] added app insights --- .../AspNetCoreShiftLeft.Web.csproj | 16 ++++++++++++-- .../Pages/Shared/_Layout.cshtml | 4 +++- src/AspNetCoreShiftLeft.Web/Startup.cs | 22 ++++++++++++++----- src/AspNetCoreShiftLeft.Web/appsettings.json | 3 +++ .../AspNetCoreShiftLeft.Web.Tests.csproj | 11 ++++++---- .../UnitTest1.cs | 13 ----------- 6 files changed, 43 insertions(+), 26 deletions(-) delete mode 100644 test/AspNetCoreShiftLeft.Web.Tests/UnitTest1.cs diff --git a/src/AspNetCoreShiftLeft.Web/AspNetCoreShiftLeft.Web.csproj b/src/AspNetCoreShiftLeft.Web/AspNetCoreShiftLeft.Web.csproj index 8eacdc1..790efa8 100644 --- a/src/AspNetCoreShiftLeft.Web/AspNetCoreShiftLeft.Web.csproj +++ b/src/AspNetCoreShiftLeft.Web/AspNetCoreShiftLeft.Web.csproj @@ -1,11 +1,23 @@ - + netcoreapp3.0 - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/src/AspNetCoreShiftLeft.Web/Pages/Shared/_Layout.cshtml b/src/AspNetCoreShiftLeft.Web/Pages/Shared/_Layout.cshtml index b39c56c..3d9ab4c 100644 --- a/src/AspNetCoreShiftLeft.Web/Pages/Shared/_Layout.cshtml +++ b/src/AspNetCoreShiftLeft.Web/Pages/Shared/_Layout.cshtml @@ -1,4 +1,5 @@ - +@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet + @@ -6,6 +7,7 @@ @ViewData["Title"] - AspNetCoreShiftLeft.Web + @Html.Raw(JavaScriptSnippet.FullScript)
diff --git a/src/AspNetCoreShiftLeft.Web/Startup.cs b/src/AspNetCoreShiftLeft.Web/Startup.cs index 6527397..98d1d7a 100644 --- a/src/AspNetCoreShiftLeft.Web/Startup.cs +++ b/src/AspNetCoreShiftLeft.Web/Startup.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using Microsoft.ApplicationInsights.AspNetCore.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -23,6 +19,7 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.AddAppInsights(Configuration); services.AddRazorPages(); } @@ -53,4 +50,17 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) }); } } -} + static class ServiceCollectionExtensions + { + public static IServiceCollection AddAppInsights(this IServiceCollection services, IConfiguration configuration) + { + ApplicationInsightsServiceOptions aiOptions = new ApplicationInsightsServiceOptions(); + aiOptions.EnableAdaptiveSampling = true; + + // QuickPulse (Live Metrics stream). + aiOptions.EnableQuickPulseMetricStream = true; + services.AddApplicationInsightsTelemetry(aiOptions); + return services; + } + } +} \ No newline at end of file diff --git a/src/AspNetCoreShiftLeft.Web/appsettings.json b/src/AspNetCoreShiftLeft.Web/appsettings.json index d9d9a9b..dbce3d5 100644 --- a/src/AspNetCoreShiftLeft.Web/appsettings.json +++ b/src/AspNetCoreShiftLeft.Web/appsettings.json @@ -1,4 +1,7 @@ { + "ApplicationInsights": { + "InstrumentationKey": "" + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/test/AspNetCoreShiftLeft.Web.Tests/AspNetCoreShiftLeft.Web.Tests.csproj b/test/AspNetCoreShiftLeft.Web.Tests/AspNetCoreShiftLeft.Web.Tests.csproj index f7ee2f3..4f150a2 100644 --- a/test/AspNetCoreShiftLeft.Web.Tests/AspNetCoreShiftLeft.Web.Tests.csproj +++ b/test/AspNetCoreShiftLeft.Web.Tests/AspNetCoreShiftLeft.Web.Tests.csproj @@ -7,10 +7,13 @@ - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/AspNetCoreShiftLeft.Web.Tests/UnitTest1.cs b/test/AspNetCoreShiftLeft.Web.Tests/UnitTest1.cs deleted file mode 100644 index b593f11..0000000 --- a/test/AspNetCoreShiftLeft.Web.Tests/UnitTest1.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace AspNetCoreShiftLeft.Web.Tests -{ - [TestClass] - public class UnitTest1 - { - [TestMethod] - public void TestMethod1() - { - } - } -} From 160c0cbbad65c70407aee695acc11186db347439 Mon Sep 17 00:00:00 2001 From: Chris Ayers Date: Mon, 7 Oct 2019 19:50:09 -0400 Subject: [PATCH 2/2] Update Startup.cs cleaned up app insights initialization --- src/AspNetCoreShiftLeft.Web/Startup.cs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/AspNetCoreShiftLeft.Web/Startup.cs b/src/AspNetCoreShiftLeft.Web/Startup.cs index 98d1d7a..e8f30e1 100644 --- a/src/AspNetCoreShiftLeft.Web/Startup.cs +++ b/src/AspNetCoreShiftLeft.Web/Startup.cs @@ -19,7 +19,7 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.AddAppInsights(Configuration); + services.AddApplicationInsightsTelemetry(Configuration); services.AddRazorPages(); } @@ -50,17 +50,4 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) }); } } - static class ServiceCollectionExtensions - { - public static IServiceCollection AddAppInsights(this IServiceCollection services, IConfiguration configuration) - { - ApplicationInsightsServiceOptions aiOptions = new ApplicationInsightsServiceOptions(); - aiOptions.EnableAdaptiveSampling = true; - - // QuickPulse (Live Metrics stream). - aiOptions.EnableQuickPulseMetricStream = true; - services.AddApplicationInsightsTelemetry(aiOptions); - return services; - } - } } \ No newline at end of file