Skip to content

Commit 7dd9696

Browse files
authored
fix: use still http correlation instance w/ hierarhical (#423)
1 parent b3394f2 commit 7dd9696

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/Arcus.WebApi.Logging.AzureFunctions/Extensions/IServiceCollectionExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ public static IServiceCollection AddHttpCorrelation(this IFunctionsHostBuilder b
102102
var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
103103
return new HttpCorrelationInfoAccessor(httpContextAccessor);
104104
});
105+
services.AddSingleton(serviceProvider =>
106+
{
107+
var httpContextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
108+
var correlationInfoAccessor = serviceProvider.GetRequiredService<IHttpCorrelationInfoAccessor>();
109+
var logger = serviceProvider.GetService<ILogger<HttpCorrelation>>();
110+
111+
return new HttpCorrelation(Options.Options.Create(options), httpContextAccessor, correlationInfoAccessor, logger);
112+
});
105113
}
106114

107115
services.AddSingleton<ICorrelationInfoAccessor<CorrelationInfo>>(provider => provider.GetRequiredService<IHttpCorrelationInfoAccessor>());

src/Arcus.WebApi.Tests.Unit/Logging/IFunctionsHostBuilderTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Arcus.Observability.Correlation;
33
using Arcus.WebApi.Logging.Core.Correlation;
44
#if NET6_0
5+
using Arcus.WebApi.Logging.Correlation;
56
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
67
#endif
78
using Microsoft.Extensions.DependencyInjection;
@@ -49,6 +50,22 @@ public void AddHttpCorrelation_WithHttpOptions_RegistersDedicatedCorrelation()
4950
Assert.NotNull(provider.GetService<ICorrelationInfoAccessor<CorrelationInfo>>());
5051
Assert.NotNull(provider.GetService<ICorrelationInfoAccessor>());
5152
}
53+
54+
[Fact]
55+
public void AddHttpCorrelation_WithHierarchical_StillRegistersHttpCorrelation()
56+
{
57+
// Arrange
58+
var services = new ServiceCollection();
59+
var builder = new Mock<IFunctionsHostBuilder>();
60+
builder.Setup(build => build.Services).Returns(services);
61+
62+
// Act
63+
builder.Object.AddHttpCorrelation(options => options.Format = HttpCorrelationFormat.Hierarchical);
64+
65+
// Assert
66+
IServiceProvider provider = services.BuildServiceProvider();
67+
Assert.NotNull(provider.GetService<HttpCorrelation>());
68+
}
5269
}
5370
#endif
5471
}

0 commit comments

Comments
 (0)