Skip to content

Commit 57d816f

Browse files
andrewlockNachoEchevarria
authored andcommitted
Update SSI tests for .NET 10 (preview)
1 parent 6f33626 commit 57d816f

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
@@ -461,6 +461,99 @@ public async Task OnEolFrameworkInSsi_WhenOverriden_CallsForwarderWithExpectedTe
461461

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

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

0 commit comments

Comments
 (0)