From e47e3b170d605f1e589d14265a1a97d8b66a7f25 Mon Sep 17 00:00:00 2001
From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com>
Date: Wed, 25 May 2022 10:15:28 +0200
Subject: [PATCH 1/3] feat: add dependency id to cosmosdb dep tracking
---
.../ILoggerCosmosSqlDependencyExtensions.cs | 84 ++++++-
.../CosmosSqlDependencyTests.cs | 41 ++--
.../CosmosSqlDependencyLoggingTests.cs | 228 +++++++++++++++---
3 files changed, 296 insertions(+), 57 deletions(-)
diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs
index b9bf6f23..14e3fd5a 100644
--- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs
+++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs
@@ -78,13 +78,81 @@ public static void LogCosmosSqlDependency(
/// Logs a Cosmos SQL dependency.
///
/// The logger to track the telemetry.
- /// Name of the storage resource
- /// Name of the database
- /// Name of the container
- /// Indication whether or not the operation was successful
- /// Point in time when the interaction with the dependency was started
- /// Duration of the operation
- /// Context that provides more insights on the dependency that was measured
+ /// The name of the storage resource.
+ /// The name of the database.
+ /// The name of the container.
+ /// The indication whether or not the operation was successful
+ /// The measuring the latency of the dependency.
+ /// The ID of the dependency to link as parent ID.
+ /// The context that provides more insights on the dependency that was measured.
+ /// Thrown when the or is null.
+ /// Thrown when the , , or is blank.
+ public static void LogCosmosSqlDependency(
+ this ILogger logger,
+ string accountName,
+ string database,
+ string container,
+ bool isSuccessful,
+ DurationMeasurement measurement,
+ string dependencyId,
+ Dictionary context = null)
+ {
+ Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry");
+ Guard.NotNullOrWhitespace(accountName, nameof(accountName), "Requires a non-blank account name of the Cosmos SQL storage to track a Cosmos SQL dependency");
+ Guard.NotNullOrWhitespace(database, nameof(database), "Requires a non-blank database name of the Cosmos SQL storage to track a Cosmos SQL dependency");
+ Guard.NotNullOrWhitespace(container, nameof(container), "Requires a non-blank container name of the Cosmos SQL storage to track a Cosmos SQL dependency");
+ Guard.NotNull(measurement, nameof(measurement), "Requires a dependency measurement instance to track the latency of the Cosmos SQL storage when tracking an Cosmos SQL dependency");
+
+ LogCosmosSqlDependency(logger, accountName, database, container, isSuccessful, measurement.StartTime, measurement.Elapsed, dependencyId, context);
+ }
+
+ ///
+ /// Logs a Cosmos SQL dependency.
+ ///
+ /// The logger to track the telemetry.
+ /// The name of the storage resource.
+ /// The name of the database.
+ /// The name of the container.
+ /// The indication whether or not the operation was successful.
+ /// The point in time when the interaction with the dependency was started.
+ /// The duration of the operation.
+ /// The context that provides more insights on the dependency that was measured.
+ /// Thrown when the is null.
+ /// Thrown when the , , or is blank.
+ /// Thrown when the is a negative time range.
+ public static void LogCosmosSqlDependency(
+ this ILogger logger,
+ string accountName,
+ string database,
+ string container,
+ bool isSuccessful,
+ DateTimeOffset startTime,
+ TimeSpan duration,
+ Dictionary context = null)
+ {
+ Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry");
+ Guard.NotNullOrWhitespace(accountName, nameof(accountName), "Requires a non-blank account name of the Cosmos SQL storage to track a Cosmos SQL dependency");
+ Guard.NotNullOrWhitespace(database, nameof(database), "Requires a non-blank database name of the Cosmos SQL storage to track a Cosmos SQL dependency");
+ 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);
+ }
+
+ ///
+ /// Logs a Cosmos SQL dependency.
+ ///
+ /// The logger to track the telemetry.
+ /// The name of the storage resource.
+ /// The name of the database.
+ /// The name of the container.
+ /// The indication whether or not the operation was successful.
+ /// The point in time when the interaction with the dependency was started.
+ /// The duration of the operation.
+ /// The ID of the dependency to link as parent ID.
+ /// The context that provides more insights on the dependency that was measured.
/// Thrown when the is null.
/// Thrown when the , , or is blank.
/// Thrown when the is a negative time range.
@@ -96,6 +164,7 @@ public static void LogCosmosSqlDependency(
bool isSuccessful,
DateTimeOffset startTime,
TimeSpan duration,
+ string dependencyId,
Dictionary context = null)
{
Guard.NotNull(logger, nameof(logger), "Requires a logger instance to track telemetry");
@@ -114,6 +183,7 @@ public static void LogCosmosSqlDependency(
targetName: accountName,
duration: duration,
startTime: startTime,
+ dependencyId: dependencyId,
resultCode: null,
isSuccessful:
isSuccessful,
diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs
index 8fc4805f..3aea529e 100644
--- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs
+++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs
@@ -29,20 +29,20 @@ public async Task LogCosmosSqlDependency_SinksToApplicationInsights_ResultsInCos
string container = BogusGenerator.Commerce.ProductName();
string database = BogusGenerator.Commerce.ProductName();
string accountName = BogusGenerator.Finance.AccountName();
- string dependencyData = $"{database}/{container}";
string dependencyName = $"{database}/{container}";
+ string dependencyId = BogusGenerator.Random.Guid().ToString();
using (ILoggerFactory loggerFactory = CreateLoggerFactory(config => config.Enrich.WithComponentName(componentName)))
{
ILogger logger = loggerFactory.CreateLogger();
bool isSuccessful = BogusGenerator.PickRandom(true, false);
- DateTimeOffset startTime = DateTimeOffset.Now; // BogusGenerator.Date.RecentOffset(days: 0);
+ DateTimeOffset startTime = DateTimeOffset.Now;
TimeSpan duration = BogusGenerator.Date.Timespan();
Dictionary telemetryContext = CreateTestTelemetryContext();
// Act
- logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, startTime, duration, telemetryContext);
+ logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, startTime, duration, dependencyId, telemetryContext);
}
// Assert
@@ -51,34 +51,41 @@ public async Task LogCosmosSqlDependency_SinksToApplicationInsights_ResultsInCos
await RetryAssertUntilTelemetryShouldBeAvailableAsync(async () =>
{
EventsResults results =
- await client.Events.GetDependencyEventsAsync(ApplicationId,
- timespan: "PT15M");
+ await client.Events.GetDependencyEventsAsync(ApplicationId, PastHalfHourTimeSpan);
+
Assert.NotEmpty(results.Value);
- Assert.Contains(results.Value, result =>
+ AssertX.Any(results.Value, result =>
{
- return result.Dependency.Type == dependencyType
- && result.Dependency.Target == accountName
- && result.Dependency.Data == dependencyData
- && result.Cloud.RoleName == componentName
- && result.Dependency.Name == dependencyName;
+ Assert.Equal(dependencyType, result.Dependency.Type);
+ Assert.Equal(accountName, result.Dependency.Target);
+ Assert.Equal(dependencyName, result.Dependency.Data);
+ Assert.Equal(componentName, result.Cloud.RoleName);
+ Assert.Equal(dependencyName, result.Dependency.Name);
});
});
}
- AssertX.Any(GetLogEventsFromMemory(), logEvent => {
+ AssertSerilogLogProperties(dependencyType, dependencyName, accountName);
+ }
+
+ private void AssertSerilogLogProperties(string dependencyType, string dependencyName, string accountName)
+ {
+ IEnumerable logEvents = GetLogEventsFromMemory();
+ AssertX.Any(logEvents, logEvent =>
+ {
StructureValue logEntry = logEvent.Properties.GetAsStructureValue(ContextProperties.DependencyTracking.DependencyLogEntry);
Assert.NotNull(logEntry);
- var actualDependencyType = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyType));
+ LogEventProperty actualDependencyType = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyType));
Assert.Equal(dependencyType, actualDependencyType.Value.ToDecentString());
- var actualDependencyData = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyData));
- Assert.Equal(dependencyData, actualDependencyData.Value.ToDecentString());
+ LogEventProperty actualDependencyData = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyData));
+ Assert.Equal(dependencyName, actualDependencyData.Value.ToDecentString());
- var actualTargetName = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.TargetName));
+ LogEventProperty actualTargetName = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.TargetName));
Assert.Equal(accountName, actualTargetName.Value.ToDecentString());
- var actualDependencyName = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyName));
+ LogEventProperty actualDependencyName = Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.DependencyName));
Assert.Equal(dependencyName, actualDependencyName.Value.ToDecentString());
Assert.Single(logEntry.Properties, prop => prop.Name == nameof(DependencyLogEntry.Context));
diff --git a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CosmosSqlDependencyLoggingTests.cs b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CosmosSqlDependencyLoggingTests.cs
index ef0b25ed..222d24c9 100644
--- a/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CosmosSqlDependencyLoggingTests.cs
+++ b/src/Arcus.Observability.Tests.Unit/Telemetry/Logging/CosmosSqlDependencyLoggingTests.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using Arcus.Observability.Telemetry.Core;
using Arcus.Observability.Telemetry.Core.Logging;
using Bogus;
@@ -10,19 +11,19 @@ namespace Arcus.Observability.Tests.Unit.Telemetry.Logging
[Trait("Category", "Unit")]
public class CosmosSqlDependencyLoggingTests
{
- private readonly Faker _bogusGenerator = new Faker();
+ private static readonly Faker BogusGenerator = new Faker();
[Fact]
public void LogCosmosSqlDependency_ValidArguments_Succeeds()
{
// Arrange
var logger = new TestLogger();
- 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 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();
// Act
logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, startTime, duration);
@@ -40,31 +41,80 @@ public void LogCosmosSqlDependency_ValidArguments_Succeeds()
Assert.Contains("Azure DocumentDB " + dependencyName, logMessage);
}
+ [Fact]
+ public void LogCosmosSqlDependencyWithDependencyId_ValidArguments_Succeeds()
+ {
+ // Arrange
+ var logger = new TestLogger();
+ string container = BogusGenerator.Lorem.Word();
+ string database = BogusGenerator.Lorem.Word();
+ string accountName = BogusGenerator.Lorem.Word();
+ bool isSuccessful = BogusGenerator.Random.Bool();
+ DateTimeOffset startTime = BogusGenerator.Date.PastOffset();
+ TimeSpan duration = BogusGenerator.Date.Timespan();
+ string dependencyId = BogusGenerator.Lorem.Word();
+
+ string key = BogusGenerator.Lorem.Word();
+ string value = BogusGenerator.Lorem.Word();
+ var context = new Dictionary { [key] = value };
+
+ // Act
+ logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, startTime, duration, dependencyId, context);
+
+ // Assert
+ DependencyLogEntry dependency = logger.GetMessageAsDependency();
+ Assert.Equal("Azure DocumentDB", dependency.DependencyType);
+ Assert.Equal(accountName, dependency.TargetName);
+ Assert.Equal($"{database}/{container}", dependency.DependencyName);
+ Assert.Equal($"{database}/{container}", dependency.DependencyData);
+ Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime);
+ Assert.Equal(duration, dependency.Duration);
+ Assert.Equal(dependencyId, dependency.DependencyId);
+ Assert.Equal(value, Assert.Contains(key, dependency.Context));
+ }
+
[Fact]
public void LogCosmosSqlDependency_WithNegativeDuration_Fails()
{
// Arrange
var logger = new TestLogger();
- 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();
+ 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 = TimeSpanGenerator.GeneratePositiveDuration().Negate();
// Act / Assert
Assert.ThrowsAny(() => logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, startTime, duration));
}
+ [Fact]
+ public void LogCosmosSqlDependencyWithDependencyId_WithNegativeDuration_Fails()
+ {
+ // Arrange
+ var logger = new TestLogger();
+ 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 = TimeSpanGenerator.GeneratePositiveDuration().Negate();
+ string dependencyId = BogusGenerator.Lorem.Word();
+
+ // Act / Assert
+ Assert.ThrowsAny(() => logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, startTime, duration, dependencyId));
+ }
+
[Fact]
public void LogCosmosSqlDependencyWithDependencyMeasurement_ValidArguments_Succeeds()
{
// Arrange
var logger = new TestLogger();
- string container = _bogusGenerator.Commerce.ProductName();
- string database = _bogusGenerator.Commerce.ProductName();
- string accountName = _bogusGenerator.Finance.AccountName();
- bool isSuccessful = _bogusGenerator.Random.Bool();
+ string container = BogusGenerator.Commerce.ProductName();
+ string database = BogusGenerator.Commerce.ProductName();
+ string accountName = BogusGenerator.Finance.AccountName();
+ bool isSuccessful = BogusGenerator.Random.Bool();
var measurement = DependencyMeasurement.Start();
DateTimeOffset startTime = measurement.StartTime;
@@ -92,10 +142,10 @@ public void LogCosmosSqlDependencyWithDurationMeasurement_ValidArguments_Succeed
{
// Arrange
var logger = new TestLogger();
- string container = _bogusGenerator.Lorem.Word();
- string database = _bogusGenerator.Lorem.Word();
- string accountName = _bogusGenerator.Lorem.Word();
- bool isSuccessful = _bogusGenerator.Random.Bool();
+ string container = BogusGenerator.Lorem.Word();
+ string database = BogusGenerator.Lorem.Word();
+ string accountName = BogusGenerator.Lorem.Word();
+ bool isSuccessful = BogusGenerator.Random.Bool();
var measurement = DurationMeasurement.Start();
DateTimeOffset startTime = measurement.StartTime;
@@ -116,15 +166,51 @@ public void LogCosmosSqlDependencyWithDurationMeasurement_ValidArguments_Succeed
Assert.Equal(isSuccessful, dependency.IsSuccessful);
}
+ [Fact]
+ public void LogCosmosSqlDependencyWithDurationMeasurementWithDependencyId_ValidArguments_Succeeds()
+ {
+ // Arrange
+ var logger = new TestLogger();
+ string container = BogusGenerator.Lorem.Word();
+ string database = BogusGenerator.Lorem.Word();
+ string accountName = BogusGenerator.Lorem.Word();
+ bool isSuccessful = BogusGenerator.Random.Bool();
+
+ var measurement = DurationMeasurement.Start();
+ DateTimeOffset startTime = measurement.StartTime;
+ measurement.Dispose();
+ TimeSpan duration = measurement.Elapsed;
+ string dependencyId = BogusGenerator.Lorem.Word();
+
+ string key = BogusGenerator.Lorem.Word();
+ string value = BogusGenerator.Lorem.Word();
+ var context = new Dictionary { [key] = value };
+
+ // Act
+ logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, measurement, dependencyId, context);
+
+ // Assert
+ DependencyLogEntry dependency = logger.GetMessageAsDependency();
+ Assert.Equal(accountName, dependency.TargetName);
+ Assert.Equal("Azure DocumentDB", dependency.DependencyType);
+ Assert.Equal(database + "/" + container, dependency.DependencyName);
+ Assert.Equal(database + "/" + container, dependency.DependencyData);
+ Assert.Equal(startTime.ToString(FormatSpecifiers.InvariantTimestampFormat), dependency.StartTime);
+ Assert.Equal(duration, dependency.Duration);
+ Assert.Equal(isSuccessful, dependency.IsSuccessful);
+ Assert.Equal(dependencyId, dependency.DependencyId);
+ Assert.Equal(value, Assert.Contains(key, dependency.Context));
+ }
+
[Theory]
[ClassData(typeof(Blanks))]
public void LogCosmosSqlDependencyWithDurationMeasurement_WithoutAccountName_Fails(string accountName)
{
// Arrange
var logger = new TestLogger();
- string container = _bogusGenerator.Commerce.ProductName();
- string database = _bogusGenerator.Commerce.ProductName();
- bool isSuccessful = _bogusGenerator.Random.Bool();
+ string container = BogusGenerator.Commerce.ProductName();
+ string database = BogusGenerator.Commerce.ProductName();
+ bool isSuccessful = BogusGenerator.Random.Bool();
var measurement = DurationMeasurement.Start();
measurement.Dispose();
@@ -134,15 +220,34 @@ public void LogCosmosSqlDependencyWithDurationMeasurement_WithoutAccountName_Fai
() => logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, measurement));
}
+ [Theory]
+ [ClassData(typeof(Blanks))]
+ public void LogCosmosSqlDependencyWithDurationMeasurementWithDependencyId_WithoutAccountName_Fails(string accountName)
+ {
+ // Arrange
+ var logger = new TestLogger();
+ string container = BogusGenerator.Commerce.ProductName();
+ string database = BogusGenerator.Commerce.ProductName();
+ bool isSuccessful = BogusGenerator.Random.Bool();
+
+ var measurement = DurationMeasurement.Start();
+ measurement.Dispose();
+ string dependencyId = BogusGenerator.Lorem.Word();
+
+ // Act / Assert
+ Assert.ThrowsAny(
+ () => logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, measurement, dependencyId));
+ }
+
[Theory]
[ClassData(typeof(Blanks))]
public void LogCosmosSqlDependencyWithDurationMeasurement_WithoutDatabase_Fails(string database)
{
// Arrange
var logger = new TestLogger();
- string container = _bogusGenerator.Commerce.ProductName();
- string accountName = _bogusGenerator.Finance.AccountName();
- bool isSuccessful = _bogusGenerator.Random.Bool();
+ string container = BogusGenerator.Commerce.ProductName();
+ string accountName = BogusGenerator.Finance.AccountName();
+ bool isSuccessful = BogusGenerator.Random.Bool();
var measurement = DurationMeasurement.Start();
measurement.Dispose();
@@ -152,15 +257,34 @@ public void LogCosmosSqlDependencyWithDurationMeasurement_WithoutDatabase_Fails(
() => logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, measurement));
}
+ [Theory]
+ [ClassData(typeof(Blanks))]
+ public void LogCosmosSqlDependencyWithDurationMeasurementWithDependencyId_WithoutDatabase_Fails(string database)
+ {
+ // Arrange
+ var logger = new TestLogger();
+ string container = BogusGenerator.Commerce.ProductName();
+ string accountName = BogusGenerator.Finance.AccountName();
+ bool isSuccessful = BogusGenerator.Random.Bool();
+
+ var measurement = DurationMeasurement.Start();
+ measurement.Dispose();
+ string dependencyId = BogusGenerator.Lorem.Word();
+
+ // Act / Assert
+ Assert.ThrowsAny(
+ () => logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, measurement, dependencyId));
+ }
+
[Theory]
[ClassData(typeof(Blanks))]
public void LogCosmosSqlDependencyWithDurationMeasurement_WithoutContainer_Fails(string container)
{
// Arrange
var logger = new TestLogger();
- string database = _bogusGenerator.Commerce.ProductName();
- string accountName = _bogusGenerator.Finance.AccountName();
- bool isSuccessful = _bogusGenerator.Random.Bool();
+ string database = BogusGenerator.Commerce.ProductName();
+ string accountName = BogusGenerator.Finance.AccountName();
+ bool isSuccessful = BogusGenerator.Random.Bool();
var measurement = DurationMeasurement.Start();
measurement.Dispose();
@@ -170,15 +294,34 @@ public void LogCosmosSqlDependencyWithDurationMeasurement_WithoutContainer_Fails
() => logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, measurement));
}
+ [Theory]
+ [ClassData(typeof(Blanks))]
+ public void LogCosmosSqlDependencyWithDurationMeasurementWithDependencyId_WithoutContainer_Fails(string container)
+ {
+ // Arrange
+ var logger = new TestLogger();
+ string database = BogusGenerator.Commerce.ProductName();
+ string accountName = BogusGenerator.Finance.AccountName();
+ bool isSuccessful = BogusGenerator.Random.Bool();
+
+ var measurement = DurationMeasurement.Start();
+ measurement.Dispose();
+ string dependencyId = BogusGenerator.Lorem.Word();
+
+ // Act / Assert
+ Assert.ThrowsAny(
+ () => logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, measurement, dependencyId));
+ }
+
[Fact]
public void LogCosmosSqlDependencyWithDurationMeasurement_WithoutMeasurement_Fails()
{
// 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();
+ string database = BogusGenerator.Commerce.ProductName();
+ string container = BogusGenerator.Commerce.ProductName();
+ string accountName = BogusGenerator.Finance.AccountName();
+ bool isSuccessful = BogusGenerator.Random.Bool();
var measurement = DurationMeasurement.Start();
measurement.Dispose();
@@ -187,5 +330,24 @@ public void LogCosmosSqlDependencyWithDurationMeasurement_WithoutMeasurement_Fai
Assert.ThrowsAny(
() => logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, measurement: (DurationMeasurement)null));
}
+
+ [Fact]
+ public void LogCosmosSqlDependencyWithDurationMeasurementWithDependencyId_WithoutMeasurement_Fails()
+ {
+ // 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 measurement = DurationMeasurement.Start();
+ measurement.Dispose();
+ string dependencyId = BogusGenerator.Lorem.Word();
+
+ // Act / Assert
+ Assert.ThrowsAny(
+ () => logger.LogCosmosSqlDependency(accountName, database, container, isSuccessful, measurement: null, dependencyId));
+ }
}
}
From 6b0d20fcd4b0765317effe2c60a582a2b981e1f4 Mon Sep 17 00:00:00 2001
From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com>
Date: Wed, 1 Jun 2022 07:12:08 +0200
Subject: [PATCH 2/3] pr-sug: add better description for duration measurement
---
.../Extensions/ILoggerCosmosSqlDependencyExtensions.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs
index 14e3fd5a..d2bfab1f 100644
--- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs
+++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs
@@ -52,7 +52,7 @@ public static void LogCosmosSqlDependency(
/// The name of the database.
/// The name of the container.
/// The indication whether or not the operation was successful
- /// The measuring the latency of the dependency.
+ /// The measuring of the latency to call the dependency.
/// The context that provides more insights on the dependency that was measured.
/// Thrown when the or is null.
/// Thrown when the , , or is blank.
@@ -82,7 +82,7 @@ public static void LogCosmosSqlDependency(
/// The name of the database.
/// The name of the container.
/// The indication whether or not the operation was successful
- /// The measuring the latency of the dependency.
+ /// The measuring of the latency to call the dependency.
/// The ID of the dependency to link as parent ID.
/// The context that provides more insights on the dependency that was measured.
/// Thrown when the or is null.
From e559febfe08d213c6ebabb6e7863ebdae842a9ec Mon Sep 17 00:00:00 2001
From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com>
Date: Wed, 1 Jun 2022 08:26:28 +0200
Subject: [PATCH 3/3] pr-fix: use 'duration' io 'latency' for duration
measurement description
---
.../Extensions/ILoggerCosmosSqlDependencyExtensions.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs
index d2bfab1f..0ce9846e 100644
--- a/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs
+++ b/src/Arcus.Observability.Telemetry.Core/Extensions/ILoggerCosmosSqlDependencyExtensions.cs
@@ -52,7 +52,7 @@ public static void LogCosmosSqlDependency(
/// The name of the database.
/// The name of the container.
/// The indication whether or not the operation was successful
- /// The measuring of the latency to call the dependency.
+ /// The measuring of the duration to call the dependency.
/// The context that provides more insights on the dependency that was measured.
/// Thrown when the or is null.
/// Thrown when the , , or is blank.
@@ -82,7 +82,7 @@ public static void LogCosmosSqlDependency(
/// The name of the database.
/// The name of the container.
/// The indication whether or not the operation was successful
- /// The measuring of the latency to call the dependency.
+ /// The measuring of the duration to call the dependency.
/// The ID of the dependency to link as parent ID.
/// The context that provides more insights on the dependency that was measured.
/// Thrown when the or is null.