From b5796b7d191ce6e756d2e0b75f75bb429b992035 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 14 Nov 2023 08:38:37 +0100 Subject: [PATCH 1/2] chore: remove obsolete built-in telemetry extensions --- .../ILoggerCustomDependencyExtensions.cs | 128 ----------- .../Extensions/ILoggerEventExtensions.cs | 19 -- .../ILoggerHttpDependencyExtensions.cs | 27 --- .../Extensions/ILoggerMetricExtensions.cs | 41 ---- .../Sinks/ApplicationInsights/EventTests.cs | 46 ---- .../Serilog/TelemetryTypeFilterTests.cs | 60 ------ ...licationInsightsTelemetryConverterTests.cs | 121 ----------- .../Logging/CustomDependencyLoggingTests.cs | 199 ------------------ .../Telemetry/Logging/EventLoggingTests.cs | 27 --- .../Logging/HttpDependencyLoggingTests.cs | 32 --- .../Telemetry/Logging/MetricLoggingTests.cs | 92 -------- 11 files changed, 792 deletions(-) diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs index 4da0309b..6925812e 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCustomDependencyExtensions.cs @@ -13,36 +13,6 @@ namespace Microsoft.Extensions.Logging // ReSharper disable once InconsistentNaming public static partial class ILoggerExtensions { - /// - /// Logs a dependency. - /// - /// The logger to track the telemetry. - /// Custom type of dependency - /// Custom data of dependency - /// Indication whether or not the operation was successful - /// Measuring the latency to call the dependency - /// Context that provides more insights on the dependency that was measured - /// - /// Thrown when the , , is null. - /// - /// Thrown when the is blank. - [Obsolete("Use the overload with " + nameof(DurationMeasurement) + " instead to track a custom dependency")] - public static void LogDependency( - this ILogger logger, - string dependencyType, - object dependencyData, - bool isSuccessful, - DependencyMeasurement measurement, - Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); - Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); - Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); - Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency"); - - LogDependency(logger, dependencyType, dependencyData, isSuccessful, measurement.StartTime, measurement.Elapsed, context); - } - /// /// Logs a dependency. /// @@ -103,38 +73,6 @@ public static void LogDependency( LogDependency(logger, dependencyType, dependencyData, isSuccessful, measurement.StartTime, measurement.Elapsed, dependencyId, context); } - /// - /// Logs a dependency. - /// - /// The logger to track the telemetry. - /// Custom type of dependency - /// Custom data of dependency - /// Indication whether or not the operation was successful - /// The name of the dependency - /// Measuring the latency to call the dependency - /// Context that provides more insights on the dependency that was measured - /// - /// Thrown when the , , is null. - /// - /// Thrown when the is blank. - [Obsolete("Use the overload with " + nameof(DurationMeasurement) + " instead to track a custom dependency")] - public static void LogDependency( - this ILogger logger, - string dependencyType, - object dependencyData, - bool isSuccessful, - string dependencyName, - DependencyMeasurement measurement, - Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); - Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); - Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); - Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency"); - - LogDependency(logger, dependencyType, dependencyData, isSuccessful, dependencyName, measurement.StartTime, measurement.Elapsed, context); - } - /// /// Logs a dependency. /// @@ -335,38 +273,6 @@ public static void LogDependency( LogDependency(logger, dependencyType, dependencyData, targetName: null, isSuccessful, dependencyName, startTime, duration, dependencyId, context); } - /// - /// Logs a dependency. - /// - /// The logger to track the telemetry. - /// Custom type of dependency - /// Custom data of dependency - /// Name of the dependency target - /// Indication whether or not the operation was successful - /// Measuring the latency to call the dependency - /// Context that provides more insights on the dependency that was measured - /// - /// Thrown when the , , is null. - /// - /// Thrown when the is blank. - [Obsolete("Use the overload with " + nameof(DurationMeasurement) + " instead to track a custom dependency")] - public static void LogDependency( - this ILogger logger, - string dependencyType, - object dependencyData, - string targetName, - bool isSuccessful, - DependencyMeasurement measurement, - Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); - Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); - Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); - Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency"); - - LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, measurement.StartTime, measurement.Elapsed, context); - } - /// /// Logs a dependency. /// @@ -431,40 +337,6 @@ public static void LogDependency( LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, measurement.StartTime, measurement.Elapsed, dependencyId, context); } - /// - /// Logs a dependency. - /// - /// The logger to track the telemetry. - /// Custom type of dependency - /// Custom data of dependency - /// Name of the dependency target - /// Indication whether or not the operation was successful - /// The name of the dependency - /// Measuring the latency to call the dependency - /// Context that provides more insights on the dependency that was measured - /// - /// Thrown when the , , is null. - /// - /// Thrown when the is blank. - [Obsolete("Use the overload with " + nameof(DurationMeasurement) + " instead to track a custom dependency")] - public static void LogDependency( - this ILogger logger, - string dependencyType, - object dependencyData, - string targetName, - bool isSuccessful, - string dependencyName, - DependencyMeasurement measurement, - Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); - Guard.NotNullOrWhitespace(dependencyType, nameof(dependencyType), "Requires a non-blank custom dependency type when tracking the custom dependency"); - Guard.NotNull(dependencyData, nameof(dependencyData), "Requires custom dependency data when tracking the custom dependency"); - Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the dependency when tracking the custom dependency"); - - LogDependency(logger, dependencyType, dependencyData, targetName, isSuccessful, dependencyName, measurement.StartTime, measurement.Elapsed, context); - } - /// /// Logs a dependency. /// diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventExtensions.cs index 41676fc1..22ae1fb9 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerEventExtensions.cs @@ -49,24 +49,5 @@ public static void LogCustomEvent(this ILogger logger, string name, Dictionary - /// Logs a custom event - /// - /// The logger to track the telemetry. - /// Name of the event - /// Context that provides more insights on the event that occurred - /// Thrown when the is null. - /// Thrown when the is blank. - [Obsolete("Use " + nameof(LogCustomEvent) + " instead")] - public static void LogEvent(this ILogger logger, string name, Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); - Guard.NotNullOrWhitespace(name, nameof(name), "Requires a non-blank event name to track an custom event"); - - context = context ?? new Dictionary(); - - logger.LogWarning(MessageFormats.EventFormat, new EventLogEntry(name, context)); - } } } diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerHttpDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerHttpDependencyExtensions.cs index d06ec960..9c5baa17 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerHttpDependencyExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerHttpDependencyExtensions.cs @@ -15,33 +15,6 @@ namespace Microsoft.Extensions.Logging // ReSharper disable once InconsistentNaming public static partial class ILoggerExtensions { - /// - /// Logs an HTTP dependency - /// - /// The logger to track the telemetry. - /// The request that started the HTTP communication. - /// The status code that was returned by the service for this HTTP communication. - /// The measuring the latency of the HTTP dependency. - /// The context that provides more insights on the dependency that was measured. - /// Thrown when the , , or is null. - /// - /// Thrown when the doesn't have a request URI or HTTP method, the is outside 100-599 range inclusively. - /// - [Obsolete("Use the overload with " + nameof(DurationMeasurement) + " instead to track a HTTP dependency")] - public static void LogHttpDependency( - this ILogger logger, - HttpRequestMessage request, - HttpStatusCode statusCode, - DependencyMeasurement measurement, - Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); - Guard.NotNull(request, nameof(request), "Requires a HTTP request message to track a HTTP dependency"); - Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the HTTP communication when tracking a HTTP dependency"); - - LogHttpDependency(logger, request, statusCode, measurement.StartTime, measurement.Elapsed, context); - } - /// /// Logs an HTTP dependency. /// diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerMetricExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerMetricExtensions.cs index 3213e25a..6c0de4db 100644 --- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerMetricExtensions.cs +++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerMetricExtensions.cs @@ -30,26 +30,6 @@ public static void LogCustomMetric(this ILogger logger, string name, double valu LogCustomMetric(logger, name, value, DateTimeOffset.UtcNow, context); } - /// - /// Logs a custom metric - /// - /// The logger to track the metric. - /// Name of the metric - /// Value of the metric - /// Context that provides more insights on the event that occurred - /// Thrown when the is null. - /// Thrown when the is blank. - [Obsolete("Use " + nameof(LogCustomMetric) + " instead")] - public static void LogMetric(this ILogger logger, string name, double value, Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); - Guard.NotNullOrWhitespace(name, nameof(name), "Requires a non-blank name to track a metric"); - - context = context ?? new Dictionary(); - - LogMetric(logger, name, value, DateTimeOffset.UtcNow, context); - } - /// /// Logs a custom metric /// @@ -69,26 +49,5 @@ public static void LogCustomMetric(this ILogger logger, string name, double valu logger.LogWarning(MessageFormats.MetricFormat, new MetricLogEntry(name, value, timestamp, context)); } - - /// - /// Logs a custom metric - /// - /// The logger to track the metric. - /// Name of the metric - /// Value of the metric - /// Timestamp of the metric - /// Context that provides more insights on the event that occurred - /// Thrown when the is null. - /// Thrown when the is blank. - [Obsolete("Use " + nameof(LogCustomMetric) + " instead")] - public static void LogMetric(this ILogger logger, string name, double value, DateTimeOffset timestamp, Dictionary context = null) - { - Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry"); - Guard.NotNullOrWhitespace(name, nameof(name), "Requires a non-blank name to track a metric"); - - context = context ?? new Dictionary(); - - logger.LogWarning(MessageFormats.MetricFormat, new MetricLogEntry(name, value, timestamp, context)); - } } } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs index 1e6eb5ec..403acda3 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs @@ -1,20 +1,15 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; using Arcus.Observability.Correlation; using Arcus.Observability.Telemetry.Core; -using Arcus.Observability.Telemetry.Core.Logging; using Arcus.Observability.Telemetry.Serilog.Enrichers; using Arcus.Observability.Tests.Core; -using Microsoft.Azure.ApplicationInsights.Query; using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; -using Serilog.Events; using Xunit; using Xunit.Abstractions; -using ILogger = Microsoft.Extensions.Logging.ILogger; namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights { @@ -24,24 +19,6 @@ public EventTests(ITestOutputHelper outputWriter) : base(outputWriter) { } - [Fact] - public async Task LogEvent_SinksToApplicationInsights_ResultsInEventTelemetry() - { - // Arrange - string eventName = BogusGenerator.Finance.AccountName(); - Dictionary telemetryContext = CreateTestTelemetryContext(); - - // Act - Logger.LogEvent(eventName, telemetryContext); - - // Assert - await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => - { - EventsCustomEventResult[] results = await client.GetEventsAsync(); - Assert.Contains(results, result => result.CustomEvent.Name == eventName); - }); - } - [Fact] public async Task LogCustomEvent_SinksToApplicationInsights_ResultsInEventTelemetry() { @@ -79,29 +56,6 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => }); } - [Fact] - public async Task LogEventWithVersion_SinksToApplicationInsights_ResultsInTelemetryWithVersion() - { - // Arrange - var eventName = "Update version"; - LoggerConfiguration.Enrich.WithVersion(); - - // Act - Logger.LogEvent(eventName); - - // Assert - await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client=> - { - EventsCustomEventResult[] events = await client.GetEventsAsync(); - Assert.Contains(events, ev => - { - return ev.CustomEvent.Name == eventName - && ev.CustomDimensions.TryGetValue(VersionEnricher.DefaultPropertyName, out string actualVersion) - && !String.IsNullOrWhiteSpace(actualVersion); - }); - }); - } - [Fact] public async Task LogCustomEventWithVersion_SinksToApplicationInsights_ResultsInTelemetryWithVersion() { diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/TelemetryTypeFilterTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/TelemetryTypeFilterTests.cs index ef14f7fb..5d5a93c4 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/TelemetryTypeFilterTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/TelemetryTypeFilterTests.cs @@ -30,33 +30,6 @@ public class TelemetryTypeFilterTests public static IEnumerable TelemetryTypesWithoutDependency => GetTelemetryTypesWithout(TelemetryType.Dependency); public static IEnumerable TelemetryTypesWithoutRequest => GetTelemetryTypesWithout(TelemetryType.Request); - [Fact] - public void LogEvent_WithTelemetryTypeFilter_IgnoresLogEvent() - { - // Arrange - string eventName = _bogusGenerator.Random.Word(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); - var properties = new Dictionary { [propertyName] = propertyValue }; - - var spySink = new InMemoryLogSink(); - Logger serilogLogger = new LoggerConfiguration() - .Filter.With(TelemetryTypeFilter.On(TelemetryType.Events)) - .WriteTo.Sink(spySink) - .CreateLogger(); - - using (var factory = new SerilogLoggerFactory(serilogLogger)) - { - ILogger logger = factory.CreateLogger(); - - // Act - logger.LogEvent(eventName, properties); - - // Assert - Assert.Empty(spySink.CurrentLogEmits); - } - } - [Fact] public void LogCustomEvent_WithTelemetryTypeFilter_IgnoresLogEvent() { @@ -84,39 +57,6 @@ public void LogCustomEvent_WithTelemetryTypeFilter_IgnoresLogEvent() } } - [Theory] - [MemberData(nameof(TelemetryTypesWithoutEvent))] - public void LogEvent_WithTelemetryTypeFilterOnOtherType_DoesNotFilterOutEntry(TelemetryType telemetryType) - { - // Arrange - string eventName = _bogusGenerator.Random.Word(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); - var properties = new Dictionary { [propertyName] = propertyValue }; - - var spySink = new InMemoryLogSink(); - Logger serilogLogger = new LoggerConfiguration() - .Filter.With(TelemetryTypeFilter.On(telemetryType, isTrackingEnabled: false)) - .WriteTo.Sink(spySink) - .CreateLogger(); - - using (var factory = new SerilogLoggerFactory(serilogLogger)) - { - ILogger logger = factory.CreateLogger(); - - // Act - logger.LogEvent(eventName, properties); - - // Assert - LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); - Assert.NotNull(logEvent); - string writtenMessage = logEvent.RenderMessage(); - Assert.Contains(propertyName, writtenMessage); - Assert.Contains(propertyValue, writtenMessage); - Assert.Contains(TelemetryType.Events.ToString(), writtenMessage); - } - } - [Theory] [MemberData(nameof(TelemetryTypesWithoutEvent))] public void LogCustomEvent_WithTelemetryTypeFilterOnOtherType_DoesNotFilterOutEntry(TelemetryType telemetryType) diff --git a/src/Arcus.Observability.Tests.Unit/Serilog/ApplicationInsightsTelemetryConverterTests.cs b/src/Arcus.Observability.Tests.Unit/Serilog/ApplicationInsightsTelemetryConverterTests.cs index 22f99f6e..75db1fda 100644 --- a/src/Arcus.Observability.Tests.Unit/Serilog/ApplicationInsightsTelemetryConverterTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Serilog/ApplicationInsightsTelemetryConverterTests.cs @@ -629,45 +629,6 @@ public void LogSqlDependency_WithSqlDependency_CreatesSqlDependencyTelemetry() }); } - [Fact] - public void LogEvent_WithEvent_CreatesEventTelemetry() - { - // Arrange - const string eventName = "Order Invoiced"; - var spySink = new InMemoryLogSink(); - string operationId = $"operation-id-{Guid.NewGuid()}"; - string transactionId = $"transaction-{Guid.NewGuid()}"; - ILogger logger = CreateLogger(spySink, - config => config.Enrich.WithProperty(ContextProperties.Correlation.OperationId, operationId) - .Enrich.WithProperty(ContextProperties.Correlation.TransactionId, transactionId)); - - var telemetryContext = new Dictionary - { - ["OrderId"] = "ABC", - ["Vendor"] = "Contoso" - }; - - logger.LogEvent(eventName, telemetryContext); - LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); - Assert.NotNull(logEvent); - - var converter = ApplicationInsightsTelemetryConverter.Create(); - - // Act - IEnumerable telemetries = converter.Convert(logEvent, formatProvider: null); - - // Assert - AssertDoesContainLogProperty(logEvent, EventTracking.EventLogEntry); - Assert.Collection(telemetries, telemetry => - { - var eventTelemetry = Assert.IsType(telemetry); - Assert.Equal(eventName, eventTelemetry.Name); - AssertOperationContextForNonRequest(eventTelemetry, operationId, transactionId); - AssertContainsTelemetryProperty(eventTelemetry, "OrderId", "ABC"); - AssertContainsTelemetryProperty(eventTelemetry, "Vendor", "Contoso"); - }); - } - [Fact] public void LogCustomEvent_WithEvent_CreatesEventTelemetry() { @@ -707,47 +668,6 @@ public void LogCustomEvent_WithEvent_CreatesEventTelemetry() }); } - [Fact] - public void LogEvent_WithJsonTelemetryValue_CreatesEventTelemetry() - { - // Arrange - const string eventName = "Order Invoiced"; - var spySink = new InMemoryLogSink(); - string operationId = $"operation-id-{Guid.NewGuid()}"; - string transactionId = $"transaction-{Guid.NewGuid()}"; - ILogger logger = CreateLogger(spySink, - config => config.Enrich.WithProperty(ContextProperties.Correlation.OperationId, operationId) - .Enrich.WithProperty(ContextProperties.Correlation.TransactionId, transactionId)); - - Order order = OrderGenerator.Generate(); - string json = JsonSerializer.Serialize(order); - var context = new Dictionary - { - ["Value"] = json, - ["OrderId"] = "ABC", - ["Vendor"] = "Contoso" - }; - logger.LogEvent(eventName, context); - LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); - Assert.NotNull(logEvent); - - var converter = ApplicationInsightsTelemetryConverter.Create(); - - // Act - IEnumerable telemetries = converter.Convert(logEvent, formatProvider: null); - - // Assert - Assert.Collection(telemetries, telemetry => - { - var eventTelemetry = Assert.IsType(telemetry); - Assert.Equal(eventName, eventTelemetry.Name); - AssertOperationContextForNonRequest(eventTelemetry, operationId, transactionId); - AssertContainsTelemetryProperty(eventTelemetry, "Value", json); - AssertContainsTelemetryProperty(eventTelemetry, "OrderId", "ABC"); - AssertContainsTelemetryProperty(eventTelemetry, "Vendor", "Contoso"); - }); - } - [Fact] public void LogCustomEvent_WithJsonTelemetryValue_CreatesEventTelemetry() { @@ -822,47 +742,6 @@ public void LogException_WithException_CreatesExceptionTelemetry() }); } - [Fact] - public void LogMetric_WithMetric_CreatesMetricTelemetry() - { - // Arrange - const string metricName = "Request stream"; - const double metricValue = 0.13; - var timestamp = DateTimeOffset.UtcNow; - var spySink = new InMemoryLogSink(); - string operationId = $"operation-id-{Guid.NewGuid()}"; - string transactionId = $"transaction-{Guid.NewGuid()}"; - ILogger logger = CreateLogger(spySink, - config => config.Enrich.WithProperty(ContextProperties.Correlation.OperationId, operationId) - .Enrich.WithProperty(ContextProperties.Correlation.TransactionId, transactionId)); - - var telemetryContext = new Dictionary - { - ["Capacity"] = "0.45" - }; - logger.LogMetric(metricName, metricValue, timestamp, telemetryContext); - LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); - Assert.NotNull(logEvent); - - var converter = ApplicationInsightsTelemetryConverter.Create(); - - // Act - IEnumerable telemetries = converter.Convert(logEvent, formatProvider: null); - - // Assert - AssertDoesContainLogProperty(logEvent, MetricTracking.MetricLogEntry); - Assert.Collection(telemetries, telemetry => - { - var metricTelemetry = Assert.IsType(telemetry); - Assert.Equal(metricName, metricTelemetry.Name); - Assert.Equal(metricValue, metricTelemetry.Sum); - Assert.Equal(timestamp, metricTelemetry.Timestamp); - AssertOperationContextForNonRequest(metricTelemetry, operationId, transactionId); - - AssertContainsTelemetryProperty(metricTelemetry, "Capacity", "0.45"); - }); - } - [Fact] public void LogCustomMetric_WithMetric_CreatesMetricTelemetry() { diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs index 4b1fe3a2..c7f2edc5 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CustomDependencyLoggingTests.cs @@ -211,32 +211,6 @@ public void LogDependency_WithNegativeDurationWithDependencyId_Fails() Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, startTime, duration, dependencyId)); } - [Fact] - public void LogDependencyWithDependencyMeasurement_ValidArguments_Succeeds() - { - // Arrange - var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Random.Int().ToString(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - var measurement = DependencyMeasurement.Start(); - DateTimeOffset startTime = measurement.StartTime; - measurement.Dispose(); - TimeSpan duration = measurement.Elapsed; - - // Act - logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement); - - // Assert - string logMessage = logger.WrittenMessage; - Assert.Contains(TelemetryType.Dependency.ToString(), logMessage); - Assert.Contains(dependencyType, logMessage); - Assert.Contains(dependencyData, logMessage); - Assert.Contains(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), logMessage); - Assert.Contains(duration.ToString(), logMessage); - Assert.Contains(isSuccessful.ToString(), logMessage); - } - [Fact] public void LogDependencyWithDurationMeasurement_ValidArgumentsWithDependencyId_Succeeds() { @@ -317,34 +291,6 @@ public void LogDependencyWithDependencyDurationMeasurement_ValidArgumentsWithDep Assert.Equal(dependencyId, dependency.DependencyId); } - [Fact] - public void LogDependencyWithDependencyMeasurement_ValidArgumentsWithDependencyName_Succeeds() - { - // Arrange - var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Database.Type(); - var dependencyData = _bogusGenerator.Random.Int().ToString(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Lorem.Word(); - var measurement = DependencyMeasurement.Start(); - DateTimeOffset startTime = measurement.StartTime; - measurement.Dispose(); - TimeSpan duration = measurement.Elapsed; - - // Act - logger.LogDependency(dependencyType, dependencyData, isSuccessful, dependencyName, measurement); - - // Assert - string logMessage = logger.WrittenMessage; - Assert.Contains(TelemetryType.Dependency.ToString(), logMessage); - Assert.Contains(dependencyType, logMessage); - Assert.Contains(dependencyData, logMessage); - Assert.Contains(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), logMessage); - Assert.Contains(duration.ToString(), logMessage); - Assert.Contains(isSuccessful.ToString(), logMessage); - Assert.Contains(dependencyName, logMessage); - } - [Fact] public void LogDependencyWithDurationMeasurement_ValidArgumentsWithDependencyNameWithDependencyId_Succeeds() { @@ -663,19 +609,6 @@ public void LogDependencyWithDurationMeasurementWithTargetName_WithoutMeasuremen () => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement: null, dependencyId)); } - [Fact] - public void LogDependencyWithDependencyMeasurement_WithoutDependencyMeasurement_Fails() - { - // Arrange - var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Random.Int().ToString(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - - // Act / Assert - Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement: (DependencyMeasurement)null)); - } - [Fact] public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyMeasurement_Fails() { @@ -703,21 +636,6 @@ public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyMeas Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement: null, dependencyId)); } - [Fact] - public void LogDependencyWithDependencyMeasurement_WithoutDependencyType_Fails() - { - // Arrange - var logger = new TestLogger(); - string dependencyType = null; - var dependencyData = _bogusGenerator.Random.Int().ToString(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - var measurement = DependencyMeasurement.Start(); - measurement.Dispose(); - - // Act / Assert - Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement)); - } - [Fact] public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyType_Fails() { @@ -749,21 +667,6 @@ public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyType Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement, dependencyId)); } - [Fact] - public void LogDependencyWithDependencyMeasurement_WithoutDependencyData_Fails() - { - // Arrange - var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Name.FullName(); - object dependencyData = null; - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - var measurement = DependencyMeasurement.Start(); - measurement.Dispose(); - - // Act / Assert - Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, isSuccessful, measurement)); - } - [Fact] public void LogDependencyWithDependencyDurationMeasurement_WithoutDependencyData_Fails() { @@ -1034,62 +937,6 @@ public void LogDependencyTarget_WithNegativeDurationWithDependencyId_Fails() Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, startTime, duration, dependencyId)); } - [Fact] - public void LogDependencyWithDependencyMeasurementTarget_ValidArguments_Succeeds() - { - // Arrange - var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Random.Int().ToString(); - string targetName = _bogusGenerator.Lorem.Word(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - var measurement = DependencyMeasurement.Start(); - DateTimeOffset startTime = measurement.StartTime; - measurement.Dispose(); - TimeSpan duration = measurement.Elapsed; - - // Act - logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement); - - // Assert - string logMessage = logger.WrittenMessage; - Assert.Contains(TelemetryType.Dependency.ToString(), logMessage); - Assert.Contains(dependencyType, logMessage); - Assert.Contains(dependencyData, logMessage); - Assert.Contains(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), logMessage); - Assert.Contains(duration.ToString(), logMessage); - Assert.Contains(isSuccessful.ToString(), logMessage); - } - - [Fact] - public void LogDependencyWithDependencyMeasurementTarget_ValidArgumentsWithDependencyName_Succeeds() - { - // Arrange - var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Random.Int().ToString(); - string targetName = _bogusGenerator.Lorem.Word(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Lorem.Word(); - var measurement = DependencyMeasurement.Start(); - DateTimeOffset startTime = measurement.StartTime; - measurement.Dispose(); - TimeSpan duration = measurement.Elapsed; - - // Act - logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, dependencyName, measurement); - - // Assert - string logMessage = logger.WrittenMessage; - Assert.Contains(TelemetryType.Dependency.ToString(), logMessage); - Assert.Contains(dependencyType, logMessage); - Assert.Contains(dependencyData, logMessage); - Assert.Contains(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), logMessage); - Assert.Contains(duration.ToString(), logMessage); - Assert.Contains(isSuccessful.ToString(), logMessage); - Assert.Contains(dependencyName, logMessage); - } - [Fact] public void LogDependencyWithDurationMeasurementTarget_ValidArgumentsWithDependencyName_Succeeds() { @@ -1334,22 +1181,6 @@ public void LogDependencyWithDurationMeasurementTarget_WithoutMeasurementWithDep () => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, dependencyName, measurement: null, dependencyId)); } - [Fact] - public void LogDependencyTargetWithDependencyMeasurement_WithoutDependencyType_Fails() - { - // Arrange - var logger = new TestLogger(); - string dependencyType = null; - var dependencyData = _bogusGenerator.Random.Int().ToString(); - string targetName = _bogusGenerator.Lorem.Word(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - var measurement = DependencyMeasurement.Start(); - measurement.Dispose(); - - // Act / Assert - Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement)); - } - [Fact] public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependencyType_Fails() { @@ -1383,22 +1214,6 @@ public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependen Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement, dependencyId)); } - [Fact] - public void LogDependencyTargetWithDependencyMeasurement_WithoutDependencyData_Fails() - { - // Arrange - var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Name.FullName(); - object dependencyData = null; - string targetName = _bogusGenerator.Lorem.Word(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - var measurement = DependencyMeasurement.Start(); - measurement.Dispose(); - - // Act / Assert - Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement)); - } - [Fact] public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependencyData_Fails() { @@ -1432,20 +1247,6 @@ public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependen Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement, dependencyId)); } - [Fact] - public void LogDependencyTargetWithDependencyMeasurement_WithoutDependencyMeasurement_Fails() - { - // Arrange - var logger = new TestLogger(); - string dependencyType = _bogusGenerator.Lorem.Word(); - var dependencyData = _bogusGenerator.Random.Int().ToString(); - string targetName = _bogusGenerator.Lorem.Word(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - - // Act / Assert - Assert.ThrowsAny(() => logger.LogDependency(dependencyType, dependencyData, targetName, isSuccessful, measurement: (DependencyMeasurement)null)); - } - [Fact] public void LogDependencyTargetWithDependencyDurationMeasurement_WithoutDependencyMeasurement_Fails() { diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventLoggingTests.cs index a6eeb441..be615429 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/EventLoggingTests.cs @@ -12,22 +12,6 @@ public class EventLoggingTests { private readonly Faker _bogusGenerator = new Faker(); - [Fact] - public void LogEvent_ValidArguments_Succeeds() - { - // Arrange - var logger = new TestLogger(); - string eventName = _bogusGenerator.Name.FullName(); - - // Act - logger.LogEvent(eventName); - - // Assert - var logMessage = logger.WrittenMessage; - Assert.Contains(TelemetryType.Events.ToString(), logMessage); - Assert.Contains(eventName, logMessage); - } - [Fact] public void LogCustomEvent_ValidArguments_Succeeds() { @@ -44,17 +28,6 @@ public void LogCustomEvent_ValidArguments_Succeeds() Assert.Contains(eventName, logMessage); } - [Fact] - public void LogEvent_NoEventNameSpecified_ThrowsException() - { - // Arrange - var logger = new TestLogger(); - string eventName = null; - - // Act & Arrange - Assert.Throws(() => logger.LogEvent(eventName)); - } - [Fact] public void LogCustomEvent_NoEventNameSpecified_ThrowsException() { diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpDependencyLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpDependencyLoggingTests.cs index 7d57d157..84f16933 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpDependencyLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/HttpDependencyLoggingTests.cs @@ -159,38 +159,6 @@ public void LogHttpDependency_NoRequestWasSpecified_ThrowsException() Assert.Throws(() => logger.LogHttpDependency(request, statusCode, startTime, duration)); } - [Fact] - public void LogHttpDependencyWithDependencyMeasurement_ValidArguments_Succeeds() - { - // Arrange - var logger = new TestLogger(); - var request = new HttpRequestMessage(HttpMethod.Get, BogusGenerator.Internet.UrlWithPath()); - var statusCode = (HttpStatusCode)BogusGenerator.Random.Int(100, 599); - var measurement = DependencyMeasurement.Start(); - DateTimeOffset startTime = measurement.StartTime; - measurement.Dispose(); - TimeSpan duration = measurement.Elapsed; - - // Act - logger.LogHttpDependency(request, statusCode, measurement); - - // Assert - var logMessage = logger.WrittenMessage; - Assert.Contains(TelemetryType.Dependency.ToString(), logMessage); - Assert.Contains(request.RequestUri.Host, logMessage); - Assert.Contains(request.RequestUri.PathAndQuery, logMessage); - Assert.Contains(request.Method.ToString(), logMessage); - Assert.Contains(((int)statusCode).ToString(), logMessage); - Assert.Contains(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), logMessage); - Assert.Contains(duration.ToString(), logMessage); - var isSuccessful = (int)statusCode >= 200 && (int)statusCode < 300; - Assert.Contains($"Successful: {isSuccessful}", logMessage); - Uri requestUri = request.RequestUri; - HttpMethod requestMethod = request.Method; - string dependencyName = $"{requestMethod} {requestUri.AbsolutePath}"; - Assert.Contains("Http " + dependencyName, logMessage); - } - [Fact] public void LogHttpDependencyWithDurationMeasurement_ValidArguments_Succeeds() { diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/MetricLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/MetricLoggingTests.cs index 5a4d630d..8c333f6f 100644 --- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/MetricLoggingTests.cs +++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/MetricLoggingTests.cs @@ -13,28 +13,6 @@ public class MetricLoggingTests { private readonly Faker _bogusGenerator = new Faker(); - [Fact] - public void LogMetric_ValidArguments_Succeeds() - { - // Arrange - var logger = new TestLogger(); - string metricName = _bogusGenerator.Lorem.Word(); - double metricValue = _bogusGenerator.Random.Double(); - - // Act - logger.LogMetric(metricName, metricValue, context: null); - - // Assert - MetricLogEntry metric = logger.GetMessageAsMetric(); - Assert.Equal(metricName, metric.MetricName); - Assert.Equal(metricValue, metric.MetricValue); - Assert.Collection(metric.Context, item => - { - Assert.Equal(ContextProperties.General.TelemetryType, item.Key); - Assert.Equal(TelemetryType.Metrics, item.Value); - }); - } - [Fact] public void LogCustomMetric_ValidArguments_Succeeds() { @@ -57,30 +35,6 @@ public void LogCustomMetric_ValidArguments_Succeeds() }); } - [Fact] - public void LogMetric_ValidArgumentsWithTimestamp_Succeeds() - { - // Arrange - var logger = new TestLogger(); - string metricName = _bogusGenerator.Lorem.Word(); - double metricValue = _bogusGenerator.Random.Double(); - DateTimeOffset timestamp = _bogusGenerator.Date.RecentOffset(); - - // Act - logger.LogMetric(metricName, metricValue, timestamp); - - // Assert - MetricLogEntry metric = logger.GetMessageAsMetric(); - Assert.Equal(metricName, metric.MetricName); - Assert.Equal(metricValue, metric.MetricValue); - Assert.Equal(timestamp.ToString(FormatSpecifiers.InvariantTimestampFormat), metric.Timestamp); - Assert.Collection(metric.Context, item => - { - Assert.Equal(ContextProperties.General.TelemetryType, item.Key); - Assert.Equal(TelemetryType.Metrics, item.Value); - }); - } - [Fact] public void LogCustomMetric_ValidArgumentsWithTimestamp_Succeeds() { @@ -105,40 +59,6 @@ public void LogCustomMetric_ValidArgumentsWithTimestamp_Succeeds() }); } - [Fact] - public void LogMetric_ValidArgumentsWithCustomContext_Succeeds() - { - // Arrange - var logger = new TestLogger(); - string metricName = _bogusGenerator.Lorem.Word(); - double metricValue = _bogusGenerator.Random.Double(); - DateTimeOffset timestamp = _bogusGenerator.Date.RecentOffset(); - - string key = _bogusGenerator.Lorem.Word(); - string value = _bogusGenerator.Lorem.Word(); - var context = new Dictionary { [key] = value }; - - // Act - logger.LogMetric(metricName, metricValue, timestamp, context); - - // Assert - MetricLogEntry metric = logger.GetMessageAsMetric(); - Assert.Equal(metricName, metric.MetricName); - Assert.Equal(metricValue, metric.MetricValue); - Assert.Equal(timestamp.ToString(FormatSpecifiers.InvariantTimestampFormat), metric.Timestamp); - Assert.Collection(metric.Context, - item => - { - Assert.Equal(key, item.Key); - Assert.Equal(value, item.Value); - }, - item => - { - Assert.Equal(ContextProperties.General.TelemetryType, item.Key); - Assert.Equal(TelemetryType.Metrics, item.Value); - }); - } - [Fact] public void LogCustomMetric_ValidArgumentsWithCustomContext_Succeeds() { @@ -173,18 +93,6 @@ public void LogCustomMetric_ValidArgumentsWithCustomContext_Succeeds() }); } - [Fact] - public void LogMetric_NoMetricNameWasSpecified_ThrowsException() - { - // Arrange - var logger = new TestLogger(); - string metricName = null; - double metricValue = _bogusGenerator.Random.Double(); - - // Act & Arrange - Assert.Throws(() => logger.LogMetric(metricName, metricValue, context: null)); - } - [Fact] public void LogCustomMetric_NoMetricNameWasSpecified_ThrowsException() { From f95a18a64bc44d5d122a54f593e8328eeb35ad2f Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Mon, 20 Nov 2023 07:20:23 +0100 Subject: [PATCH 2/2] pr-fix: telemetry type filter integration tests --- .../Serilog/TelemetryTypeFilterTests.cs | 473 +++++++++--------- 1 file changed, 236 insertions(+), 237 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/TelemetryTypeFilterTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/TelemetryTypeFilterTests.cs index 5d5a93c4..a1e51fcf 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/TelemetryTypeFilterTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/TelemetryTypeFilterTests.cs @@ -8,9 +8,7 @@ using Arcus.Observability.Telemetry.Serilog.Filters; using Arcus.Observability.Tests.Core; using Bogus; -using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using Moq; using Serilog; using Serilog.Core; using Serilog.Events; @@ -23,7 +21,7 @@ namespace Arcus.Observability.Tests.Integration.Serilog [Trait("Category", "Integration")] public class TelemetryTypeFilterTests { - private readonly Faker _bogusGenerator = new Faker(); + private static readonly Faker Bogus = new Faker(); public static IEnumerable TelemetryTypesWithoutEvent => GetTelemetryTypesWithout(TelemetryType.Events); public static IEnumerable TelemetryTypesWithoutMetric => GetTelemetryTypesWithout(TelemetryType.Metrics); @@ -34,9 +32,9 @@ public class TelemetryTypeFilterTests public void LogCustomEvent_WithTelemetryTypeFilter_IgnoresLogEvent() { // Arrange - string eventName = _bogusGenerator.Random.Word(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string eventName = Bogus.Random.Word(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -62,9 +60,9 @@ public void LogCustomEvent_WithTelemetryTypeFilter_IgnoresLogEvent() public void LogCustomEvent_WithTelemetryTypeFilterOnOtherType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string eventName = _bogusGenerator.Random.Word(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string eventName = Bogus.Random.Word(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -94,9 +92,9 @@ public void LogCustomEvent_WithTelemetryTypeFilterOnOtherType_DoesNotFilterOutEn public void LogSecurityEvent_WithTelemetryTypeFilter_IgnoresLogEvent() { // Arrange - string eventName = _bogusGenerator.Random.Word(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string eventName = Bogus.Random.Word(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -122,9 +120,9 @@ public void LogSecurityEvent_WithTelemetryTypeFilter_IgnoresLogEvent() public void LogSecurityEvent_WithTelemetryTypeFilterOnOtherType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string eventName = _bogusGenerator.Random.Word(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string eventName = Bogus.Random.Word(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -150,42 +148,14 @@ public void LogSecurityEvent_WithTelemetryTypeFilterOnOtherType_DoesNotFilterOut } } - [Fact] - public void LogMetric_WithTelemetryTypeFilter_IgnoresMetric() - { - // Arrange - string metricName = _bogusGenerator.Random.Word(); - double metricValue = _bogusGenerator.Random.Double(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); - var properties = new Dictionary { [propertyName] = propertyValue }; - - var spySink = new InMemoryLogSink(); - Logger serilogLogger = new LoggerConfiguration() - .Filter.With(TelemetryTypeFilter.On(TelemetryType.Metrics)) - .WriteTo.Sink(spySink) - .CreateLogger(); - - using (var factory = new SerilogLoggerFactory(serilogLogger)) - { - ILogger logger = factory.CreateLogger(); - - // Act - logger.LogMetric(metricName, metricValue, properties); - - // Assert - Assert.Empty(spySink.CurrentLogEmits); - } - } - [Fact] public void LogCustomMetric_WithTelemetryTypeFilter_IgnoresMetric() { // Arrange - string metricName = _bogusGenerator.Random.Word(); - double metricValue = _bogusGenerator.Random.Double(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string metricName = Bogus.Random.Word(); + double metricValue = Bogus.Random.Double(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -208,13 +178,13 @@ public void LogCustomMetric_WithTelemetryTypeFilter_IgnoresMetric() [Theory] [MemberData(nameof(TelemetryTypesWithoutMetric))] - public void LogMetric_WithTelemetryTypeFilterOnDifferentTyp_DoesNotFilterOutEntry(TelemetryType telemetryType) + public void LogCustomMetric_WithTelemetryTypeFilterOnDifferentType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string metricName = _bogusGenerator.Random.Word(); - double metricValue = _bogusGenerator.Random.Double(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string metricName = Bogus.Random.Word(); + double metricValue = Bogus.Random.Double(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -228,7 +198,7 @@ public void LogMetric_WithTelemetryTypeFilterOnDifferentTyp_DoesNotFilterOutEntr ILogger logger = factory.CreateLogger(); // Act - logger.LogMetric(metricName, metricValue, properties); + logger.LogCustomMetric(metricName, metricValue, properties); // Assert LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); @@ -242,52 +212,81 @@ public void LogMetric_WithTelemetryTypeFilterOnDifferentTyp_DoesNotFilterOutEntr } } - [Theory] - [MemberData(nameof(TelemetryTypesWithoutMetric))] - public void LogCustomMetric_WithTelemetryTypeFilterOnDifferentTyp_DoesNotFilterOutEntry(TelemetryType telemetryType) + [Fact] + public void LogCustomRequest_WithTelemetryTypeFilter_IgnoresRequest() { // Arrange - string metricName = _bogusGenerator.Random.Word(); - double metricValue = _bogusGenerator.Random.Double(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + var spySink = new InMemoryLogSink(); + var serilogLogger = new LoggerConfiguration() + .Filter.With(TelemetryTypeFilter.On(TelemetryType.Request)) + .WriteTo.Sink(spySink) + .CreateLogger(); + + using var factory = new SerilogLoggerFactory(serilogLogger); + ILogger logger = factory.CreateLogger(); + + string requestSource = Bogus.Random.Word(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.RecentOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; + // Act + logger.LogCustomRequest(requestSource, isSuccessful, startTime, duration, properties); + + // Assert + Assert.Empty(spySink.CurrentLogEmits); + } + + [Theory] + [MemberData(nameof(TelemetryTypesWithoutRequest))] + public void LogCustomRequest_WithTelemetryTypeFilterOnDifferentType_DoesNotFilterOutEntry(TelemetryType telemetryType) + { + // Arrange var spySink = new InMemoryLogSink(); - Logger serilogLogger = new LoggerConfiguration() + var serilogLogger = new LoggerConfiguration() .Filter.With(TelemetryTypeFilter.On(telemetryType)) .WriteTo.Sink(spySink) .CreateLogger(); - using (var factory = new SerilogLoggerFactory(serilogLogger)) - { - ILogger logger = factory.CreateLogger(); + using var factory = new SerilogLoggerFactory(serilogLogger); + ILogger logger = factory.CreateLogger(); - // Act - logger.LogCustomMetric(metricName, metricValue, properties); + string requestSource = Bogus.Random.Word(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.RecentOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); + var properties = new Dictionary { [propertyName] = propertyValue }; - // Assert - LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); - Assert.NotNull(logEvent); - string writtenMessage = logEvent.RenderMessage(); - Assert.Contains(metricName, writtenMessage); - Assert.Contains(metricValue.ToString(CultureInfo.InvariantCulture), writtenMessage); - Assert.Contains(propertyName, writtenMessage); - Assert.Contains(propertyValue, writtenMessage); - Assert.Contains(TelemetryType.Metrics.ToString(), writtenMessage); - } + // Act + logger.LogCustomRequest(requestSource, isSuccessful, startTime, duration, properties); + + // Assert + LogEvent logEvent = Assert.Single(spySink.CurrentLogEmits); + Assert.NotNull(logEvent); + string writtenMessage = logEvent.RenderMessage(); + Assert.Contains(requestSource, writtenMessage); + Assert.Contains((isSuccessful ? 200 : 500).ToString(), writtenMessage); + Assert.Contains(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), writtenMessage); + Assert.Contains(duration.ToString(), writtenMessage); + Assert.Contains(propertyName, writtenMessage); + Assert.Contains(propertyValue, writtenMessage); } [Fact] public void LogHttpDependency_WithTelemetryTypeFilter_IgnoresHttpDependency() { // Arrange - var request = new HttpRequestMessage(HttpMethod.Get, _bogusGenerator.Internet.UrlWithPath()); - var statusCode = _bogusGenerator.PickRandom(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + var request = new HttpRequestMessage(HttpMethod.Get, Bogus.Internet.UrlWithPath()); + var statusCode = Bogus.PickRandom(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -313,12 +312,12 @@ public void LogHttpDependency_WithTelemetryTypeFilter_IgnoresHttpDependency() public void LogHttpDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - var request = new HttpRequestMessage(HttpMethod.Get, _bogusGenerator.Internet.UrlWithPath()); - var statusCode = _bogusGenerator.PickRandom(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + var request = new HttpRequestMessage(HttpMethod.Get, Bogus.Internet.UrlWithPath()); + var statusCode = Bogus.PickRandom(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -355,15 +354,15 @@ public void LogHttpDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_Do public void LogSqlDependency_WithTelemetryTypeFilter_IgnoresDependency() { // Arrange - string serverName = _bogusGenerator.Name.FullName(); - string databaseName = _bogusGenerator.Name.FullName(); - string tableName = _bogusGenerator.Name.FullName(); - string operationName = _bogusGenerator.Name.FullName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string serverName = Bogus.Name.FullName(); + string databaseName = Bogus.Name.FullName(); + string tableName = Bogus.Name.FullName(); + string operationName = Bogus.Name.FullName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -389,15 +388,15 @@ public void LogSqlDependency_WithTelemetryTypeFilter_IgnoresDependency() public void LogSqlDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string serverName = _bogusGenerator.Name.FullName(); - string databaseName = _bogusGenerator.Name.FullName(); - string tableName = _bogusGenerator.Name.FullName(); - string operationName = _bogusGenerator.Name.FullName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string serverName = Bogus.Name.FullName(); + string databaseName = Bogus.Name.FullName(); + string tableName = Bogus.Name.FullName(); + string operationName = Bogus.Name.FullName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -435,12 +434,12 @@ public void LogSqlDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_Doe public void LogServiceBusTopicDependency_WithTelemetryTypeFilter_IgnoresDependency() { // Arrange - string topicName = _bogusGenerator.Commerce.Product(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - TimeSpan duration = _bogusGenerator.Date.Timespan(); + string topicName = Bogus.Commerce.Product(); + bool isSuccessful = Bogus.PickRandom(true, false); + TimeSpan duration = Bogus.Date.Timespan(); DateTimeOffset startTime = DateTimeOffset.UtcNow; - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -466,12 +465,12 @@ public void LogServiceBusTopicDependency_WithTelemetryTypeFilter_IgnoresDependen public void LogServiceBusTopicDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string topicName = _bogusGenerator.Commerce.Product(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - TimeSpan duration = _bogusGenerator.Date.Timespan(); + string topicName = Bogus.Commerce.Product(); + bool isSuccessful = Bogus.PickRandom(true, false); + TimeSpan duration = Bogus.Date.Timespan(); DateTimeOffset startTime = DateTimeOffset.UtcNow; - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -506,12 +505,12 @@ public void LogServiceBusTopicDependency_WithTelemetryTypeFilterOnDifferentTelem public void LogServiceBusQueueDependency_WithTelemetryTypeFilter_IgnoresDependency() { // Arrange - string queueName = _bogusGenerator.Commerce.Product(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - TimeSpan duration = _bogusGenerator.Date.Timespan(); + string queueName = Bogus.Commerce.Product(); + bool isSuccessful = Bogus.PickRandom(true, false); + TimeSpan duration = Bogus.Date.Timespan(); DateTimeOffset startTime = DateTimeOffset.UtcNow; - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -537,12 +536,12 @@ public void LogServiceBusQueueDependency_WithTelemetryTypeFilter_IgnoresDependen public void LogServiceBusQueueDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string queueName = _bogusGenerator.Commerce.Product(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - TimeSpan duration = _bogusGenerator.Date.Timespan(); + string queueName = Bogus.Commerce.Product(); + bool isSuccessful = Bogus.PickRandom(true, false); + TimeSpan duration = Bogus.Date.Timespan(); DateTimeOffset startTime = DateTimeOffset.UtcNow; - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -577,13 +576,13 @@ public void LogServiceBusQueueDependency_WithTelemetryTypeFilterOnDifferentTelem public void LogAzureSearchDependency_WithTelemetryTypeFilter_IgnoresDependency() { // Arrange - string searchServiceName = _bogusGenerator.Commerce.Product(); - string operationName = _bogusGenerator.Commerce.ProductName(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - DateTimeOffset startTime = _bogusGenerator.Date.RecentOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string searchServiceName = Bogus.Commerce.Product(); + string operationName = Bogus.Commerce.ProductName(); + bool isSuccessful = Bogus.PickRandom(true, false); + DateTimeOffset startTime = Bogus.Date.RecentOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -609,13 +608,13 @@ public void LogAzureSearchDependency_WithTelemetryTypeFilter_IgnoresDependency() public void LogAzureSearchDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string searchServiceName = _bogusGenerator.Commerce.Product(); - string operationName = _bogusGenerator.Commerce.ProductName(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - DateTimeOffset startTime = _bogusGenerator.Date.RecentOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string searchServiceName = Bogus.Commerce.Product(); + string operationName = Bogus.Commerce.ProductName(); + bool isSuccessful = Bogus.PickRandom(true, false); + DateTimeOffset startTime = Bogus.Date.RecentOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -652,11 +651,11 @@ public void LogAzureKeyVaultDependency_WithTelemetryTypeFilter_IgnoresDependency // Arrange var vaultUri = "https://myvault.vault.azure.net"; string secretName = "MySecret"; - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - DateTimeOffset startTime = _bogusGenerator.Date.RecentOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + bool isSuccessful = Bogus.PickRandom(true, false); + DateTimeOffset startTime = Bogus.Date.RecentOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -684,11 +683,11 @@ public void LogAzureKeyVaultDependency_WithTelemetryTypeFilterOnDifferentTelemet // Arrange var vaultUri = "https://myvault.vault.azure.net"; string secretName = "MySecret"; - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - DateTimeOffset startTime = _bogusGenerator.Date.RecentOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + bool isSuccessful = Bogus.PickRandom(true, false); + DateTimeOffset startTime = Bogus.Date.RecentOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -722,14 +721,14 @@ public void LogAzureKeyVaultDependency_WithTelemetryTypeFilterOnDifferentTelemet public void LogDependencyTarget_WithTelemetryTypeFilter_IgnoresDependency() { // Arrange - string dependencyType = _bogusGenerator.Name.FullName(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); - string targetName = _bogusGenerator.Lorem.Word(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string dependencyType = Bogus.Name.FullName(); + var dependencyData = Bogus.Finance.Amount().ToString("F"); + string targetName = Bogus.Lorem.Word(); + bool isSuccessful = Bogus.PickRandom(true, false); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -755,15 +754,15 @@ public void LogDependencyTarget_WithTelemetryTypeFilter_IgnoresDependency() public void LogDependencyTarget_WithTelemetryTypeFilterOnDifferentTelemetryType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string dependencyType = _bogusGenerator.Name.FullName(); - var dependencyData = _bogusGenerator.Finance.Amount().ToString("F"); - string targetName = _bogusGenerator.Lorem.Word(); - bool isSuccessful = _bogusGenerator.PickRandom(true, false); - string dependencyName = _bogusGenerator.Random.Word(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string dependencyType = Bogus.Name.FullName(); + var dependencyData = Bogus.Finance.Amount().ToString("F"); + string targetName = Bogus.Lorem.Word(); + bool isSuccessful = Bogus.PickRandom(true, false); + string dependencyName = Bogus.Random.Word(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -799,14 +798,14 @@ public void LogDependencyTarget_WithTelemetryTypeFilterOnDifferentTelemetryType_ public void LogCosmosSqlDependency_WithTelemetryTypeFilter_IgnoresDependency() { // Arrange - string container = _bogusGenerator.Commerce.ProductName(); - string database = _bogusGenerator.Commerce.ProductName(); - string accountName = _bogusGenerator.Finance.AccountName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string container = Bogus.Commerce.ProductName(); + string database = Bogus.Commerce.ProductName(); + string accountName = Bogus.Finance.AccountName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -832,14 +831,14 @@ public void LogCosmosSqlDependency_WithTelemetryTypeFilter_IgnoresDependency() public void LogCosmosSqlDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string container = _bogusGenerator.Commerce.ProductName(); - string database = _bogusGenerator.Commerce.ProductName(); - string accountName = _bogusGenerator.Finance.AccountName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string container = Bogus.Commerce.ProductName(); + string database = Bogus.Commerce.ProductName(); + string accountName = Bogus.Finance.AccountName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -875,12 +874,12 @@ public void LogCosmosSqlDependency_WithTelemetryTypeFilterOnDifferentTelemetryTy public void LogIotHubDependency_WithTelemetryTypeFilter_IgnoresDependency() { // Arrange - string iotHubName = _bogusGenerator.Commerce.ProductName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string iotHubName = Bogus.Commerce.ProductName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -906,12 +905,12 @@ public void LogIotHubDependency_WithTelemetryTypeFilter_IgnoresDependency() public void LogIotHubDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string iotHubName = _bogusGenerator.Commerce.ProductName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string iotHubName = Bogus.Commerce.ProductName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -946,13 +945,13 @@ public void LogIotHubDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_ public void LogEventHubsDependency_WithTelemetryTypeFilter_IgnoresDependency() { // Arrange - string eventHubName = _bogusGenerator.Commerce.ProductName(); - string namespaceName = _bogusGenerator.Finance.AccountName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string eventHubName = Bogus.Commerce.ProductName(); + string namespaceName = Bogus.Finance.AccountName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -978,13 +977,13 @@ public void LogEventHubsDependency_WithTelemetryTypeFilter_IgnoresDependency() public void LogEventHubsDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string eventHubName = _bogusGenerator.Commerce.ProductName(); - string namespaceName = _bogusGenerator.Finance.AccountName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string eventHubName = Bogus.Commerce.ProductName(); + string namespaceName = Bogus.Finance.AccountName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -1019,13 +1018,13 @@ public void LogEventHubsDependency_WithTelemetryTypeFilterOnDifferentTelemetryTy public void LogTableStorageDependency_WithTelemetryTypeFilter_FiltersOutDependency() { // Arrange - string tableName = _bogusGenerator.Commerce.ProductName(); - string accountName = _bogusGenerator.Finance.AccountName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string tableName = Bogus.Commerce.ProductName(); + string accountName = Bogus.Finance.AccountName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -1051,13 +1050,13 @@ public void LogTableStorageDependency_WithTelemetryTypeFilter_FiltersOutDependen public void LogTableStorageDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string tableName = _bogusGenerator.Commerce.ProductName(); - string accountName = _bogusGenerator.Finance.AccountName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string tableName = Bogus.Commerce.ProductName(); + string accountName = Bogus.Finance.AccountName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -1092,13 +1091,13 @@ public void LogTableStorageDependency_WithTelemetryTypeFilterOnDifferentTelemetr public void LogBlobStorageDependency_WithTelemetryTypeFilter_IgnoresDependency() { // Arrange - string containerName = _bogusGenerator.Commerce.ProductName(); - string accountName = _bogusGenerator.Finance.AccountName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string containerName = Bogus.Commerce.ProductName(); + string accountName = Bogus.Finance.AccountName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink(); @@ -1124,13 +1123,13 @@ public void LogBlobStorageDependency_WithTelemetryTypeFilter_IgnoresDependency() public void LogBlobStorageDependency_WithTelemetryTypeFilterOnDifferentTelemetryType_DoesNotFilterOutEntry(TelemetryType telemetryType) { // Arrange - string containerName = _bogusGenerator.Commerce.ProductName(); - string accountName = _bogusGenerator.Finance.AccountName(); - bool isSuccessful = _bogusGenerator.Random.Bool(); - DateTimeOffset startTime = _bogusGenerator.Date.PastOffset(); - TimeSpan duration = _bogusGenerator.Date.Timespan(); - string propertyName = _bogusGenerator.Random.Word(); - string propertyValue = _bogusGenerator.Random.Word(); + string containerName = Bogus.Commerce.ProductName(); + string accountName = Bogus.Finance.AccountName(); + bool isSuccessful = Bogus.Random.Bool(); + DateTimeOffset startTime = Bogus.Date.PastOffset(); + TimeSpan duration = Bogus.Date.Timespan(); + string propertyName = Bogus.Random.Word(); + string propertyValue = Bogus.Random.Word(); var properties = new Dictionary { [propertyName] = propertyValue }; var spySink = new InMemoryLogSink();