From 14e17ad49ecc14f915dfebf47e37f3d3099f737c Mon Sep 17 00:00:00 2001 From: Stijn Moreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 10 Oct 2023 07:03:33 +0200 Subject: [PATCH] chore: remove deprecated correlation (#540) --- .../CorrelationInfoOperationOptions.cs | 49 ---- .../CorrelationInfoOptions.cs | 26 -- .../CorrelationInfoTransactionOptions.cs | 62 ----- .../CorrelationInfoUpstreamServiceOptions.cs | 48 ---- .../DefaultCorrelationInfoAccessor.cs | 16 +- .../DefaultCorrelationInfoAccessorT.cs | 16 +- .../IServiceCollectionExtensions.cs | 149 ----------- ...LoggerEnrichmentConfigurationExtensions.cs | 43 ---- .../CorrelationInfoOptionsTests.cs | 42 --- .../DefaultCorrelationInfoAccessorTests.cs | 34 --- .../IServiceCollectionExtensionsTests.cs | 111 -------- .../Correlation/TestCorrelationInfoOptions.cs | 15 -- .../Enrichers/CorrelationInfoEnricherTests.cs | 242 ------------------ 13 files changed, 2 insertions(+), 851 deletions(-) delete mode 100644 src/Arcus.Observability.Correlation/CorrelationInfoOperationOptions.cs delete mode 100644 src/Arcus.Observability.Correlation/CorrelationInfoOptions.cs delete mode 100644 src/Arcus.Observability.Correlation/CorrelationInfoTransactionOptions.cs delete mode 100644 src/Arcus.Observability.Correlation/CorrelationInfoUpstreamServiceOptions.cs delete mode 100644 src/Arcus.Observability.Tests.Unit/Correlation/CorrelationInfoOptionsTests.cs delete mode 100644 src/Arcus.Observability.Tests.Unit/Correlation/DefaultCorrelationInfoAccessorTests.cs delete mode 100644 src/Arcus.Observability.Tests.Unit/Correlation/TestCorrelationInfoOptions.cs diff --git a/src/Arcus.Observability.Correlation/CorrelationInfoOperationOptions.cs b/src/Arcus.Observability.Correlation/CorrelationInfoOperationOptions.cs deleted file mode 100644 index 5beb9d31..00000000 --- a/src/Arcus.Observability.Correlation/CorrelationInfoOperationOptions.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using GuardNet; - -namespace Arcus.Observability.Correlation -{ - /// - /// Correlation options specific for the operation ID. - /// - [Obsolete("Use HTTP, messaging, or custom-specific correlation options instead")] - public class CorrelationInfoOperationOptions - { - private string _headerName = "RequestId"; - private Func _generateId = () => Guid.NewGuid().ToString(); - - /// - /// Gets or sets whether to include the operation ID in the response. - /// - /// - /// A common use case is to disable tracing info in edge services, so that such details are not exposed to the outside world. - /// - public bool IncludeInResponse { get; set; } = true; - - /// - /// Gets or sets the header that will contain the response operation ID. - /// - public string HeaderName - { - get => _headerName; - set - { - Guard.NotNullOrWhitespace(value, nameof(value), "Correlation operation header cannot be blank"); - _headerName = value; - } - } - - /// - /// Gets or sets the function to generate the operation ID when the is set to true (default: true). - /// - public Func GenerateId - { - get => _generateId; - set - { - Guard.NotNull(value, nameof(value), "Correlation function to generate an operation ID cannot be 'null'"); - _generateId = value; - } - } - } -} diff --git a/src/Arcus.Observability.Correlation/CorrelationInfoOptions.cs b/src/Arcus.Observability.Correlation/CorrelationInfoOptions.cs deleted file mode 100644 index c9516c52..00000000 --- a/src/Arcus.Observability.Correlation/CorrelationInfoOptions.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; - -namespace Arcus.Observability.Correlation -{ - /// - /// Options for handling correlation id on incoming requests. - /// - [Obsolete("Use HTTP, messaging, or custom-specific correlation options instead")] - public class CorrelationInfoOptions - { - /// - /// Gets the correlation options specific for the transaction ID. - /// - public CorrelationInfoTransactionOptions Transaction { get; } = new CorrelationInfoTransactionOptions(); - - /// - /// Gets the correlation options specific for the operation ID. - /// - public CorrelationInfoOperationOptions Operation { get; } = new CorrelationInfoOperationOptions(); - - /// - /// Gets the correlation options specific for the upstream service. - /// - public CorrelationInfoUpstreamServiceOptions OperationParent { get; } = new CorrelationInfoUpstreamServiceOptions(); - } -} diff --git a/src/Arcus.Observability.Correlation/CorrelationInfoTransactionOptions.cs b/src/Arcus.Observability.Correlation/CorrelationInfoTransactionOptions.cs deleted file mode 100644 index c656fbc8..00000000 --- a/src/Arcus.Observability.Correlation/CorrelationInfoTransactionOptions.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using GuardNet; - -namespace Arcus.Observability.Correlation -{ - /// - /// Correlation options specific to the transaction ID. - /// - [Obsolete("Use HTTP, messaging, or custom-specific correlation options instead")] - public class CorrelationInfoTransactionOptions - { - private string _headerName = "X-Transaction-ID"; - private Func _generateId = () => Guid.NewGuid().ToString(); - - /// - /// Get or sets whether the transaction ID can be specified in the request, and will be used throughout the request handling. - /// - public bool AllowInRequest { get; set; } = true; - - /// - /// Gets or sets whether or not the transaction ID should be generated when there isn't any transaction ID found in the request. - /// - public bool GenerateWhenNotSpecified { get; set; } = true; - - /// - /// Gets or sets whether to include the transaction ID in the response. - /// - /// - /// A common use case is to disable tracing info in edge services, so that such details are not exposed to the outside world. - /// - public bool IncludeInResponse { get; set; } = true; - - /// - /// Gets or sets the header that will contain the request/response transaction ID. - /// - public string HeaderName - { - get => _headerName; - set - { - Guard.NotNullOrWhitespace(value, nameof(value), "Correlation transaction header cannot be blank"); - _headerName = value; - } - } - - /// - /// Gets or sets the function to generate the transaction ID when - /// (1) the request doesn't have already an transaction ID, and - /// (2) the is set to true (default: true), and - /// (3) the is set to true (default: true). - /// - public Func GenerateId - { - get => _generateId; - set - { - Guard.NotNull(value, nameof(value), "Correlation function to generate an transaction ID cannot be 'null'"); - _generateId = value; - } - } - } -} diff --git a/src/Arcus.Observability.Correlation/CorrelationInfoUpstreamServiceOptions.cs b/src/Arcus.Observability.Correlation/CorrelationInfoUpstreamServiceOptions.cs deleted file mode 100644 index 8b17a612..00000000 --- a/src/Arcus.Observability.Correlation/CorrelationInfoUpstreamServiceOptions.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using GuardNet; - -namespace Arcus.Observability.Correlation -{ - /// - /// Correlation options specific to the upstream services, used in the . - /// - [Obsolete("Use HTTP, messaging, or custom-specific correlation options instead")] - public class CorrelationInfoUpstreamServiceOptions - { - private string _operationParentIdHeaderName = "Request-Id"; - private Func _generateId = () => Guid.NewGuid().ToString(); - - /// - /// Gets or sets the flag indicating whether or not the upstream service information should be extracted from the following the W3C Trace-Context standard. - /// - public bool ExtractFromRequest { get; set; } = true; - - /// - /// Gets or sets the request header name where te operation parent ID is located (default: "Request-Id"). - /// - /// Thrown when the is blank. - public string OperationParentIdHeaderName - { - get => _operationParentIdHeaderName; - set - { - Guard.NotNullOrWhitespace(value, nameof(value), "Requires a non-blank value for the operation parent ID request header name"); - _operationParentIdHeaderName = value; - } - } - - /// - /// Gets or sets the function to generate the operation parent ID without extracting from the request. - /// - /// Thrown when the is null. - public Func GenerateId - { - get => _generateId; - set - { - Guard.NotNull(value, nameof(value), "Requires a function to generate the operation parent ID"); - _generateId = value; - } - } - } -} diff --git a/src/Arcus.Observability.Correlation/DefaultCorrelationInfoAccessor.cs b/src/Arcus.Observability.Correlation/DefaultCorrelationInfoAccessor.cs index c1247230..db854753 100644 --- a/src/Arcus.Observability.Correlation/DefaultCorrelationInfoAccessor.cs +++ b/src/Arcus.Observability.Correlation/DefaultCorrelationInfoAccessor.cs @@ -1,23 +1,9 @@ -using System; - -namespace Arcus.Observability.Correlation +namespace Arcus.Observability.Correlation { /// /// Default implementation to access the in the current context. /// public class DefaultCorrelationInfoAccessor : DefaultCorrelationInfoAccessor, ICorrelationInfoAccessor { - /// - /// Prevents a new instance of the class from being created. - /// - public DefaultCorrelationInfoAccessor() - { - } - - /// - /// Gets the default instance for the class. - /// - [Obsolete("Create a new instance instead of using this static value")] - public new static DefaultCorrelationInfoAccessor Instance { get; } = new DefaultCorrelationInfoAccessor(); } } \ No newline at end of file diff --git a/src/Arcus.Observability.Correlation/DefaultCorrelationInfoAccessorT.cs b/src/Arcus.Observability.Correlation/DefaultCorrelationInfoAccessorT.cs index c8a23f34..c023a14f 100644 --- a/src/Arcus.Observability.Correlation/DefaultCorrelationInfoAccessorT.cs +++ b/src/Arcus.Observability.Correlation/DefaultCorrelationInfoAccessorT.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading; +using System.Threading; namespace Arcus.Observability.Correlation { @@ -11,13 +10,6 @@ public class DefaultCorrelationInfoAccessor : ICorrelationInfo { private TCorrelationInfo _correlationInfo; - /// - /// Prevents a new instance of the class from being created. - /// - public DefaultCorrelationInfoAccessor() - { - } - /// /// Gets the current correlation information initialized in this context. /// @@ -34,11 +26,5 @@ public void SetCorrelationInfo(TCorrelationInfo correlationInfo) { Interlocked.Exchange(ref _correlationInfo, correlationInfo); } - - /// - /// Gets the default instance for the class. - /// - [Obsolete("Create a new instance instead of using this static value")] - public static DefaultCorrelationInfoAccessor Instance { get; } = new DefaultCorrelationInfoAccessor(); } } diff --git a/src/Arcus.Observability.Correlation/IServiceCollectionExtensions.cs b/src/Arcus.Observability.Correlation/IServiceCollectionExtensions.cs index 06a5dc00..daa63353 100644 --- a/src/Arcus.Observability.Correlation/IServiceCollectionExtensions.cs +++ b/src/Arcus.Observability.Correlation/IServiceCollectionExtensions.cs @@ -23,21 +23,6 @@ public static IServiceCollection AddCorrelation(this IServiceCollection services return AddCorrelation(services); } - /// - /// Adds operation and transaction correlation to the application using the - /// - /// The services collection containing the dependency injection services. - /// The function to configure additional options how the correlation works. - [Obsolete("Use HTTP, messaging, or custom-specific correlation registration instead")] - public static IServiceCollection AddCorrelation( - this IServiceCollection services, - Action configureOptions) - { - Guard.NotNull(services, nameof(services)); - - return AddCorrelation(services, new DefaultCorrelationInfoAccessor(), configureOptions); - } - /// /// Adds operation and transaction correlation to the application using the /// @@ -55,65 +40,6 @@ public static IServiceCollection AddCorrelation(this IServiceCollection services provider => new DefaultCorrelationInfoAccessor()); } - /// - /// Adds operation and transaction correlation to the application using the - /// - /// The type of the model. - /// The services collection containing the dependency injection services. - /// The function to configure additional options how the correlation works. - [Obsolete("Use HTTP, messaging, or custom-specific correlation registration instead")] - public static IServiceCollection AddCorrelation( - this IServiceCollection services, - Action configureOptions) - where TCorrelationInfo : CorrelationInfo - { - Guard.NotNull(services, nameof(services)); - - return AddCorrelation(services, configureOptions); - } - - /// - /// Adds operation and transaction correlation to the application using the . - /// - /// The type of the model. - /// The type of the custom model. - /// The services collection containing the dependency injection services. - /// The function to configure additional options how the correlation works. - [Obsolete("Use HTTP, messaging, or custom-specific correlation registration instead")] - public static IServiceCollection AddCorrelation( - this IServiceCollection services, - Action configureOptions = null) - where TCorrelationInfo : CorrelationInfo - where TOptions : CorrelationInfoOptions - { - Guard.NotNull(services, nameof(services)); - - return AddCorrelation, TCorrelationInfo, TOptions>( - services, - serviceProvider => new DefaultCorrelationInfoAccessor(), - configureOptions); - } - - /// - /// Adds operation and transaction correlation to the application. - /// - /// The type of the implementation. - /// The services collection containing the dependency injection services. - /// The custom implementation to retrieve the . - /// The function to configure additional options how the correlation works. - [Obsolete("Use HTTP, messaging, or custom-specific correlation registration instead")] - public static IServiceCollection AddCorrelation( - this IServiceCollection services, - TAccessor customCorrelationAccessor, - Action configureOptions = null) - where TAccessor : class, ICorrelationInfoAccessor - { - Guard.NotNull(services, nameof(services)); - Guard.NotNull(customCorrelationAccessor, nameof(customCorrelationAccessor)); - - return AddCorrelation(services, serviceProvider => customCorrelationAccessor, configureOptions); - } - /// /// Adds operation and transaction correlation to the application. /// @@ -132,26 +58,6 @@ public static IServiceCollection AddCorrelation(this IServiceCollection services return AddCorrelation(services, createCustomCorrelationAccessor); } - /// - /// Adds operation and transaction correlation to the application. - /// - /// The type of the implementation. - /// The services collection containing the dependency injection services. - /// The custom implementation factory to retrieve the . - /// The function to configure additional options how the correlation works. - [Obsolete("Use HTTP, messaging, or custom-specific correlation registration instead")] - public static IServiceCollection AddCorrelation( - this IServiceCollection services, - Func createCustomCorrelationAccessor, - Action configureOptions) - where TAccessor : class, ICorrelationInfoAccessor - { - Guard.NotNull(services, nameof(services)); - Guard.NotNull(createCustomCorrelationAccessor, nameof(createCustomCorrelationAccessor)); - - return AddCorrelation(services, createCustomCorrelationAccessor, configureOptions); - } - /// /// Adds operation and transaction correlation to the application. /// @@ -178,60 +84,5 @@ public static IServiceCollection AddCorrelation(this IServiceCollection services return services; } - - /// - /// Adds operation and transaction correlation to the application. - /// - /// The type of the implementation. - /// The type of the custom model. - /// The services collection containing the dependency injection services. - /// The custom implementation factory to retrieve the . - /// The function to configure additional options how the correlation works. - [Obsolete("Use HTTP, messaging, or custom-specific correlation registration instead")] - public static IServiceCollection AddCorrelation( - this IServiceCollection services, - Func createCustomCorrelationAccessor, - Action configureOptions) - where TAccessor : class, ICorrelationInfoAccessor - where TCorrelationInfo : CorrelationInfo - { - Guard.NotNull(services, nameof(services)); - Guard.NotNull(createCustomCorrelationAccessor, nameof(createCustomCorrelationAccessor)); - - return AddCorrelation(services, createCustomCorrelationAccessor, configureOptions); - } - - /// - /// Adds operation and transaction correlation to the application. - /// - /// The type of the implementation. - /// The type of the custom model. - /// The type of the custom model. - /// The services collection containing the dependency injection services. - /// The custom implementation factory to retrieve the . - /// The function to configure additional options how the correlation works. - [Obsolete("Use HTTP, messaging, or custom-specific correlation registration instead")] - public static IServiceCollection AddCorrelation( - this IServiceCollection services, - Func createCustomCorrelationAccessor, - Action configureOptions) - where TAccessor : class, ICorrelationInfoAccessor - where TCorrelationInfo : CorrelationInfo - where TOptions : CorrelationInfoOptions - { - Guard.NotNull(services, nameof(services)); - Guard.NotNull(createCustomCorrelationAccessor, nameof(createCustomCorrelationAccessor)); - - services.AddScoped>(createCustomCorrelationAccessor); - services.AddScoped(serviceProvider => - { - return new CorrelationInfoAccessorProxy( - serviceProvider.GetRequiredService>()); - }); - - services.Configure(options => configureOptions?.Invoke(options)); - - return services; - } } } diff --git a/src/Arcus.Observability.Telemetry.Serilog.Enrichers/Extensions/LoggerEnrichmentConfigurationExtensions.cs b/src/Arcus.Observability.Telemetry.Serilog.Enrichers/Extensions/LoggerEnrichmentConfigurationExtensions.cs index 0f26f7b3..bff32634 100644 --- a/src/Arcus.Observability.Telemetry.Serilog.Enrichers/Extensions/LoggerEnrichmentConfigurationExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Serilog.Enrichers/Extensions/LoggerEnrichmentConfigurationExtensions.cs @@ -145,27 +145,6 @@ public static LoggerConfiguration WithVersion(this LoggerEnrichmentConfiguration return enrichmentConfiguration.With(new KubernetesEnricher(nodeNamePropertyName, podNamePropertyName, namespacePropertyName)); } - /// - /// Adds the to the logger enrichment configuration which adds the information from the current context. - /// - /// The configuration to add the enricher. - /// The name of the property to enrich the log event with the correlation operation ID. - /// The name of the property to enrich the log event with the correlation transaction ID. - /// Thrown when the is null. - /// Thrown when the or is blank. - [Obsolete("Use the " + nameof(WithCorrelationInfo) + " overload with providing your own default correlation accessor")] - public static LoggerConfiguration WithCorrelationInfo( - this LoggerEnrichmentConfiguration enrichmentConfiguration, - string operationIdPropertyName = ContextProperties.Correlation.OperationId, - string transactionIdPropertyName = ContextProperties.Correlation.TransactionId) - { - Guard.NotNull(enrichmentConfiguration, nameof(enrichmentConfiguration), "Requires an enrichment configuration to add the correlation information enricher"); - Guard.NotNullOrWhitespace(operationIdPropertyName, nameof(operationIdPropertyName), "Requires a property name to enrich the log event with the correlation operation ID"); - Guard.NotNullOrWhitespace(transactionIdPropertyName, nameof(transactionIdPropertyName), "Requires a property name to enrich the log event with the correlation transaction ID"); - - return WithCorrelationInfo(enrichmentConfiguration, DefaultCorrelationInfoAccessor.Instance, operationIdPropertyName, transactionIdPropertyName); - } - /// /// Adds the previously registered to the logger enrichment configuration which adds the information from the current context. /// @@ -212,28 +191,6 @@ public static LoggerConfiguration WithVersion(this LoggerEnrichmentConfiguration return WithCorrelationInfo(enrichmentConfiguration, accessor, configureOptions); } - /// - /// Adds the to the logger enrichment configuration which adds the information from the current context. - /// - /// The configuration to add the enricher. - /// The name of the property to enrich the log event with the correlation operation ID. - /// The name of the property to enrich the log event with the correlation transaction ID. - /// Thrown when the is null. - /// Thrown when the or is blank. - [Obsolete("Use the " + nameof(WithCorrelationInfo) + " overload with providing your own default correlation accessor")] - public static LoggerConfiguration WithCorrelationInfo( - this LoggerEnrichmentConfiguration enrichmentConfiguration, - string operationIdPropertyName = ContextProperties.Correlation.OperationId, - string transactionIdPropertyName = ContextProperties.Correlation.TransactionId) - where TCorrelationInfo : CorrelationInfo - { - Guard.NotNull(enrichmentConfiguration, nameof(enrichmentConfiguration), "Requires an enrichment configuration to add the correlation information enricher"); - Guard.NotNullOrWhitespace(operationIdPropertyName, nameof(operationIdPropertyName), "Requires a property name to enrich the log event with the correlation operation ID"); - Guard.NotNullOrWhitespace(transactionIdPropertyName, nameof(transactionIdPropertyName), "Requires a property name to enrich the log event with the correlation transaction ID"); - - return WithCorrelationInfo(enrichmentConfiguration, DefaultCorrelationInfoAccessor.Instance, operationIdPropertyName, transactionIdPropertyName); - } - /// /// Adds the to the logger enrichment configuration which adds the information from the current context. /// diff --git a/src/Arcus.Observability.Tests.Unit/Correlation/CorrelationInfoOptionsTests.cs b/src/Arcus.Observability.Tests.Unit/Correlation/CorrelationInfoOptionsTests.cs deleted file mode 100644 index a405cdee..00000000 --- a/src/Arcus.Observability.Tests.Unit/Correlation/CorrelationInfoOptionsTests.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Arcus.Observability.Correlation; -using Xunit; - -namespace Arcus.Observability.Tests.Unit.Correlation -{ - [Trait("Category", "Unit")] - public class CorrelationInfoOptionsTests - { - [Fact] - public void OperationParentIdPropertyName_HasDefault_Succeeds() - { - // Arrange - var options = new CorrelationInfoOptions(); - - // Act / Assert - Assert.NotEmpty(options.OperationParent.OperationParentIdHeaderName); - } - - [Theory] - [ClassData(typeof(Blanks))] - public void SetOperationParentIdPropertyName_WithBlankValue_Fails(string operationIdPropertyName) - { - // Arrange - var options = new CorrelationInfoOptions(); - - // Act / Assert - Assert.ThrowsAny(() => - options.OperationParent.OperationParentIdHeaderName = operationIdPropertyName); - } - - [Fact] - public void OperationParentId_WithoutGeneration_Fails() - { - // Arrange - var options = new CorrelationInfoOptions(); - - // Act / Assert - Assert.ThrowsAny(() => options.OperationParent.GenerateId = null); - } - } -} diff --git a/src/Arcus.Observability.Tests.Unit/Correlation/DefaultCorrelationInfoAccessorTests.cs b/src/Arcus.Observability.Tests.Unit/Correlation/DefaultCorrelationInfoAccessorTests.cs deleted file mode 100644 index 9202449b..00000000 --- a/src/Arcus.Observability.Tests.Unit/Correlation/DefaultCorrelationInfoAccessorTests.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Threading.Tasks; -using Arcus.Observability.Correlation; -using Xunit; - -namespace Arcus.Observability.Tests.Unit.Correlation -{ - public class DefaultCorrelationInfoAccessorTests - { - [Fact] - public async Task SetCorrelationInfo_Twice_UsesMostRecentValueInAsynchContext() - { - // Arrange - var firstOperationId = $"operation-{Guid.NewGuid()}"; - var secondOperationId = $"operation-{Guid.NewGuid()}"; - var transactionId = $"transaction-{Guid.NewGuid()}"; - await SetCorrelationInfoAsync(firstOperationId, transactionId); - - // Act - await SetCorrelationInfoAsync(secondOperationId, transactionId); - - // Assert - CorrelationInfo correlationInfo = DefaultCorrelationInfoAccessor.Instance.GetCorrelationInfo(); - Assert.Equal(secondOperationId, correlationInfo.OperationId); - Assert.Equal(transactionId, correlationInfo.TransactionId); - } - - private async Task SetCorrelationInfoAsync(string operationId, string transactionId) - { - await Task.Run(() => DefaultCorrelationInfoAccessor.Instance.SetCorrelationInfo( - new CorrelationInfo(operationId, transactionId))); - } - } -} diff --git a/src/Arcus.Observability.Tests.Unit/Correlation/IServiceCollectionExtensionsTests.cs b/src/Arcus.Observability.Tests.Unit/Correlation/IServiceCollectionExtensionsTests.cs index 79ff49df..392f8a62 100644 --- a/src/Arcus.Observability.Tests.Unit/Correlation/IServiceCollectionExtensionsTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Correlation/IServiceCollectionExtensionsTests.cs @@ -1,7 +1,6 @@ using System; using Arcus.Observability.Correlation; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; using Moq; using Xunit; @@ -25,55 +24,6 @@ public void AddCorrelation_DefaultSetup_RegistersDefaultAccessor() Assert.NotNull(correlationInfoAccessor); } - [Fact] - public void AddCorrelation_DefaultSetupWithOptions_RegistersDefaultAccessorWithOptions() - { - // Arrange - var services = new ServiceCollection(); - services.AddCorrelation(options => options.Operation.IncludeInResponse = true); - - // Act - IServiceProvider serviceProvider = services.BuildServiceProvider(); - - // Assert - var correlationInfoAccessor = serviceProvider.GetService(); - Assert.NotNull(correlationInfoAccessor); - Assert.NotNull(serviceProvider.GetService>()); - } - - [Fact] - public void AddCorrelation_CustomAccessor_RegistersDefaultAccessor() - { - // Arrange - var services = new ServiceCollection(); - var stubAccessor = Mock.Of(); - services.AddCorrelation(stubAccessor); - - // Act - IServiceProvider serviceProvider = services.BuildServiceProvider(); - - // Assert - var correlationInfoAccessor = serviceProvider.GetService(); - Assert.NotNull(correlationInfoAccessor); - } - - [Fact] - public void AddCorrelation_CustomAccessorWithOptions_RegistersCustomAccessorWithOptions() - { - // Arrange - var services = new ServiceCollection(); - var stubAccessor = Mock.Of(); - services.AddCorrelation(stubAccessor, options => options.Transaction.IncludeInResponse = true); - - // Act - IServiceProvider serviceProvider = services.BuildServiceProvider(); - - // Assert - var correlationInfoAccessor = serviceProvider.GetService(); - Assert.NotNull(correlationInfoAccessor); - Assert.NotNull(serviceProvider.GetService>()); - } - [Fact] public void AddCorrelation_CustomAccessorFactory_RegistersCustomAccessor() { @@ -90,23 +40,6 @@ public void AddCorrelation_CustomAccessorFactory_RegistersCustomAccessor() Assert.NotNull(correlationInfoAccessor); } - [Fact] - public void AddCorrelation_CustomAccessorFactoryWithOptions_RegistersCustomAccessorWithOptions() - { - // Arrange - var services = new ServiceCollection(); - var stubAccessor = Mock.Of(); - services.AddCorrelation(provider => stubAccessor, options => options.Operation.IncludeInResponse = true); - - // Act - IServiceProvider serviceProvider = services.BuildServiceProvider(); - - // Assert - var correlationInfoAccessor = serviceProvider.GetService(); - Assert.NotNull(correlationInfoAccessor); - Assert.NotNull(serviceProvider.GetService>()); - } - [Fact] public void AddCorrelation_CustomCorrelationFactory_RegisterCustomCorrelation() { @@ -125,49 +58,5 @@ public void AddCorrelation_CustomCorrelationFactory_RegisterCustomCorrelation() Assert.NotNull(correlationInfoAccessorT); Assert.Same(testCorrelationInfoAccessor, correlationInfoAccessorT); } - - [Fact] - public void AddCorrelation_CustomCorrelationInfoOptionsWithDefaultAccessor_RegisterCustomOptions() - { - // Arrange - string expectedTestOption = $"test-option-{Guid.NewGuid()}"; - var services = new ServiceCollection(); - services.AddCorrelation(options => options.TestOption = expectedTestOption); - - // Act - IServiceProvider serviceProvider = services.BuildServiceProvider(); - - // Assert - Assert.NotNull(serviceProvider.GetService()); - Assert.NotNull(serviceProvider.GetService>()); - var testOptions = serviceProvider.GetService>(); - Assert.NotNull(testOptions); - Assert.NotNull(testOptions.Value); - Assert.Equal(expectedTestOption, testOptions.Value.TestOption); - } - - [Fact] - public void AddCorrelation_CustomCorrelationAccessorWithCustomOptions_RegisterCustomAccessorAndOptions() - { - // Arrange - string expectedTestOption = $"test-option-{Guid.NewGuid()}"; - var testCorrelationInfoProvider = new TestCorrelationInfoAccessor(); - var services = new ServiceCollection(); - services.AddCorrelation( - provider => testCorrelationInfoProvider, - options => options.TestOption = expectedTestOption); - - // Act - IServiceProvider serviceProvider = services.BuildServiceProvider(); - - // Assert - Assert.NotNull(serviceProvider.GetService()); - var correlationInfoAccessor = serviceProvider.GetService>(); - Assert.Same(testCorrelationInfoProvider, correlationInfoAccessor); - var testOptions = serviceProvider.GetService>(); - Assert.NotNull(testOptions); - Assert.NotNull(testOptions.Value); - Assert.Equal(expectedTestOption, testOptions.Value.TestOption); - } } } diff --git a/src/Arcus.Observability.Tests.Unit/Correlation/TestCorrelationInfoOptions.cs b/src/Arcus.Observability.Tests.Unit/Correlation/TestCorrelationInfoOptions.cs deleted file mode 100644 index 972672a0..00000000 --- a/src/Arcus.Observability.Tests.Unit/Correlation/TestCorrelationInfoOptions.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Arcus.Observability.Correlation; - -namespace Arcus.Observability.Tests.Unit.Correlation -{ - /// - /// Test implementation of the . - /// - public class TestCorrelationInfoOptions : CorrelationInfoOptions - { - /// - /// Gets or sets the test option on this testing variant. - /// - public string TestOption { get; set; } - } -} \ No newline at end of file diff --git a/src/Arcus.Observability.Tests.Unit/Serilog/Enrichers/CorrelationInfoEnricherTests.cs b/src/Arcus.Observability.Tests.Unit/Serilog/Enrichers/CorrelationInfoEnricherTests.cs index fe4dada8..b4c9f881 100644 --- a/src/Arcus.Observability.Tests.Unit/Serilog/Enrichers/CorrelationInfoEnricherTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Serilog/Enrichers/CorrelationInfoEnricherTests.cs @@ -15,35 +15,6 @@ namespace Arcus.Observability.Tests.Unit.Serilog.Enrichers [Trait("Category", "Unit")] public class CorrelationInfoEnricherTests { - [Fact] - public void LogEvent_WithStaticDefaultCorrelationInfoAccessor_HasOperationIdAndTransactionId() - { - // Arrange - string expectedOperationId = $"operation-{Guid.NewGuid()}"; - string expectedTransactionId = $"transaction-{Guid.NewGuid()}"; - - var spySink = new InMemoryLogSink(); - var correlationInfoAccessor = DefaultCorrelationInfoAccessor.Instance; - correlationInfoAccessor.SetCorrelationInfo(new CorrelationInfo(expectedOperationId, expectedTransactionId)); - - ILogger logger = new LoggerConfiguration() - .Enrich.WithCorrelationInfo() - .WriteTo.Sink(spySink) - .CreateLogger(); - - // Act - logger.Information("This message will be enriched with correlation information"); - - // Assert - LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); - Assert.True( - logEvent.ContainsProperty(ContextProperties.Correlation.OperationId, expectedOperationId), - $"Expected to have a log property operation ID '{ContextProperties.Correlation.OperationId}' with the value '{expectedOperationId}'"); - Assert.True( - logEvent.ContainsProperty(ContextProperties.Correlation.TransactionId, expectedTransactionId), - $"Expected to have a log property transaction ID '{ContextProperties.Correlation.TransactionId}' with the value '{expectedTransactionId}'"); - } - [Fact] public void LogEvent_WithDefaultCorrelationInfoAccessor_HasOperationIdAndTransactionId() { @@ -106,36 +77,6 @@ public void LogEvent_WithDefaultCorrelationInfoAccessor_HasOperationIdAndTransac $"Expected to have a log property operation parent ID '{ContextProperties.Correlation.OperationParentId}' with the value '{expectedOperationParentId}'"); } - [Fact] - public void LogEvent_WithStaticDefaultCorrelationInfoAccessorWithCustomOperationIdProperty_HasOperationIdAndTransactionId() - { - // Arrange - string operationIdPropertyName = $"operation-name-{Guid.NewGuid():N}"; - string expectedOperationId = $"operation-{Guid.NewGuid()}"; - string expectedTransactionId = $"transaction-{Guid.NewGuid()}"; - - var spySink = new InMemoryLogSink(); - var correlationInfoAccessor = DefaultCorrelationInfoAccessor.Instance; - correlationInfoAccessor.SetCorrelationInfo(new CorrelationInfo(expectedOperationId, expectedTransactionId)); - - ILogger logger = new LoggerConfiguration() - .Enrich.WithCorrelationInfo(operationIdPropertyName: operationIdPropertyName) - .WriteTo.Sink(spySink) - .CreateLogger(); - - // Act - logger.Information("This message will be enriched with correlation information"); - - // Assert - LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); - Assert.True( - logEvent.ContainsProperty(operationIdPropertyName, expectedOperationId), - $"Expected to have a log property operation ID '{operationIdPropertyName}' with the value '{expectedOperationId}'"); - Assert.True( - logEvent.ContainsProperty(ContextProperties.Correlation.TransactionId, expectedTransactionId), - $"Expected to have a log property transaction ID '{ContextProperties.Correlation.TransactionId}' with the value '{expectedTransactionId}'"); - } - [Fact] public void LogEvent_WithDefaultCorrelationInfoAccessorWithCustomOperationIdProperty_HasOperationIdAndTransactionId() { @@ -196,36 +137,6 @@ public void LogEvent_WithDefaultCorrelationInfoAccessorWithCustomOperationIdProp $"Expected to have a log property transaction ID '{ContextProperties.Correlation.TransactionId}' with the value '{expectedTransactionId}'"); } - [Fact] - public void LogEvent_WithStaticDefaultCorrelationInfoAccessorWithCustomTransactionIdProperty_HasOperationIdAndTransactionId() - { - // Arrange - string transactionIdPropertyName = $"transaction-name-{Guid.NewGuid():N}"; - string expectedOperationId = $"operation-{Guid.NewGuid()}"; - string expectedTransactionId = $"transaction-{Guid.NewGuid()}"; - - var spySink = new InMemoryLogSink(); - var correlationInfoAccessor = DefaultCorrelationInfoAccessor.Instance; - correlationInfoAccessor.SetCorrelationInfo(new CorrelationInfo(expectedOperationId, expectedTransactionId)); - - ILogger logger = new LoggerConfiguration() - .Enrich.WithCorrelationInfo(transactionIdPropertyName: transactionIdPropertyName) - .WriteTo.Sink(spySink) - .CreateLogger(); - - // Act - logger.Information("This message will be enriched with correlation information"); - - // Assert - LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); - Assert.True( - logEvent.ContainsProperty(ContextProperties.Correlation.OperationId, expectedOperationId), - $"Expected to have a log property operation ID '{ContextProperties.Correlation.OperationId}' with the value '{expectedOperationId}'"); - Assert.True( - logEvent.ContainsProperty(transactionIdPropertyName, expectedTransactionId), - $"Expected to have a log property transaction ID '{transactionIdPropertyName}' with the value '{expectedTransactionId}'"); - } - [Fact] public void LogEvent_WithDefaultCorrelationInfoAccessorWithCustomTransactionIdProperty_HasOperationIdAndTransactionId() { @@ -320,39 +231,6 @@ public void LogEvent_WithDefaultCorrelationInfoAccessorWithCustomOperationParent $"Expected to have a log property operation parent ID '{operationParentIdPropertyName}' with the value '{expectedOperationParentId}'"); } - [Fact] - public void LogEvent_WithStaticDefaultCorrelationInfoAccessorT_HasOperationIdAndTransactionId() - { - // Arrange - string expectedOperationId = $"operation-{Guid.NewGuid()}"; - string expectedTransactionId = $"transaction-{Guid.NewGuid()}"; - string expectedTestId = $"test-{Guid.NewGuid()}"; - - var spySink = new InMemoryLogSink(); - var correlationInfoAccessor = DefaultCorrelationInfoAccessor.Instance; - correlationInfoAccessor.SetCorrelationInfo(new TestCorrelationInfo(expectedOperationId, expectedTransactionId, expectedTestId)); - - ILogger logger = new LoggerConfiguration() - .Enrich.WithCorrelationInfo() - .WriteTo.Sink(spySink) - .CreateLogger(); - - // Act - logger.Information("This message will be enriched with correlation information"); - - // Assert - LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); - Assert.True( - logEvent.ContainsProperty(ContextProperties.Correlation.OperationId, expectedOperationId), - $"Expected to have a log property operation ID '{ContextProperties.Correlation.OperationId}' with the value '{expectedOperationId}'"); - Assert.True( - logEvent.ContainsProperty(ContextProperties.Correlation.TransactionId, expectedTransactionId), - $"Expected to have a log property transaction ID '{ContextProperties.Correlation.TransactionId}' with the value '{expectedTransactionId}'"); - Assert.False( - logEvent.ContainsProperty(TestCorrelationInfoEnricher.TestId, expectedTestId), - $"Expected to have a log property test ID '{TestCorrelationInfoEnricher.TestId}' with the value '{expectedTestId}'"); - } - [Fact] public void LogEvent_WithDefaultCorrelationInfoAccessorT_HasOperationIdAndTransactionId() { @@ -386,40 +264,6 @@ public void LogEvent_WithDefaultCorrelationInfoAccessorT_HasOperationIdAndTransa $"Expected to have a log property test ID '{TestCorrelationInfoEnricher.TestId}' with the value '{expectedTestId}'"); } - [Fact] - public void LogEvent_WithStaticDefaultCorrelationInfoAccessorTWithCustomOperationIdProperty_HasOperationIdAndTransactionId() - { - // Arrange - string operationIdPropertyName = $"operation-name-{Guid.NewGuid():N}"; - string expectedOperationId = $"operation-{Guid.NewGuid()}"; - string expectedTransactionId = $"transaction-{Guid.NewGuid()}"; - string expectedTestId = $"test-{Guid.NewGuid()}"; - - var spySink = new InMemoryLogSink(); - var correlationInfoAccessor = DefaultCorrelationInfoAccessor.Instance; - correlationInfoAccessor.SetCorrelationInfo(new TestCorrelationInfo(expectedOperationId, expectedTransactionId, expectedTestId)); - - ILogger logger = new LoggerConfiguration() - .Enrich.WithCorrelationInfo(operationIdPropertyName: operationIdPropertyName) - .WriteTo.Sink(spySink) - .CreateLogger(); - - // Act - logger.Information("This message will be enriched with correlation information"); - - // Assert - LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); - Assert.True( - logEvent.ContainsProperty(operationIdPropertyName, expectedOperationId), - $"Expected to have a log property operation ID '{operationIdPropertyName}' with the value '{expectedOperationId}'"); - Assert.True( - logEvent.ContainsProperty(ContextProperties.Correlation.TransactionId, expectedTransactionId), - $"Expected to have a log property transaction ID '{ContextProperties.Correlation.TransactionId}' with the value '{expectedTransactionId}'"); - Assert.False( - logEvent.ContainsProperty(TestCorrelationInfoEnricher.TestId, expectedTestId), - $"Expected to have a log property test ID '{TestCorrelationInfoEnricher.TestId}' with the value '{expectedTestId}'"); - } - [Fact] public void LogEvent_WithDefaultCorrelationInfoAccessorTWithCustomOperationIdProperty_HasOperationIdAndTransactionId() { @@ -454,40 +298,6 @@ public void LogEvent_WithDefaultCorrelationInfoAccessorTWithCustomOperationIdPro $"Expected to have a log property test ID '{TestCorrelationInfoEnricher.TestId}' with the value '{expectedTestId}'"); } - [Fact] - public void LogEvent_WithStaticDefaultCorrelationInfoAccessorTWithCustomTransactionIdProperty_HasOperationIdAndTransactionId() - { - // Arrange - string transactionIdPropertyName = $"transaction-name-{Guid.NewGuid():N}"; - string expectedOperationId = $"operation-{Guid.NewGuid()}"; - string expectedTransactionId = $"transaction-{Guid.NewGuid()}"; - string expectedTestId = $"test-{Guid.NewGuid()}"; - - var spySink = new InMemoryLogSink(); - var correlationInfoAccessor = DefaultCorrelationInfoAccessor.Instance; - correlationInfoAccessor.SetCorrelationInfo(new TestCorrelationInfo(expectedOperationId, expectedTransactionId, expectedTestId)); - - ILogger logger = new LoggerConfiguration() - .Enrich.WithCorrelationInfo(transactionIdPropertyName: transactionIdPropertyName) - .WriteTo.Sink(spySink) - .CreateLogger(); - - // Act - logger.Information("This message will be enriched with correlation information"); - - // Assert - LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); - Assert.True( - logEvent.ContainsProperty(ContextProperties.Correlation.OperationId, expectedOperationId), - $"Expected to have a log property operation ID '{ContextProperties.Correlation.OperationId}' with the value '{expectedOperationId}'"); - Assert.True( - logEvent.ContainsProperty(transactionIdPropertyName, expectedTransactionId), - $"Expected to have a log property transaction ID '{transactionIdPropertyName}' with the value '{expectedTransactionId}'"); - Assert.False( - logEvent.ContainsProperty(TestCorrelationInfoEnricher.TestId, expectedTestId), - $"Expected to have a log property test ID '{TestCorrelationInfoEnricher.TestId}' with the value '{expectedTestId}'"); - } - [Fact] public void LogEvent_WithDefaultCorrelationInfoAccessorTWithCustomTransactionIdProperty_HasOperationIdAndTransactionId() { @@ -796,30 +606,6 @@ public void CreateEnricher_WithBlankTransactionIdPropertyName_Throws(string tran transactionIdPropertyName: transactionIdPropertyName)); } - [Theory] - [ClassData(typeof(Blanks))] - public void WithCorrelationInfo_WithBlankOperationIdName_Throws(string operationIdPropertyName) - { - // Arrange - var configuration = new LoggerConfiguration(); - - // Act / Assert - Assert.ThrowsAny( - () => configuration.Enrich.WithCorrelationInfo(operationIdPropertyName: operationIdPropertyName)); - } - - [Theory] - [ClassData(typeof(Blanks))] - public void WithCorrelationInfo_WithBlankTransactionIdName_Throws(string transactionIdPropertyName) - { - // Arrange - var configuration = new LoggerConfiguration(); - - // Act / Assert - Assert.ThrowsAny( - () => configuration.Enrich.WithCorrelationInfo(transactionIdPropertyName: transactionIdPropertyName)); - } - [Theory] [ClassData(typeof(Blanks))] public void WithCorrelationInfoAccessor_WithBlankOperationIdName_Throws(string operationIdPropertyName) @@ -882,34 +668,6 @@ public void WithCorrelationInfoAccessor_WithServiceProviderWithBlankTransactionI transactionIdPropertyName: transactionIdPropertyName)); } - [Theory] - [ClassData(typeof(Blanks))] - public void WithCorrelationInfoAccessorT_WithBlankOperationIdName_Throws(string operationIdPropertyName) - { - // Arrange - var configuration = new LoggerConfiguration(); - - // Act / Assert - Assert.ThrowsAny( - () => configuration.Enrich.WithCorrelationInfo( - DefaultCorrelationInfoAccessor.Instance, - operationIdPropertyName: operationIdPropertyName)); - } - - [Theory] - [ClassData(typeof(Blanks))] - public void WithCorrelationInfoAccessorT_WithBlankTransactionIdName_Throws(string transactionIdPropertyName) - { - // Arrange - var configuration = new LoggerConfiguration(); - - // Act / Assert - Assert.ThrowsAny( - () => configuration.Enrich.WithCorrelationInfo( - DefaultCorrelationInfoAccessor.Instance, - transactionIdPropertyName: transactionIdPropertyName)); - } - [Theory] [ClassData(typeof(Blanks))] public void WithCorrelationInfoAccessorT_WithServiceProviderWithBlankOperationIdName_Throws(string operationIdPropertyName)