Skip to content

Commit

Permalink
wider system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vandonr committed Aug 14, 2024
1 parent 80af8b5 commit 7c1ef10
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ public MicrosoftDataSqlClientTests(ITestOutputHelper output)
public static IEnumerable<object[]> 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);

[SkippableTheory]
[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)
Expand Down Expand Up @@ -65,20 +67,27 @@ 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;

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);
}
Expand Down

0 comments on commit 7c1ef10

Please sign in to comment.