Skip to content

Commit 4d3c53c

Browse files
committed
Update SSI tests for .NET 10 (preview)
1 parent da591a5 commit 4d3c53c

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/InstrumentationTests.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,99 @@ public async Task OnEolFrameworkInSsi_WhenOverriden_CallsForwarderWithExpectedTe
466466

467467
#endif
468468
#if NETCOREAPP3_1_OR_GREATER
469+
// We have different behaviour depending on whether the framework is in preview
470+
// This condition should always point to the "next" version of .NET
471+
// e.g. if .NET 10 is in preview, use NET10_0_OR_GREATER.
472+
// Once .NET 10 goes GA, update this to NET11_0_OR_GREATER
473+
#if NET10_0_OR_GREATER
474+
[SkippableFact]
475+
[Trait("RunOnWindows", "True")]
476+
[Flaky("The creation of the app is flaky due to the .NET SDK: https://github.com/NuGet/Home/issues/14343")]
477+
public async Task OnPreviewFrameworkInSsi_CallsForwarderWithExpectedTelemetry()
478+
{
479+
var logDir = SetLogDirectory();
480+
var logFileName = Path.Combine(logDir, $"{Guid.NewGuid()}.txt");
481+
var echoApp = _fixture.GetAppPath(Output, EnvironmentHelper);
482+
Output.WriteLine("Setting forwarder to " + echoApp);
483+
Output.WriteLine("Logging telemetry to " + logFileName);
484+
485+
// indicate we're running in auto-instrumentation, this just needs to be non-null
486+
SetEnvironmentVariable("DD_INJECTION_ENABLED", "tracer");
487+
SetEnvironmentVariable("DD_TELEMETRY_FORWARDER_PATH", echoApp);
488+
// Need to force injection because we bail by default
489+
SetEnvironmentVariable("DD_INJECT_FORCE", "true");
490+
491+
SetEnvironmentVariable(WatchFileEnvironmentVariable, logFileName);
492+
493+
using var agent = EnvironmentHelper.GetMockAgent(useTelemetry: true);
494+
using var processResult = await RunSampleAndWaitForExit(agent, arguments: "traces 1");
495+
AssertInstrumented(agent, logDir);
496+
497+
var pointsJson = """
498+
[{
499+
"name": "library_entrypoint.complete",
500+
"tags": ["injection_forced:true"]
501+
}]
502+
""";
503+
AssertHasExpectedTelemetry(logFileName, processResult, pointsJson);
504+
}
505+
506+
[SkippableFact]
507+
[Trait("RunOnWindows", "True")]
508+
[Flaky("The creation of the app is flaky due to the .NET SDK: https://github.com/NuGet/Home/issues/14343")]
509+
public async Task OnPreviewFrameworkInSsi_WhenForwarderPathExists_CallsForwarderWithExpectedTelemetry()
510+
{
511+
var logDir = SetLogDirectory();
512+
var logFileName = Path.Combine(logDir, $"{Guid.NewGuid()}.txt");
513+
514+
var echoApp = _fixture.GetAppPath(Output, EnvironmentHelper);
515+
Output.WriteLine("Setting forwarder to " + echoApp);
516+
Output.WriteLine("Logging telemetry to " + logFileName);
517+
518+
// indicate we're running in auto-instrumentation, this just needs to be non-null
519+
SetEnvironmentVariable("DD_INJECTION_ENABLED", "tracer");
520+
SetEnvironmentVariable("DD_TELEMETRY_FORWARDER_PATH", echoApp);
521+
522+
SetEnvironmentVariable(WatchFileEnvironmentVariable, logFileName);
523+
524+
using var agent = EnvironmentHelper.GetMockAgent(useTelemetry: true);
525+
using var processResult = await RunSampleAndWaitForExit(agent, arguments: "traces 1");
526+
AssertNotInstrumented(agent, logDir);
527+
528+
var pointsJson = """
529+
[{
530+
"name": "library_entrypoint.abort",
531+
"tags": ["reason:incompatible_runtime"]
532+
},{
533+
"name": "library_entrypoint.abort.runtime"
534+
}]
535+
""";
536+
AssertHasExpectedTelemetry(logFileName, processResult, pointsJson);
537+
}
538+
539+
[SkippableFact]
540+
[Trait("RunOnWindows", "True")]
541+
public async Task OnPreviewFrameworkInSsi_Buffers()
542+
{
543+
// indicate we're running in auto-instrumentation, this just needs to be non-null
544+
SetEnvironmentVariable("DD_INJECTION_ENABLED", "tracer");
545+
var logDir = SetLogDirectory();
546+
547+
using var agent = EnvironmentHelper.GetMockAgent(useTelemetry: true);
548+
using var processResult = await RunSampleAndWaitForExit(agent, arguments: "traces 1");
549+
AssertNotInstrumented(agent, logDir);
550+
// this is already tested in AssertNotInstrumented, but adding an explicit check here to make sure
551+
if (EnvironmentTools.IsWindows())
552+
{
553+
AssertNativeLoaderLogContainsString(logDir, "Buffering of logs enabled");
554+
Directory.GetFiles(logDir).Should().NotContain(filename => Path.GetFileName(filename).StartsWith("dotnet-"));
555+
}
556+
else
557+
{
558+
AssertNativeLoaderLogContainsString(logDir, "Buffering of logs disabled");
559+
}
560+
}
561+
#else
469562
[SkippableTheory]
470563
[Trait("RunOnWindows", "True")]
471564
[InlineData("1")]
@@ -521,6 +614,7 @@ public async Task OnSupportedFrameworkInSsi_BuffersLogsInitiallyAndThenFlushes()
521614
AssertNativeLoaderLogContainsString(logDir, "Buffering of logs disabled");
522615
}
523616
}
617+
#endif
524618
#endif
525619

526620
// The dynamic context switch/bail out is only available in .NET 8+

0 commit comments

Comments
 (0)