Skip to content
Merged
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
10 changes: 5 additions & 5 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This repository publishes Application Insights observability packages for teleme
## Runtime and layout

- SDK: `10.0.301` from `global.json`; package and test projects target `net9.0` and `net10.0`.
- Solution: `src/MX.Observability.ApplicationInsights.sln`.
- Solution: `src/MX.Observability.ApplicationInsights.slnx`.
- Core package: `MX.Observability.ApplicationInsights`.
- Adapters: `MX.Observability.ApplicationInsights.AspNetCore` and `MX.Observability.ApplicationInsights.WorkerService`.
- Tests: `MX.Observability.ApplicationInsights.Tests`.
Expand All @@ -22,10 +22,10 @@ This repository publishes Application Insights observability packages for teleme
## Validation

```pwsh
dotnet build src/MX.Observability.ApplicationInsights.sln
dotnet test src/MX.Observability.ApplicationInsights.sln
dotnet test src/MX.Observability.ApplicationInsights.sln --filter "FullyQualifiedName~MyTestClass.MyTestMethod"
dotnet format src/MX.Observability.ApplicationInsights.sln --verify-no-changes
dotnet build src/MX.Observability.ApplicationInsights.slnx
dotnet test src/MX.Observability.ApplicationInsights.slnx
dotnet test src/MX.Observability.ApplicationInsights.slnx --filter "FullyQualifiedName~MyTestClass.MyTestMethod"
dotnet format src/MX.Observability.ApplicationInsights.slnx --verify-no-changes
```

Usage and configuration contracts are documented in `README.md`.
10 changes: 5 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Multi-target .NET observability libraries for Application Insights telemetry fil

## Locations

- Solution: `src/MX.Observability.ApplicationInsights.sln`
- Solution: `src/MX.Observability.ApplicationInsights.slnx`
- Core package: `src/MX.Observability.ApplicationInsights`
- Host adapters: `src/MX.Observability.ApplicationInsights.AspNetCore`, `src/MX.Observability.ApplicationInsights.WorkerService`
- Tests: `src/MX.Observability.ApplicationInsights.Tests`
Expand All @@ -13,10 +13,10 @@ Multi-target .NET observability libraries for Application Insights telemetry fil
## Commands

```pwsh
dotnet build src/MX.Observability.ApplicationInsights.sln
dotnet test src/MX.Observability.ApplicationInsights.sln
dotnet test src/MX.Observability.ApplicationInsights.sln --filter "FullyQualifiedName~MyTestClass.MyTestMethod"
dotnet format src/MX.Observability.ApplicationInsights.sln --verify-no-changes
dotnet build src/MX.Observability.ApplicationInsights.slnx
dotnet test src/MX.Observability.ApplicationInsights.slnx
dotnet test src/MX.Observability.ApplicationInsights.slnx --filter "FullyQualifiedName~MyTestClass.MyTestMethod"
dotnet format src/MX.Observability.ApplicationInsights.slnx --verify-no-changes
```

## Constraints
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.ApplicationInsights.AspNetCore;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Options;
using MX.Observability.ApplicationInsights.AspNetCore;
using MX.Observability.ApplicationInsights.Auditing;
using MX.Observability.ApplicationInsights.Filtering;
using MX.Observability.ApplicationInsights.Filtering.Configuration;
using MX.Observability.ApplicationInsights.Jobs;
#pragma warning restore CS0618

namespace MX.Observability.ApplicationInsights.Tests.AspNetCore;

[Trait("Category", "Unit")]
public class ServiceCollectionExtensionsTests

Check warning on line 19 in src/MX.Observability.ApplicationInsights.Tests/AspNetCore/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxfP4Lrhi2iBofg7&open=AaBbNxfP4Lrhi2iBofg7&pullRequest=25
{
#pragma warning disable CS0618 // IHostingEnvironment is obsolete but still required by the Application Insights AspNetCore SDK's DI wiring.
private sealed class StubHostingEnvironment : IHostingEnvironment
{
public string EnvironmentName { get; set; } = "Development";
public string ApplicationName { get; set; } = "Tests";
public string WebRootPath { get; set; } = string.Empty;
public IFileProvider WebRootFileProvider { get; set; } = new NullFileProvider();
public string ContentRootPath { get; set; } = AppContext.BaseDirectory;
public IFileProvider ContentRootFileProvider { get; set; } = new NullFileProvider();
}
#pragma warning restore CS0618

private sealed class NullTelemetryProcessor : ITelemetryProcessor
{
public void Process(ITelemetry item)
{
}
}

private static ServiceCollection CreateServicesWithApplicationInsights()
{
var services = new ServiceCollection();
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());

Check warning on line 43 in src/MX.Observability.ApplicationInsights.Tests/AspNetCore/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxfP4Lrhi2iBofhA&open=AaBbNxfP4Lrhi2iBofhA&pullRequest=25
#pragma warning disable CS0618 // IHostingEnvironment is obsolete but still required by the Application Insights AspNetCore SDK's DI wiring.
services.AddSingleton<IHostingEnvironment>(new StubHostingEnvironment());

Check warning on line 45 in src/MX.Observability.ApplicationInsights.Tests/AspNetCore/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxfP4Lrhi2iBofhB&open=AaBbNxfP4Lrhi2iBofhB&pullRequest=25
#pragma warning restore CS0618
services.AddApplicationInsightsTelemetry();

Check warning on line 47 in src/MX.Observability.ApplicationInsights.Tests/AspNetCore/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxfP4Lrhi2iBofhC&open=AaBbNxfP4Lrhi2iBofhC&pullRequest=25
return services;
}

[Fact]
public void AddObservability_RegistersCoreServices()

Check warning on line 52 in src/MX.Observability.ApplicationInsights.Tests/AspNetCore/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddObservability_RegistersCoreServices()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxfP4Lrhi2iBofg8&open=AaBbNxfP4Lrhi2iBofg8&pullRequest=25
{
var services = CreateServicesWithApplicationInsights();

services.AddObservability();

Check warning on line 56 in src/MX.Observability.ApplicationInsights.Tests/AspNetCore/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxfP4Lrhi2iBofg_&open=AaBbNxfP4Lrhi2iBofg_&pullRequest=25
using var provider = services.BuildServiceProvider();

Assert.NotNull(provider.GetRequiredService<IAuditLogger>());
Assert.NotNull(provider.GetRequiredService<IJobTelemetry>());
Assert.NotNull(provider.GetRequiredService<IOptions<TelemetryFilterOptions>>().Value);
}

[Fact]
public void AddObservability_RegistersTelemetryFilterProcessorFactory()

Check warning on line 65 in src/MX.Observability.ApplicationInsights.Tests/AspNetCore/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddObservability_RegistersTelemetryFilterProcessorFactory()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxfP4Lrhi2iBofg9&open=AaBbNxfP4Lrhi2iBofg9&pullRequest=25
{
var services = CreateServicesWithApplicationInsights();

services.AddObservability();

Check warning on line 69 in src/MX.Observability.ApplicationInsights.Tests/AspNetCore/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxfP4Lrhi2iBofhD&open=AaBbNxfP4Lrhi2iBofhD&pullRequest=25
using var provider = services.BuildServiceProvider();

var factory = Assert.Single(provider.GetServices<ITelemetryProcessorFactory>());
var created = factory.Create(new NullTelemetryProcessor());

Assert.IsType<TelemetryFilterProcessor>(created);

Check warning on line 75 in src/MX.Observability.ApplicationInsights.Tests/AspNetCore/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxfP4Lrhi2iBofhE&open=AaBbNxfP4Lrhi2iBofhE&pullRequest=25
}

[Fact]
public void AddObservability_WithConfigureFiltering_AppliesOverrides()

Check warning on line 79 in src/MX.Observability.ApplicationInsights.Tests/AspNetCore/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddObservability_WithConfigureFiltering_AppliesOverrides()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxfP4Lrhi2iBofg-&open=AaBbNxfP4Lrhi2iBofg-&pullRequest=25
{
var services = CreateServicesWithApplicationInsights();

services.AddObservability(options => options.Enabled = false);

Check warning on line 83 in src/MX.Observability.ApplicationInsights.Tests/AspNetCore/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxfP4Lrhi2iBofhF&open=AaBbNxfP4Lrhi2iBofhF&pullRequest=25
using var provider = services.BuildServiceProvider();

var options = provider.GetRequiredService<IOptions<TelemetryFilterOptions>>().Value;

Assert.False(options.Enabled);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Moq;
using MX.Observability.ApplicationInsights.Auditing;
using MX.Observability.ApplicationInsights.Extensions;
using MX.Observability.ApplicationInsights.Filtering.Configuration;
using MX.Observability.ApplicationInsights.Jobs;

namespace MX.Observability.ApplicationInsights.Tests.Extensions;

[Trait("Category", "Unit")]
public class ServiceCollectionExtensionsTests

Check warning on line 15 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhG&open=AaBbNxhF4Lrhi2iBofhG&pullRequest=25
{
private static ServiceCollection CreateServicesWithConfiguration()
{
var services = new ServiceCollection();
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());

Check warning on line 20 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhN&open=AaBbNxhF4Lrhi2iBofhN&pullRequest=25
services.AddSingleton(new TelemetryClient(new TelemetryConfiguration()));

Check warning on line 21 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhO&open=AaBbNxhF4Lrhi2iBofhO&pullRequest=25
return services;
}

[Fact]
public void AddObservabilityCore_RegistersAuditLoggerAndJobTelemetry()

Check warning on line 26 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddObservabilityCore_RegistersAuditLoggerAndJobTelemetry()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhH&open=AaBbNxhF4Lrhi2iBofhH&pullRequest=25
{
var services = CreateServicesWithConfiguration();

services.AddObservabilityCore();

Check warning on line 30 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhP&open=AaBbNxhF4Lrhi2iBofhP&pullRequest=25
using var provider = services.BuildServiceProvider();

Assert.NotNull(provider.GetRequiredService<IAuditLogger>());
Assert.NotNull(provider.GetRequiredService<IJobTelemetry>());
}

[Fact]
public void AddObservabilityCore_WithEmptyConfiguration_BindsSafeDefaults()

Check warning on line 38 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddObservabilityCore_WithEmptyConfiguration_BindsSafeDefaults()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhI&open=AaBbNxhF4Lrhi2iBofhI&pullRequest=25
{
var services = CreateServicesWithConfiguration();

services.AddObservabilityCore();

Check warning on line 42 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhS&open=AaBbNxhF4Lrhi2iBofhS&pullRequest=25
using var provider = services.BuildServiceProvider();

var options = provider.GetRequiredService<IOptions<TelemetryFilterOptions>>().Value;

Assert.True(options.Enabled);
Assert.NotNull(options.Dependencies);
Assert.NotNull(options.Requests);
Assert.NotNull(options.Traces);
Assert.NotNull(options.CustomEvents);
}

[Fact]
public void AddObservabilityCore_WithConfigureFiltering_AppliesOverrides()

Check warning on line 55 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddObservabilityCore_WithConfigureFiltering_AppliesOverrides()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhJ&open=AaBbNxhF4Lrhi2iBofhJ&pullRequest=25
{
var services = CreateServicesWithConfiguration();

services.AddObservabilityCore(options => options.Enabled = false);

Check warning on line 59 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhT&open=AaBbNxhF4Lrhi2iBofhT&pullRequest=25
using var provider = services.BuildServiceProvider();

var options = provider.GetRequiredService<IOptions<TelemetryFilterOptions>>().Value;

Assert.False(options.Enabled);
}

[Fact]
public void AddAuditLogging_RegistersAuditLoggerOnly()

Check warning on line 68 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddAuditLogging_RegistersAuditLoggerOnly()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhK&open=AaBbNxhF4Lrhi2iBofhK&pullRequest=25
{
var services = new ServiceCollection();
services.AddSingleton(new TelemetryClient(new TelemetryConfiguration()));

Check warning on line 71 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhQ&open=AaBbNxhF4Lrhi2iBofhQ&pullRequest=25

services.AddAuditLogging();

Check warning on line 73 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhR&open=AaBbNxhF4Lrhi2iBofhR&pullRequest=25
using var provider = services.BuildServiceProvider();

Assert.NotNull(provider.GetRequiredService<IAuditLogger>());
Assert.Null(provider.GetService<IJobTelemetry>());
}

[Fact]
public void AddJobTelemetry_RegistersJobTelemetryOnly()

Check warning on line 81 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddJobTelemetry_RegistersJobTelemetryOnly()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhL&open=AaBbNxhF4Lrhi2iBofhL&pullRequest=25
{
var services = new ServiceCollection();
services.AddSingleton(new TelemetryClient(new TelemetryConfiguration()));

Check warning on line 84 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhU&open=AaBbNxhF4Lrhi2iBofhU&pullRequest=25
services.AddSingleton(Mock.Of<IAuditLogger>());

Check warning on line 85 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhV&open=AaBbNxhF4Lrhi2iBofhV&pullRequest=25

services.AddJobTelemetry();

Check warning on line 87 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhW&open=AaBbNxhF4Lrhi2iBofhW&pullRequest=25
using var provider = services.BuildServiceProvider();

Assert.NotNull(provider.GetRequiredService<IJobTelemetry>());
}

[Fact]
public void AddObservabilityCore_RegistersAuditLoggerAndJobTelemetryAsSingletons()

Check warning on line 94 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddObservabilityCore_RegistersAuditLoggerAndJobTelemetryAsSingletons()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhM&open=AaBbNxhF4Lrhi2iBofhM&pullRequest=25
{
var services = CreateServicesWithConfiguration();

services.AddObservabilityCore();

Check warning on line 98 in src/MX.Observability.ApplicationInsights.Tests/Extensions/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhF4Lrhi2iBofhX&open=AaBbNxhF4Lrhi2iBofhX&pullRequest=25
using var provider = services.BuildServiceProvider();

Assert.Same(provider.GetRequiredService<IAuditLogger>(), provider.GetRequiredService<IAuditLogger>());
Assert.Same(provider.GetRequiredService<IJobTelemetry>(), provider.GetRequiredService<IJobTelemetry>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="10.0.1" />
<PackageReference Include="coverlet.msbuild" Version="10.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.3" />
Expand All @@ -24,8 +25,14 @@
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MX.Observability.ApplicationInsights\MX.Observability.ApplicationInsights.csproj" />
<ProjectReference Include="..\MX.Observability.ApplicationInsights.AspNetCore\MX.Observability.ApplicationInsights.AspNetCore.csproj" />
<ProjectReference Include="..\MX.Observability.ApplicationInsights.WorkerService\MX.Observability.ApplicationInsights.WorkerService.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.WorkerService;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using MX.Observability.ApplicationInsights.Auditing;
using MX.Observability.ApplicationInsights.Filtering;
using MX.Observability.ApplicationInsights.Filtering.Configuration;
using MX.Observability.ApplicationInsights.Jobs;
using MX.Observability.ApplicationInsights.WorkerService;

namespace MX.Observability.ApplicationInsights.Tests.WorkerService;

[Trait("Category", "Unit")]
public class ServiceCollectionExtensionsTests

Check warning on line 16 in src/MX.Observability.ApplicationInsights.Tests/WorkerService/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhO4Lrhi2iBofhY&open=AaBbNxhO4Lrhi2iBofhY&pullRequest=25
{
private sealed class NullTelemetryProcessor : ITelemetryProcessor
{
public void Process(ITelemetry item)
{
}
}

private static ServiceCollection CreateServicesWithApplicationInsights()
{
var services = new ServiceCollection();
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());

Check warning on line 28 in src/MX.Observability.ApplicationInsights.Tests/WorkerService/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhO4Lrhi2iBofhd&open=AaBbNxhO4Lrhi2iBofhd&pullRequest=25
services.AddApplicationInsightsTelemetryWorkerService();

Check warning on line 29 in src/MX.Observability.ApplicationInsights.Tests/WorkerService/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhO4Lrhi2iBofhe&open=AaBbNxhO4Lrhi2iBofhe&pullRequest=25
return services;
}

[Fact]
public void AddObservability_RegistersCoreServices()

Check warning on line 34 in src/MX.Observability.ApplicationInsights.Tests/WorkerService/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddObservability_RegistersCoreServices()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhO4Lrhi2iBofhZ&open=AaBbNxhO4Lrhi2iBofhZ&pullRequest=25
{
var services = CreateServicesWithApplicationInsights();

services.AddObservability();

Check warning on line 38 in src/MX.Observability.ApplicationInsights.Tests/WorkerService/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhO4Lrhi2iBofhc&open=AaBbNxhO4Lrhi2iBofhc&pullRequest=25
using var provider = services.BuildServiceProvider();

Assert.NotNull(provider.GetRequiredService<IAuditLogger>());
Assert.NotNull(provider.GetRequiredService<IJobTelemetry>());
Assert.NotNull(provider.GetRequiredService<IOptions<TelemetryFilterOptions>>().Value);
}

[Fact]
public void AddObservability_RegistersTelemetryFilterProcessorFactory()

Check warning on line 47 in src/MX.Observability.ApplicationInsights.Tests/WorkerService/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddObservability_RegistersTelemetryFilterProcessorFactory()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhO4Lrhi2iBofha&open=AaBbNxhO4Lrhi2iBofha&pullRequest=25
{
var services = CreateServicesWithApplicationInsights();

services.AddObservability();

Check warning on line 51 in src/MX.Observability.ApplicationInsights.Tests/WorkerService/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhO4Lrhi2iBofhf&open=AaBbNxhO4Lrhi2iBofhf&pullRequest=25
using var provider = services.BuildServiceProvider();

var factory = Assert.Single(provider.GetServices<ITelemetryProcessorFactory>());
var created = factory.Create(new NullTelemetryProcessor());

Assert.IsType<TelemetryFilterProcessor>(created);

Check warning on line 57 in src/MX.Observability.ApplicationInsights.Tests/WorkerService/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhO4Lrhi2iBofhg&open=AaBbNxhO4Lrhi2iBofhg&pullRequest=25
}

[Fact]
public void AddObservability_WithConfigureFiltering_AppliesOverrides()

Check warning on line 61 in src/MX.Observability.ApplicationInsights.Tests/WorkerService/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Missing XML comment for publicly visible type or member 'ServiceCollectionExtensionsTests.AddObservability_WithConfigureFiltering_AppliesOverrides()'

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhO4Lrhi2iBofhb&open=AaBbNxhO4Lrhi2iBofhb&pullRequest=25
{
var services = CreateServicesWithApplicationInsights();

services.AddObservability(options => options.Enabled = false);

Check warning on line 65 in src/MX.Observability.ApplicationInsights.Tests/WorkerService/ServiceCollectionExtensionsTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expression value is never used

See more on https://sonarcloud.io/project/issues?id=frasermolyneux_observability-appinsights&issues=AaBbNxhO4Lrhi2iBofhh&open=AaBbNxhO4Lrhi2iBofhh&pullRequest=25
using var provider = services.BuildServiceProvider();

var options = provider.GetRequiredService<IOptions<TelemetryFilterOptions>>().Value;

Assert.False(options.Enabled);
}
}
Loading
Loading