diff --git a/src/Arcus.Observability.Telemetry.AspNetCore/Extensions/ILoggerHttpDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.AspNetCore/Extensions/ILoggerHttpDependencyExtensions.cs index 3975b784..669c675f 100644 --- a/src/Arcus.Observability.Telemetry.AspNetCore/Extensions/ILoggerHttpDependencyExtensions.cs +++ b/src/Arcus.Observability.Telemetry.AspNetCore/Extensions/ILoggerHttpDependencyExtensions.cs @@ -127,8 +127,6 @@ public static void LogHttpDependency( Guard.NotNull(request, nameof(request), "Requires a HTTP request message to track a HTTP dependency"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the HTTP dependency operation"); - context = context ?? new Dictionary(); - LogHttpDependency(logger, request, statusCode, startTime, duration, dependencyId: null, context); } @@ -193,7 +191,7 @@ public static void LogHttpDependency( Guard.NotLessThan(statusCode, 100, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive"); Guard.NotGreaterThan(statusCode, 599, nameof(statusCode), "Requires a valid HTTP response status code that's within the range of 100 to 599, inclusive"); - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); string requestUri = request.Path; string targetName = request.Host.Host; diff --git a/src/Arcus.Observability.Telemetry.AspNetCore/Extensions/ILoggerRequestExtensions.cs b/src/Arcus.Observability.Telemetry.AspNetCore/Extensions/ILoggerRequestExtensions.cs index c0a1579b..6f1c75b8 100644 --- a/src/Arcus.Observability.Telemetry.AspNetCore/Extensions/ILoggerRequestExtensions.cs +++ b/src/Arcus.Observability.Telemetry.AspNetCore/Extensions/ILoggerRequestExtensions.cs @@ -67,8 +67,6 @@ public static void LogRequest( Guard.NotNull(response, nameof(response), "Requires a HTTP response instance to track a HTTP request operation"); Guard.NotNull(measurement, nameof(measurement), "Requires an measurement instance to time the duration of the HTTP request"); - context = context ?? new Dictionary(); - LogRequest(logger, request, response, measurement.StartTime, measurement.Elapsed, context); } @@ -99,8 +97,6 @@ public static void LogRequest( Guard.NotNull(response, nameof(response), "Requires a HTTP response instance to track a HTTP request operation"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the HTTP request"); - context = context ?? new Dictionary(); - LogRequest(logger, request, response.StatusCode, operationName: null, startTime, duration, context); } @@ -160,8 +156,6 @@ public static void LogRequest( Guard.NotNull(response, nameof(response), "Requires a HTTP response instance to track a HTTP request operation"); Guard.NotNull(measurement, nameof(measurement), "Requires an measurement instance to time the duration of the HTTP request"); - context = context ?? new Dictionary(); - LogRequest(logger, request, response, operationName, measurement.StartTime, measurement.Elapsed, context); } @@ -191,8 +185,6 @@ public static void LogRequest( Guard.NotNull(response, nameof(response), "Requires a HTTP response instance to track a HTTP request operation"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the HTTP request"); - context = context ?? new Dictionary(); - LogRequest(logger, request, response.StatusCode, operationName, startTime, duration, context); } @@ -254,8 +246,6 @@ public static void LogRequest( Guard.NotLessThan(responseStatusCode, 0, nameof(responseStatusCode), "Requires a HTTP response status code that's within the 0-999 range to track a HTTP request"); Guard.NotGreaterThan(responseStatusCode, 999, nameof(responseStatusCode), "Requires a HTTP response status code that's within the 0-999 range to track a HTTP request"); - context = context ?? new Dictionary(); - LogRequest(logger, request, responseStatusCode, measurement.StartTime, measurement.Elapsed, context); } @@ -287,8 +277,6 @@ public static void LogRequest( Guard.NotGreaterThan(responseStatusCode, 999, nameof(responseStatusCode), "Requires a HTTP response status code that's within the 0-999 range to track a HTTP request"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the HTTP request"); - context = context ?? new Dictionary(); - LogRequest(logger, request, responseStatusCode, operationName: null, startTime, duration, context); } @@ -353,8 +341,6 @@ public static void LogRequest( Guard.NotLessThan(responseStatusCode, 0, nameof(responseStatusCode), "Requires a HTTP response status code that's within the 0-999 range to track a HTTP request"); Guard.NotGreaterThan(responseStatusCode, 999, nameof(responseStatusCode), "Requires a HTTP response status code that's within the 0-999 range to track a HTTP request"); - context = context ?? new Dictionary(); - LogRequest(logger, request, responseStatusCode, operationName, measurement.StartTime, measurement.Elapsed, context); } @@ -388,7 +374,7 @@ public static void LogRequest( Guard.NotGreaterThan(responseStatusCode, 999, nameof(responseStatusCode), "Requires a HTTP response status code that's within the 0-999 range to track a HTTP request"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the HTTP request"); - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); logger.LogWarning(MessageFormats.RequestFormat, RequestLogEntry.CreateForHttpRequest( diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerAzureSearchDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerAzureSearchDependencyExtensions.cs index 74852dee..18713d39 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerAzureSearchDependencyExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerAzureSearchDependencyExtensions.cs @@ -67,8 +67,6 @@ public static void LogAzureSearchDependency( Guard.NotNullOrWhitespace(operationName, nameof(operationName), "Requires a non-blank name for the Azure Search service to track the Azure Service dependency"); Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the Azure Search resource when tracking the Azure Search dependency"); - context = context ?? new Dictionary(); - LogAzureSearchDependency(logger, searchServiceName, operationName, isSuccessful, measurement.StartTime, measurement.Elapsed, context); } @@ -98,8 +96,6 @@ public static void LogAzureSearchDependency( Guard.NotNullOrWhitespace(operationName, nameof(operationName), "Requires a non-blank name for the Azure Search service to track the Azure Service dependency"); Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the Azure Search resource when tracking the Azure Search dependency"); - context = context ?? new Dictionary(); - LogAzureSearchDependency(logger, searchServiceName, operationName, isSuccessful, measurement.StartTime, measurement.Elapsed, dependencyId, context); } @@ -129,8 +125,6 @@ public static void LogAzureSearchDependency( Guard.NotNullOrWhitespace(operationName, nameof(operationName), "Requires a non-blank name for the Azure Search service to track the Azure Service dependency"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the Azure Search operation"); - context = context ?? new Dictionary(); - LogAzureSearchDependency(logger, searchServiceName, operationName, isSuccessful, startTime, duration, dependencyId: null, context); } @@ -162,7 +156,7 @@ public static void LogAzureSearchDependency( Guard.NotNullOrWhitespace(operationName, nameof(operationName), "Requires a non-blank name for the Azure Search service to track the Azure Service dependency"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the Azure Search operation"); - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); logger.LogWarning(MessageFormats.DependencyFormat, new DependencyLogEntry( dependencyType: "Azure Search", diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs index 0ce9846e..9c45b503 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs @@ -136,8 +136,6 @@ public static void LogCosmosSqlDependency( Guard.NotNullOrWhitespace(container, nameof(container), "Requires a non-blank container name of the Cosmos SQL storage to track a Cosmos SQL dependency"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the Cosmos SQL operation"); - context = context ?? new Dictionary(); - LogCosmosSqlDependency(logger, accountName, database, container, isSuccessful, startTime, duration, dependencyId: null, context); } @@ -173,7 +171,7 @@ public static void LogCosmosSqlDependency( Guard.NotNullOrWhitespace(container, nameof(container), "Requires a non-blank container name of the Cosmos SQL storage to track a Cosmos SQL dependency"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the Cosmos SQL operation"); - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); string data = $"{database}/{container}"; logger.LogWarning(MessageFormats.DependencyFormat, new DependencyLogEntry( diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs index 989d7c70..4da0309b 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs @@ -636,8 +636,6 @@ public static void LogDependency( Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the dependency operation"); - context = context ?? new Dictionary(); - LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, dependencyName, startTime, duration, dependencyId: null, context); } @@ -676,7 +674,7 @@ public static void LogDependency( Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the dependency operation"); - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); logger.LogWarning(MessageFormats.DependencyFormat, new DependencyLogEntry( dependencyType, diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventExtensions.cs index a789a1cf..41676fc1 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventExtensions.cs @@ -45,7 +45,7 @@ public static void LogCustomEvent(this ILogger logger, string name, Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); logger.LogWarning(MessageFormats.EventFormat, new EventLogEntry(name, context)); } diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventHubsDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventHubsDependencyExtensions.cs index 99839860..a4d261b3 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventHubsDependencyExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventHubsDependencyExtensions.cs @@ -124,8 +124,6 @@ public static void LogEventHubsDependency( Guard.NotNullOrWhitespace(eventHubName, nameof(eventHubName), "Requires a non-blank Azure Event Hub name to track an Azure Event Hub dependency"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the Azure Events Hubs operation"); - context = context ?? new Dictionary(); - LogEventHubsDependency(logger, namespaceName, eventHubName, isSuccessful, startTime, duration, dependencyId: null, context); } @@ -158,7 +156,7 @@ public static void LogEventHubsDependency( Guard.NotNullOrWhitespace(eventHubName, nameof(eventHubName), "Requires a non-blank Azure Event Hub name to track an Azure Event Hub dependency"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the Azure Events Hubs operation"); - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); logger.LogWarning(MessageFormats.DependencyFormat, new DependencyLogEntry( dependencyType: "Azure Event Hubs", diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventHubsRequestExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventHubsRequestExtensions.cs index a83080f6..ae046aae 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventHubsRequestExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventHubsRequestExtensions.cs @@ -143,7 +143,7 @@ public static void LogEventHubsRequest( operationName = ContextProperties.RequestTracking.EventHubs.DefaultOperationName; } - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); context[ContextProperties.RequestTracking.EventHubs.Namespace] = eventHubsNamespace; context[ContextProperties.RequestTracking.EventHubs.ConsumerGroup] = consumerGroup; context[ContextProperties.RequestTracking.EventHubs.Name] = eventHubsName; diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerGeneralRequestExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerGeneralRequestExtensions.cs index dd64fc23..66a48c81 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerGeneralRequestExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerGeneralRequestExtensions.cs @@ -121,7 +121,7 @@ public static void LogCustomRequest( operationName = ContextProperties.RequestTracking.DefaultOperationName; } - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); logger.LogWarning(MessageFormats.RequestFormat, RequestLogEntry.CreateForCustomRequest(requestSource, operationName, isSuccessful, duration, startTime, context)); } diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerServiceBusDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerServiceBusDependencyExtensions.cs index e2bb4012..c829be45 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerServiceBusDependencyExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerServiceBusDependencyExtensions.cs @@ -448,7 +448,7 @@ public static void LogServiceBusDependency( Guard.NotNullOrWhitespace(entityName, nameof(entityName), "Requires a non-blank Azure Service Bus entity name to track an Azure Service Bus dependency"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the Azure Service Bus operation"); - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); context[ContextProperties.DependencyTracking.ServiceBus.EntityType] = entityType; context[ContextProperties.DependencyTracking.ServiceBus.Endpoint] = serviceBusNamespaceEndpoint; diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerServiceBusRequestExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerServiceBusRequestExtensions.cs index 4d7b6b25..25be4038 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerServiceBusRequestExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerServiceBusRequestExtensions.cs @@ -121,7 +121,7 @@ public static void LogServiceBusTopicRequestWithSuffix( Guard.NotNullOrWhitespace(subscriptionName, nameof(subscriptionName), "Requires an Azure Service Bus subscription name on the to track the topic request"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the Azure Service Bus topic request operation"); - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); context[ContextProperties.RequestTracking.ServiceBus.Topic.SubscriptionName] = subscriptionName; LogServiceBusRequestWithSuffix(logger, serviceBusNamespace, serviceBusNamespaceSuffix, topicName, operationName, isSuccessful, duration, startTime, ServiceBusEntityType.Topic, context); @@ -159,7 +159,7 @@ public static void LogServiceBusTopicRequest( Guard.NotNullOrWhitespace(subscriptionName, nameof(subscriptionName), "Requires an Azure Service Bus subscription name on the to track the topic request"); Guard.NotLessThan(duration, TimeSpan.Zero, nameof(duration), "Requires a positive time duration of the Azure Service Bus topic request operation"); - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); context[ContextProperties.RequestTracking.ServiceBus.Topic.SubscriptionName] = subscriptionName; LogServiceBusRequest(logger, serviceBusNamespace, topicName, operationName, isSuccessful, duration, startTime, ServiceBusEntityType.Topic, context); @@ -431,7 +431,7 @@ public static void LogServiceBusRequest( operationName = ContextProperties.RequestTracking.ServiceBus.DefaultOperationName; } - context = context ?? new Dictionary(); + context = context is null ? new Dictionary() : new Dictionary(context); context[ContextProperties.RequestTracking.ServiceBus.Endpoint] = serviceBusNamespace; context[ContextProperties.RequestTracking.ServiceBus.EntityName] = entityName; context[ContextProperties.RequestTracking.ServiceBus.EntityType] = entityType; diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureSearchDependencyLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureSearchDependencyLoggingTests.cs index 0338e0cc..ddad04be 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureSearchDependencyLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureSearchDependencyLoggingTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Arcus.Observability.Telemetry.Core; using Arcus.Observability.Telemetry.Core.Logging; using Bogus; @@ -307,5 +308,25 @@ public void LogAzureSearchDependencyWithDependencyIdWithDurationMeasurement_With Assert.ThrowsAny( () => logger.LogAzureSearchDependency(searchServiceName, operationName, isSuccessful, measurement: (DurationMeasurement)null, dependencyId)); } + + [Fact] + public void LogAzureSearchDependency_WithContext_DoesNotAlterContext() + { + // Arrange + var logger = new TestLogger(); + string searchServiceName = _bogusGenerator.Commerce.ProductName(); + string operationName = _bogusGenerator.Commerce.ProductName(); + bool isSuccessful = _bogusGenerator.PickRandom(true, false); + string dependencyId = _bogusGenerator.Lorem.Word(); + var startTime = _bogusGenerator.Date.RecentOffset(); + var duration = _bogusGenerator.Date.Timespan(); + var context = new Dictionary(); + + // Act + logger.LogAzureSearchDependency(searchServiceName, operationName, isSuccessful, startTime, duration, dependencyId, context); + + // Assert + Assert.Empty(context); + } } } diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureServiceBusDependencyLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureServiceBusDependencyLoggingTests.cs index 142c49ca..1ca79af7 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureServiceBusDependencyLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureServiceBusDependencyLoggingTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Arcus.Observability.Telemetry.Core; using Arcus.Observability.Telemetry.Core.Logging; using Bogus; @@ -801,5 +802,26 @@ public void LogServiceBusTopicDependencyWithDependencyIdWithDurationMeasurement_ Assert.ThrowsAny( () => logger.LogServiceBusTopicDependency(namespaceEndpoint, topicName, isSuccessful, measurement: null, dependencyId)); } + + [Fact] + public void LogServiceBusDependency_WithContext_DoesNotAlterContext() + { + // Arrange + var logger = new TestLogger(); + string namespaceEndpoint = BogusGenerator.Commerce.Product(); + string topicName = BogusGenerator.Commerce.Product(); + bool isSuccessful = BogusGenerator.PickRandom(true, false); + string dependencyId = BogusGenerator.Lorem.Word(); + var startTime = BogusGenerator.Date.RecentOffset(); + var duration = BogusGenerator.Date.Timespan(); + var entityType = BogusGenerator.PickRandom(); + var context = new Dictionary(); + + // Act + logger.LogServiceBusDependency(namespaceEndpoint, topicName, isSuccessful, startTime, duration, dependencyId, entityType, context); + + // Assert + Assert.Empty(context); + } } } diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureServiceBusRequestLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureServiceBusRequestLoggingTests.cs index 88992604..efbcf4c1 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureServiceBusRequestLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/AzureServiceBusRequestLoggingTests.cs @@ -1764,5 +1764,115 @@ public void LogServiceBusRequestWithSuffix_WithNegativeDuration_Fails() Assert.ThrowsAny( () => logger.LogServiceBusRequestWithSuffix(serviceBusNamespace, serviceBusNamespaceSuffix, entityName, operationName, isSuccessful, negativeDuration, startTime, entryType, context)); } + + [Fact] + public void LogServiceBusTopicRequest_WithContext_DoesNotAlterContext() + { + // Arrange + // Arrange + var logger = new TestLogger(); + string serviceBusNamespace = _bogusGenerator.Lorem.Word(); + string topicName = _bogusGenerator.Lorem.Word(); + string subscriptionName = _bogusGenerator.Lorem.Word(); + string operationName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.Random.Bool(); + var startTime = _bogusGenerator.Date.RecentOffset(); + var duration = _bogusGenerator.Date.Timespan(); + var context = new Dictionary(); + + // Act + logger.LogServiceBusTopicRequest(serviceBusNamespace, topicName, subscriptionName, operationName, isSuccessful, duration, startTime, context); + + // Assert + Assert.Empty(context); + } + + [Fact] + public void LogServiceBusTopicRequestWithSuffix_WithContext_DoesNotAlterContext() + { + // Arrange + // Arrange + var logger = new TestLogger(); + string serviceBusNamespace = _bogusGenerator.Lorem.Word(); + string suffix = _bogusGenerator.Lorem.Word(); + string topicName = _bogusGenerator.Lorem.Word(); + string subscriptionName = _bogusGenerator.Lorem.Word(); + string operationName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.Random.Bool(); + var startTime = _bogusGenerator.Date.RecentOffset(); + var duration = _bogusGenerator.Date.Timespan(); + var context = new Dictionary(); + + // Act + logger.LogServiceBusTopicRequestWithSuffix(serviceBusNamespace, suffix, topicName, subscriptionName, operationName, isSuccessful, duration, startTime, context); + + // Assert + Assert.Empty(context); + } + + [Fact] + public void LogServiceBusQueueRequest_WithContext_DoesNotAlterContext() + { + // Arrange + // Arrange + var logger = new TestLogger(); + string serviceBusNamespace = _bogusGenerator.Lorem.Word(); + string queueName = _bogusGenerator.Lorem.Word(); + string operationName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.Random.Bool(); + var startTime = _bogusGenerator.Date.RecentOffset(); + var duration = _bogusGenerator.Date.Timespan(); + var context = new Dictionary(); + + // Act + logger.LogServiceBusQueueRequest(serviceBusNamespace, queueName, operationName, isSuccessful, duration, startTime, context); + + // Assert + Assert.Empty(context); + } + + [Fact] + public void LogServiceBusQueueRequestWithSuffix_WithContext_DoesNotAlterContext() + { + // Arrange + // Arrange + var logger = new TestLogger(); + string serviceBusNamespace = _bogusGenerator.Lorem.Word(); + string suffix = _bogusGenerator.Lorem.Word(); + string queueName = _bogusGenerator.Lorem.Word(); + string operationName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.Random.Bool(); + var startTime = _bogusGenerator.Date.RecentOffset(); + var duration = _bogusGenerator.Date.Timespan(); + var context = new Dictionary(); + + // Act + logger.LogServiceBusQueueRequestWithSuffix(serviceBusNamespace, suffix, queueName, operationName, isSuccessful, duration, startTime, context); + + // Assert + Assert.Empty(context); + } + + [Fact] + public void LogServiceBusRequest_WithContext_DoesNotAlterContext() + { + // Arrange + // Arrange + var logger = new TestLogger(); + string serviceBusNamespace = _bogusGenerator.Lorem.Word(); + string entityName = _bogusGenerator.Lorem.Word(); + string operationName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.Random.Bool(); + var startTime = _bogusGenerator.Date.RecentOffset(); + var duration = _bogusGenerator.Date.Timespan(); + var entityType = _bogusGenerator.Random.Enum(); + var context = new Dictionary(); + + // Act + logger.LogServiceBusRequest(serviceBusNamespace, entityName, operationName, isSuccessful, duration, startTime, entityType, context); + + // Assert + Assert.Empty(context); + } } } diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CosmosSqlDependencyLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CosmosSqlDependencyLoggingTests.cs index 222d24c9..e3dae30f 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CosmosSqlDependencyLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CosmosSqlDependencyLoggingTests.cs @@ -349,5 +349,26 @@ public void LogCosmosSqlDependencyWithDurationMeasurementWithDependencyId_Withou Assert.ThrowsAny( () => logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, measurement: null, dependencyId)); } + + [Fact] + public void LogCosmosSqlDependency_WithContext_DoesNotAlterContext() + { + // Arrange + var logger = new TestLogger(); + string database = BogusGenerator.Commerce.ProductName(); + string container = BogusGenerator.Commerce.ProductName(); + string accountName = BogusGenerator.Finance.AccountName(); + bool isSuccessful = BogusGenerator.Random.Bool(); + var startTime = BogusGenerator.Date.RecentOffset(); + var duration = BogusGenerator.Date.Timespan(); + var dependencyId = BogusGenerator.Random.Guid().ToString(); + var context = new Dictionary(); + + // Act + logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, startTime, duration, dependencyId, context); + + // Assert + Assert.Empty(context); + } } } diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs index 3d977fc0..4b1fe3a2 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs @@ -1474,5 +1474,26 @@ public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependen // Act / Assert Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement: null, dependencyId)); } + + [Fact] + public void LogDependency_WithContext_DoesNotAlterContext() + { + // Arrange + var logger = new TestLogger(); + string dependencyType = _bogusGenerator.Lorem.Word(); + var dependencyData = _bogusGenerator.Random.Int().ToString(); + string targetName = _bogusGenerator.Lorem.Word(); + bool isSuccessful = _bogusGenerator.Random.Bool(); + var startTime = _bogusGenerator.Date.RecentOffset(); + var duration = _bogusGenerator.Date.Timespan(); + string dependencyId = _bogusGenerator.Random.Guid().ToString(); + var context = new Dictionary(); + + // Act + logger.LogDependency(dependencyType, dependencyData, isSuccessful, targetName, startTime, duration, dependencyId, context); + + // Assert + Assert.Empty(context); + } } } diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomRequestLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomRequestLoggingTests.cs index bf2a59dd..52110096 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomRequestLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomRequestLoggingTests.cs @@ -239,5 +239,24 @@ public void LogWithOperationName_WithNegativeDuration_Fails() Assert.ThrowsAny( () => logger.LogCustomRequest(customRequestSource, operationName, isSuccessful, startTime, duration)); } + + [Fact] + public void LogCustomRequest_WithContext_DoesNotAlterContext() + { + // Arrange + var logger = new TestLogger(); + string customRequestSource = BogusGenerator.Lorem.Word(); + string operationName = BogusGenerator.Lorem.Word(); + bool isSuccessful = BogusGenerator.PickRandom(false, true); + var startTime = BogusGenerator.Date.RecentOffset(); + var duration = BogusGenerator.Date.Timespan(); + var context = new Dictionary(); + + // Act + logger.LogCustomRequest(customRequestSource, operationName, isSuccessful, startTime, duration, context); + + // Assert + Assert.Empty(context); + } } } diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventHubsDependencyLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventHubsDependencyLoggingTests.cs index 6a94dee2..d812c76c 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventHubsDependencyLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventHubsDependencyLoggingTests.cs @@ -365,5 +365,25 @@ public void LogEventHubsDependencyWithDurationMeasurementWithDependencyId_Withou Assert.ThrowsAny( () => logger.LogEventHubsDependency(namespaceName, eventHubName, isSuccessful, measurement: null, dependencyId)); } + + [Fact] + public void LogEventHubsDependency_WithContext_DoesNotAlterContext() + { + // Arrange + var logger = new TestLogger(); + string namespaceName = BogusGenerator.Commerce.ProductName(); + string eventHubName = BogusGenerator.Commerce.ProductName(); + bool isSuccessful = BogusGenerator.Random.Bool(); + var startTime = BogusGenerator.Date.RecentOffset(); + var duration = BogusGenerator.Date.Timespan(); + var dependencyId = BogusGenerator.Random.Guid().ToString(); + var context = new Dictionary(); + + // Act + logger.LogEventHubsDependency(namespaceName, eventHubName, isSuccessful, startTime, duration, dependencyId, context); + + // Assert + Assert.Empty(context); + } } } diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventHubsRequestLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventHubsRequestLoggingTests.cs index 545f98dc..a71d39de 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventHubsRequestLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventHubsRequestLoggingTests.cs @@ -337,5 +337,26 @@ public void LogWithConsumerGroup_WithNegativeDuration_Fails() Assert.ThrowsAny( () => logger.LogEventHubsRequest(@namespace, consumerGroup, eventHubsName, operationName, isSuccessful, startTime, duration)); } + + [Fact] + public void LogEventHubsRequest_WithContext_DoesNotAlterContext() + { + // Arrange + var logger = new TestLogger(); + string @namespace = BogusGenerator.Lorem.Word(); + string consumerGroup = BogusGenerator.Lorem.Word(); + string eventHubsName = BogusGenerator.Lorem.Word(); + string operationName = BogusGenerator.Lorem.Word(); + bool isSuccessful = BogusGenerator.PickRandom(false, true); + var startTime = BogusGenerator.Date.RecentOffset(); + var duration = BogusGenerator.Date.Timespan(); + var context = new Dictionary(); + + // Act + logger.LogEventHubsRequest(@namespace, consumerGroup, eventHubsName, operationName, isSuccessful, startTime, duration, context); + + // Assert + Assert.Empty(context); + } } } diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventLoggingTests.cs index b90d18c0..a6eeb441 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventLoggingTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Arcus.Observability.Telemetry.Core; using Bogus; using Microsoft.Extensions.Logging; @@ -64,5 +65,20 @@ public void LogCustomEvent_NoEventNameSpecified_ThrowsException() // Act & Arrange Assert.Throws(() => logger.LogCustomEvent(eventName)); } + + [Fact] + public void LogCustomEvent_WithContext_DoesNotAlterContext() + { + // Arrange + var logger = new TestLogger(); + string eventName = _bogusGenerator.Lorem.Word(); + var context = new Dictionary(); + + // Act + logger.LogCustomEvent(eventName, context); + + // Assert + Assert.Empty(context); + } } } diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpDependencyLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpDependencyLoggingTests.cs index 7a3b224c..7d57d157 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpDependencyLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpDependencyLoggingTests.cs @@ -620,6 +620,24 @@ public void LogHttpDependencyWithStartDuration_WithContext_DoesNotAlterContext() Assert.Empty(context); } + [Fact] + public void LogHttpDependencyWithRequest_WithContext_DoesNotAlterContext() + { + // Arrange + var logger = new TestLogger(); + HttpRequest request = CreateStubRequest(HttpMethod.Get, "host", "/path", "https"); + int statusCode = (int) BogusGenerator.PickRandom(); + var startTime = BogusGenerator.Date.RecentOffset(); + var duration = BogusGenerator.Date.Timespan(); + var dependencyId = BogusGenerator.Random.Guid().ToString(); + var context = new Dictionary(); + + // Act + logger.LogHttpDependency(request, statusCode, startTime, duration, dependencyId, context); + + // Assert + Assert.Empty(context); + } private static HttpRequest CreateStubRequest(HttpMethod method, string host, string path, string scheme) { diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpRequestLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpRequestLoggingTests.cs index cb4e8aeb..71fd5b46 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpRequestLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpRequestLoggingTests.cs @@ -1399,6 +1399,25 @@ public void LogRequestMessage_WithContext_DoesNotAlterContext() Assert.Empty(context); } + [Fact] + public void LogRequestWithHttpRequest_WithContext_DoesNotAlterContext() + { + // Arrange + var logger = new TestLogger(); + HttpRequest request = CreateStubRequest(HttpMethod.Get, "host", "/path", "https"); + var statusCode = (int) _bogusGenerator.PickRandom(); + string operationName = _bogusGenerator.Lorem.Word(); + var startTime = _bogusGenerator.Date.RecentOffset(); + var duration = _bogusGenerator.Date.Timespan(); + var context = new Dictionary(); + + // Act + logger.LogRequest(request, statusCode, operationName, startTime, duration, context); + + // Assert + Assert.Empty(context); + } + private static HttpResponse CreateStubResponse(int statusCode) { var stubResponse = new Mock();