From 8616476dec5ae9d71ddcd5a6a2da4feea1698c46 Mon Sep 17 00:00:00 2001 From: Nick Warms Date: Mon, 16 Oct 2023 10:24:58 +0100 Subject: [PATCH 1/9] Move app insights to always be turned on Now we enable and disable app insights using the presence of the connection string in the secrets file --- DfE.FindInformationAcademiesTrusts/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DfE.FindInformationAcademiesTrusts/Program.cs b/DfE.FindInformationAcademiesTrusts/Program.cs index fb753ce8b..72f9360eb 100644 --- a/DfE.FindInformationAcademiesTrusts/Program.cs +++ b/DfE.FindInformationAcademiesTrusts/Program.cs @@ -32,6 +32,7 @@ public static void Main(string[] args) builder.Services.AddRazorPages(); builder.Services.AddHealthChecks(); + builder.Services.AddApplicationInsightsTelemetry(); AddAuthenticationServices(builder); builder.Services.Configure(options => @@ -212,7 +213,6 @@ private static void ReconfigureLogging(WebApplicationBuilder builder) } else { - builder.Services.AddApplicationInsightsTelemetry(); builder.Host.UseSerilog((_, services, loggerConfiguration) => loggerConfiguration .ReadFrom.Configuration(builder.Configuration) .WriteTo.ApplicationInsights(services.GetRequiredService(), From 0d6d549d44712dcb274053d090bce5f40b33282d Mon Sep 17 00:00:00 2001 From: Nick Warms Date: Mon, 16 Oct 2023 10:29:36 +0100 Subject: [PATCH 2/9] Add app insights snippet --- DfE.FindInformationAcademiesTrusts/Pages/Shared/_Layout.cshtml | 3 +++ DfE.FindInformationAcademiesTrusts/Pages/_ViewImports.cshtml | 2 ++ 2 files changed, 5 insertions(+) diff --git a/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Layout.cshtml b/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Layout.cshtml index 90f2a1046..cec1de6b5 100644 --- a/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Layout.cshtml +++ b/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Layout.cshtml @@ -14,6 +14,9 @@ + diff --git a/DfE.FindInformationAcademiesTrusts/Pages/_ViewImports.cshtml b/DfE.FindInformationAcademiesTrusts/Pages/_ViewImports.cshtml index 53cfbbce9..63f152ca0 100644 --- a/DfE.FindInformationAcademiesTrusts/Pages/_ViewImports.cshtml +++ b/DfE.FindInformationAcademiesTrusts/Pages/_ViewImports.cshtml @@ -1,4 +1,6 @@ @using DfE.FindInformationAcademiesTrusts +@using Microsoft.ApplicationInsights.AspNetCore @namespace DfE.FindInformationAcademiesTrusts.Pages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, NetEscapades.AspNetCore.SecurityHeaders.TagHelpers +@inject JavaScriptSnippet AppInsightsSnippet From 6a1bc1ebab6688a82b0622169d37530a7ed7e607 Mon Sep 17 00:00:00 2001 From: Nick Warms Date: Mon, 16 Oct 2023 10:31:20 +0100 Subject: [PATCH 3/9] Change CSP policies to allow for App Insights tracking --- DfE.FindInformationAcademiesTrusts/Program.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/DfE.FindInformationAcademiesTrusts/Program.cs b/DfE.FindInformationAcademiesTrusts/Program.cs index 72f9360eb..d763e1797 100644 --- a/DfE.FindInformationAcademiesTrusts/Program.cs +++ b/DfE.FindInformationAcademiesTrusts/Program.cs @@ -110,7 +110,12 @@ private static HeaderPolicyCollection GetSecurityHeaderPolicies() cspBuilder.AddScriptSrc() .Self() .UnsafeInline() - .WithNonce(); + .WithNonce() + .From("https://js.monitor.azure.com/scripts/b/ai.2.min.js"); + cspBuilder.AddConnectSrc() + .Self() + .WithNonce() + .From("https://*.in.applicationinsights.azure.com//v2/track"); cspBuilder.AddObjectSrc().None(); cspBuilder.AddBlockAllMixedContent(); cspBuilder.AddImgSrc().Self(); From 1f511d20cf0f07abf6c028f6092bb216f1d2052b Mon Sep 17 00:00:00 2001 From: Nick Warms Date: Mon, 16 Oct 2023 11:59:29 +0100 Subject: [PATCH 4/9] Remove unused CSP --- DfE.FindInformationAcademiesTrusts/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/DfE.FindInformationAcademiesTrusts/Program.cs b/DfE.FindInformationAcademiesTrusts/Program.cs index d763e1797..f0297d7b1 100644 --- a/DfE.FindInformationAcademiesTrusts/Program.cs +++ b/DfE.FindInformationAcademiesTrusts/Program.cs @@ -114,7 +114,6 @@ private static HeaderPolicyCollection GetSecurityHeaderPolicies() .From("https://js.monitor.azure.com/scripts/b/ai.2.min.js"); cspBuilder.AddConnectSrc() .Self() - .WithNonce() .From("https://*.in.applicationinsights.azure.com//v2/track"); cspBuilder.AddObjectSrc().None(); cspBuilder.AddBlockAllMixedContent(); From 448ba88e25cb0ce948f5545298623f5b8e90413e Mon Sep 17 00:00:00 2001 From: Nick Warms Date: Mon, 16 Oct 2023 10:24:58 +0100 Subject: [PATCH 5/9] Move app insights to always be turned on Now we enable and disable app insights using the presence of the connection string in the secrets file --- DfE.FindInformationAcademiesTrusts/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DfE.FindInformationAcademiesTrusts/Program.cs b/DfE.FindInformationAcademiesTrusts/Program.cs index fb753ce8b..72f9360eb 100644 --- a/DfE.FindInformationAcademiesTrusts/Program.cs +++ b/DfE.FindInformationAcademiesTrusts/Program.cs @@ -32,6 +32,7 @@ public static void Main(string[] args) builder.Services.AddRazorPages(); builder.Services.AddHealthChecks(); + builder.Services.AddApplicationInsightsTelemetry(); AddAuthenticationServices(builder); builder.Services.Configure(options => @@ -212,7 +213,6 @@ private static void ReconfigureLogging(WebApplicationBuilder builder) } else { - builder.Services.AddApplicationInsightsTelemetry(); builder.Host.UseSerilog((_, services, loggerConfiguration) => loggerConfiguration .ReadFrom.Configuration(builder.Configuration) .WriteTo.ApplicationInsights(services.GetRequiredService(), From aafcbbab744bd33b869b5de6fbd2d9bae9ad2e7f Mon Sep 17 00:00:00 2001 From: Nick Warms Date: Mon, 16 Oct 2023 10:29:36 +0100 Subject: [PATCH 6/9] Add app insights snippet --- DfE.FindInformationAcademiesTrusts/Pages/Shared/_Layout.cshtml | 3 +++ DfE.FindInformationAcademiesTrusts/Pages/_ViewImports.cshtml | 2 ++ 2 files changed, 5 insertions(+) diff --git a/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Layout.cshtml b/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Layout.cshtml index 90f2a1046..cec1de6b5 100644 --- a/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Layout.cshtml +++ b/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Layout.cshtml @@ -14,6 +14,9 @@ + diff --git a/DfE.FindInformationAcademiesTrusts/Pages/_ViewImports.cshtml b/DfE.FindInformationAcademiesTrusts/Pages/_ViewImports.cshtml index 53cfbbce9..63f152ca0 100644 --- a/DfE.FindInformationAcademiesTrusts/Pages/_ViewImports.cshtml +++ b/DfE.FindInformationAcademiesTrusts/Pages/_ViewImports.cshtml @@ -1,4 +1,6 @@ @using DfE.FindInformationAcademiesTrusts +@using Microsoft.ApplicationInsights.AspNetCore @namespace DfE.FindInformationAcademiesTrusts.Pages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @addTagHelper *, NetEscapades.AspNetCore.SecurityHeaders.TagHelpers +@inject JavaScriptSnippet AppInsightsSnippet From 1183c7e4404831bad2158fea7c608260762d08f2 Mon Sep 17 00:00:00 2001 From: Nick Warms Date: Mon, 16 Oct 2023 10:31:20 +0100 Subject: [PATCH 7/9] Change CSP policies to allow for App Insights tracking --- DfE.FindInformationAcademiesTrusts/Program.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/DfE.FindInformationAcademiesTrusts/Program.cs b/DfE.FindInformationAcademiesTrusts/Program.cs index 72f9360eb..d763e1797 100644 --- a/DfE.FindInformationAcademiesTrusts/Program.cs +++ b/DfE.FindInformationAcademiesTrusts/Program.cs @@ -110,7 +110,12 @@ private static HeaderPolicyCollection GetSecurityHeaderPolicies() cspBuilder.AddScriptSrc() .Self() .UnsafeInline() - .WithNonce(); + .WithNonce() + .From("https://js.monitor.azure.com/scripts/b/ai.2.min.js"); + cspBuilder.AddConnectSrc() + .Self() + .WithNonce() + .From("https://*.in.applicationinsights.azure.com//v2/track"); cspBuilder.AddObjectSrc().None(); cspBuilder.AddBlockAllMixedContent(); cspBuilder.AddImgSrc().Self(); From 1b0be7cd92b545f28351a75600b90834e63566fd Mon Sep 17 00:00:00 2001 From: Nick Warms Date: Mon, 16 Oct 2023 11:59:29 +0100 Subject: [PATCH 8/9] Remove unused CSP --- DfE.FindInformationAcademiesTrusts/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/DfE.FindInformationAcademiesTrusts/Program.cs b/DfE.FindInformationAcademiesTrusts/Program.cs index d763e1797..f0297d7b1 100644 --- a/DfE.FindInformationAcademiesTrusts/Program.cs +++ b/DfE.FindInformationAcademiesTrusts/Program.cs @@ -114,7 +114,6 @@ private static HeaderPolicyCollection GetSecurityHeaderPolicies() .From("https://js.monitor.azure.com/scripts/b/ai.2.min.js"); cspBuilder.AddConnectSrc() .Self() - .WithNonce() .From("https://*.in.applicationinsights.azure.com//v2/track"); cspBuilder.AddObjectSrc().None(); cspBuilder.AddBlockAllMixedContent(); From c81c59163b5e692c5f4c861eb9a2829254529c7c Mon Sep 17 00:00:00 2001 From: Nick Warms Date: Wed, 18 Oct 2023 12:47:58 +0100 Subject: [PATCH 9/9] Update documentation to include app insights --- docs/getting-started.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/getting-started.md b/docs/getting-started.md index a8ca26201..18df29e1b 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -16,6 +16,7 @@ Use this documentation to configure your local development environment. - [Set up continuous testing](#set-up-continuous-testing) - [Analyse test coverage](#analyse-test-coverage) - [Configure linting and code cleanup](#configure-linting-and-code-cleanup) +- [Application Insights](#application-insights) ## Get it working (without Docker) @@ -215,3 +216,16 @@ cd DfE.FindInformationAcademiesTrusts npm run lint ## for a list of issues npm run lint:fix ## to scan and fix issues ``` + +## Application Insights + +App insights is the platform we are using for measuring telemetry. By default app insights is on in dev and test environments and off when running locally or building in a pipeline. + +App insights can be enabled locally by including the conncection string in your secrets file. The format should be `"APPLICATIONINSIGHTS_CONNECTION_STRING": "