From 7c1ef10f1fdc65bfca2e34236342c660b88cfe71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vandon?= Date: Fri, 26 Jul 2024 16:30:06 +0200 Subject: [PATCH] wider system tests --- .../AdoNet/MicrosoftDataSqlClientTests.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqlClientTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqlClientTests.cs index 18445aad2d8f..4a39d08ef8f9 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqlClientTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/AdoNet/MicrosoftDataSqlClientTests.cs @@ -26,7 +26,9 @@ public MicrosoftDataSqlClientTests(ITestOutputHelper output) public static IEnumerable GetEnabledConfig() => from packageVersionArray in PackageVersions.MicrosoftDataSqlClient from metadataSchemaVersion in new[] { "v0", "v1" } - select new[] { packageVersionArray[0], metadataSchemaVersion }; + from dbmEnabled in new[] { true, false } + from propagation in new[] { "disabled", "service", "full" } + select new[] { packageVersionArray[0], metadataSchemaVersion, dbmEnabled, propagation }; public override Result ValidateIntegrationSpan(MockSpan span, string metadataSchemaVersion) => span.IsSqlClient(metadataSchemaVersion); @@ -34,7 +36,7 @@ public static IEnumerable GetEnabledConfig() [MemberData(nameof(GetEnabledConfig))] [Trait("Category", "EndToEnd")] [Trait("RunOnWindows", "True")] - public async Task SubmitsTraces(string packageVersion, string metadataSchemaVersion) + public async Task SubmitsTraces(string packageVersion, string metadataSchemaVersion, bool dbmEnabled, string propagation) { // ALWAYS: 133 spans // - SqlCommand: 21 spans (3 groups * 7 spans) @@ -65,9 +67,13 @@ public async Task SubmitsTraces(string packageVersion, string metadataSchemaVers } var expectedSpanCount = isVersion4 ? 91 : 147; + // there are as many spans for the instrumentation as regular spans, since we create one extra for each query. + var expectedInstrumentationSpanCount = propagation == "full" ? expectedSpanCount : 0; const string dbType = "sql-server"; const string expectedOperationName = dbType + ".query"; + SetEnvironmentVariable(ConfigurationKeys.DataStreamsMonitoring.Enabled, dbmEnabled ? "1" : "0"); + SetEnvironmentVariable("DD_DBM_PROPAGATION_MODE", propagation); SetEnvironmentVariable("DD_TRACE_SPAN_ATTRIBUTE_SCHEMA", metadataSchemaVersion); var isExternalSpan = metadataSchemaVersion == "v0"; var clientSpanServiceName = isExternalSpan ? $"{EnvironmentHelper.FullSampleName}-{dbType}" : EnvironmentHelper.FullSampleName; @@ -75,10 +81,13 @@ public async Task SubmitsTraces(string packageVersion, string metadataSchemaVers using var telemetry = this.ConfigureTelemetry(); using var agent = EnvironmentHelper.GetMockAgent(); using var process = await RunSampleAndWaitForExit(agent, packageVersion: packageVersion); + var spans = agent.WaitForSpans(expectedSpanCount, operationName: expectedOperationName); - int actualSpanCount = spans.Count(s => s.ParentId.HasValue); // Remove unexpected DB spans from the calculation + var actualSpanCount = spans.Count(s => s.ParentId.HasValue); // Remove unexpected DB spans from the calculation + var instrumentationSpans = agent.WaitForSpans(expectedInstrumentationSpanCount, operationName: "set context_info"); Assert.Equal(expectedSpanCount, actualSpanCount); + Assert.Equal(expectedInstrumentationSpanCount, instrumentationSpans.Count); ValidateIntegrationSpans(spans, metadataSchemaVersion, expectedServiceName: clientSpanServiceName, isExternalSpan); telemetry.AssertIntegrationEnabled(IntegrationId.SqlClient); }