Skip to content

Commit 41069c1

Browse files
Complete Azure Application Insights integration with tests and documentation
Co-authored-by: BenjaminMichaelis <[email protected]>
1 parent d76b7b1 commit 41069c1

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.ApplicationInsights.Extensibility;
2+
using Microsoft.Extensions.DependencyInjection;
3+
4+
namespace EssentialCSharp.Web.Tests;
5+
6+
public class ApplicationInsightsTests
7+
{
8+
[Fact]
9+
public void WhenTheApplicationStarts_ApplicationInsightsIsRegistered()
10+
{
11+
using WebApplicationFactory factory = new();
12+
13+
// Verify that Application Insights services are registered
14+
var services = factory.Services;
15+
16+
// Check if TelemetryConfiguration is registered (core Application Insights service)
17+
var telemetryConfiguration = services.GetService<TelemetryConfiguration>();
18+
Assert.NotNull(telemetryConfiguration);
19+
}
20+
21+
[Fact]
22+
public async Task WhenTheApplicationStarts_HealthCheckIsAvailable()
23+
{
24+
using WebApplicationFactory factory = new();
25+
26+
HttpClient client = factory.CreateClient();
27+
using HttpResponseMessage response = await client.GetAsync("/healthz");
28+
29+
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
30+
}
31+
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For any bugs, questions, or anything else with specifically the code found insid
99
## What You Will Need
1010

1111
- [Visual Studio](https://visualstudio.microsoft.com/) (or your preferred IDE)
12-
- [.NET 8.0 SDK](https://dotnet.microsoft.com/download)
12+
- [.NET 9.0 SDK](https://dotnet.microsoft.com/download)
1313
- If you already have .NET installed you can check the version by typing `dotnet --info` into cmd to make sure you have the right version
1414

1515
## Startup Steps
@@ -35,6 +35,7 @@ Authentication:github:clientSecret = anotherimportantclientsecret
3535
Authentication:github:clientId = anotherimportantclientid
3636
HCaptcha:SiteKey = captchaSiteKey
3737
HCaptcha:SecretKey = captchaSecretKey
38+
APPLICATIONINSIGHTS_CONNECTION_STRING = "InstrumentationKey=your-instrumentation-key-here;IngestionEndpoint=https://region.in.applicationinsights.azure.com/;LiveEndpoint=https://region.livediagnostics.monitor.azure.com/"
3839

3940
Testing Secret Values:
4041
Some Value Secrets for Testing/Development Purposes:

0 commit comments

Comments
 (0)