diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/ApplicationInfo/ApplicationInfoTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/ApplicationInfo/ApplicationInfoTest.cs index 12aaefa79ca6..a657cf8859c9 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/ApplicationInfo/ApplicationInfoTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/ApplicationInfo/ApplicationInfoTest.cs @@ -11,8 +11,6 @@ using System.Text.RegularExpressions; using Datadog.Profiler.IntegrationTests.Helpers; using FluentAssertions; -using FluentAssertions.Collections; -using FluentAssertions.Common; using Xunit.Abstractions; namespace Datadog.Profiler.IntegrationTests.ApplicationInfo @@ -35,7 +33,7 @@ public void UseTracerServiceName(string appName, string framework, string appAss ServiceName = null }; - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); var infos = new List<(string ServiceName, string Environment, string Version)>(); @@ -62,7 +60,7 @@ public void CheckMetadataAreSent(string appName, string framework, string appAss { var runner = new TestApplicationRunner(appName, framework, appAssembly, _output); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); var infos = new List(); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/Bugs/NullOrEmptyThreadNameCheck.cs b/profiler/test/Datadog.Profiler.IntegrationTests/Bugs/NullOrEmptyThreadNameCheck.cs index 475e16695207..fb02df926042 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/Bugs/NullOrEmptyThreadNameCheck.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/Bugs/NullOrEmptyThreadNameCheck.cs @@ -28,7 +28,7 @@ public void ShouldNotCrashWhenNullOrEmptyThreadName(string appName, string frame runner.Environment.SetVariable(EnvironmentVariables.WallTimeProfilerEnabled, "1"); runner.Environment.SetVariable(EnvironmentVariables.CpuProfilerEnabled, "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); // we should not see any crash + get callstacks for threads with no name diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/CodeHotspot/CodeHotspotTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/CodeHotspot/CodeHotspotTest.cs index 9e8a090818da..e9bf69063e82 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/CodeHotspot/CodeHotspotTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/CodeHotspot/CodeHotspotTest.cs @@ -39,7 +39,7 @@ public void CheckTraceContextAreAttachedForWalltimeProfilerHumberOfThreads(strin runner.Environment.SetVariable(EnvironmentVariables.WallTimeProfilerEnabled, "1"); runner.Environment.SetVariable(EnvironmentVariables.CpuProfilerEnabled, "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); var profilerRuntimeIds = new List(); agent.ProfilerRequestReceived += (object sender, EventArgs ctx) => @@ -87,7 +87,7 @@ public void CheckSpanContextAreAttachedForWalltimeProfiler(string appName, strin runner.Environment.SetVariable(EnvironmentVariables.WallTimeProfilerEnabled, "1"); runner.Environment.SetVariable(EnvironmentVariables.CpuProfilerEnabled, "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); var profilerRuntimeIds = new List(); agent.ProfilerRequestReceived += (object sender, EventArgs ctx) => @@ -134,7 +134,7 @@ public void CheckSpanContextAreAttachedForCpuProfiler(string appName, string fra runner.Environment.SetVariable(EnvironmentVariables.WallTimeProfilerEnabled, "0"); runner.Environment.SetVariable(EnvironmentVariables.CpuProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); var profilerRuntimeIds = new List(); agent.ProfilerRequestReceived += (object sender, EventArgs ctx) => @@ -178,7 +178,7 @@ public void NoTraceContextAttachedIfFeatureDeactivated(string appName, string fr var runner = new TestApplicationRunner(appName, framework, appAssembly, _output, enableTracer: true, commandLine: ScenarioCodeHotspot); runner.Environment.SetVariable(EnvironmentVariables.CodeHotSpotsEnable, "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -196,7 +196,7 @@ public void CheckEndpointsAreAttached(string appName, string framework, string a // By default, the endpoint profiling feature is activated - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -214,7 +214,7 @@ public void NoEndpointsAttachedIfFeatureDeactivated(string appName, string frame runner.TestDurationInSeconds = 20; runner.Environment.SetVariable(EnvironmentVariables.EndpointProfilerEnabled, "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/Contention/ContentionProfilerTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/Contention/ContentionProfilerTest.cs index 760ed69d94fe..cb41283bd4fc 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/Contention/ContentionProfilerTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/Contention/ContentionProfilerTest.cs @@ -31,7 +31,7 @@ public void ShouldGetContentionSamples(string appName, string framework, string EnvironmentHelper.DisableDefaultProfilers(runner); runner.Environment.SetVariable(EnvironmentVariables.ContentionProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -56,7 +56,7 @@ public void ShouldContentionProfilerBeEnabledByDefault(string appName, string fr runner.Environment.SetVariable(EnvironmentVariables.GarbageCollectionProfilerEnabled, "0"); runner.Environment.SetVariable(EnvironmentVariables.ExceptionProfilerEnabled, "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -78,7 +78,7 @@ public void ExplicitlyDisableContentionProfiler(string appName, string framework EnvironmentHelper.DisableDefaultProfilers(runner); runner.Environment.SetVariable(EnvironmentVariables.WallTimeProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/CpuAndWallTime/CpuAndWallTimeTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/CpuAndWallTime/CpuAndWallTimeTest.cs index e7c7d3dd5c1f..2e8af021448e 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/CpuAndWallTime/CpuAndWallTimeTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/CpuAndWallTime/CpuAndWallTimeTest.cs @@ -29,7 +29,7 @@ public void GetCpuSamplesIfCpuProfilerIsActivatedByDefault(string appName, strin runner.Environment.SetVariable(EnvironmentVariables.ExceptionProfilerEnabled, "0"); runner.Environment.SetVariable(EnvironmentVariables.ContentionProfilerEnabled, "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -47,7 +47,7 @@ public void GetWalltimeSamplesIfWalltimeProfilerIsActivatedByDefault(string appN runner.Environment.SetVariable(EnvironmentVariables.ExceptionProfilerEnabled, "0"); runner.Environment.SetVariable(EnvironmentVariables.ContentionProfilerEnabled, "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -61,7 +61,7 @@ public void NoSampleIfCpuAndWalltimeProfilersAreDeactivated(string appName, stri var runner = new TestApplicationRunner(appName, framework, appAssembly, _output, commandLine: CmdLine); EnvironmentHelper.DisableDefaultProfilers(runner); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -76,7 +76,7 @@ public void GetCpuSamplesIfCpuProfilerIsActivated(string appName, string framewo EnvironmentHelper.DisableDefaultProfilers(runner); runner.Environment.SetVariable(EnvironmentVariables.CpuProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -91,7 +91,7 @@ public void CheckCpuDurationInSamples(string appName, string framework, string a EnvironmentHelper.DisableDefaultProfilers(runner); runner.Environment.SetVariable(EnvironmentVariables.CpuProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -130,7 +130,7 @@ public void CheckWalltimeDurationInSamples(string appName, string framework, str EnvironmentHelper.DisableDefaultProfilers(runner); runner.Environment.SetVariable(EnvironmentVariables.WallTimeProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -149,7 +149,7 @@ public void GetWalltimeSamplesIfWalltimeProfilerIsActivated(string appName, stri EnvironmentHelper.DisableDefaultProfilers(runner); runner.Environment.SetVariable(EnvironmentVariables.WallTimeProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/DebugInfo/GitMetadataTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/DebugInfo/GitMetadataTest.cs index f219025cc036..421943ca3299 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/DebugInfo/GitMetadataTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/DebugInfo/GitMetadataTest.cs @@ -192,7 +192,7 @@ private static HashSet ExtractTracerGitMetadata(HttpListenerRequest private (HashSet ProfilerGitMetadata, HashSet TracerGitMetdata) RunTest(TestApplicationRunner runner) { - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); var profilerGitMetadata = new HashSet(); agent.ProfilerRequestReceived += (object sender, EventArgs ctx) => diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/DebugInfo/LineNumberTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/DebugInfo/LineNumberTest.cs index 0acd4b9aeb7f..7900adaa3d94 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/DebugInfo/LineNumberTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/DebugInfo/LineNumberTest.cs @@ -32,7 +32,7 @@ public void CheckLinenumbers(string appName, string framework, string appAssembl var runner = new TestApplicationRunner(appName, framework, appAssembly, _output, commandLine: "--scenario 18"); runner.Environment.CustomEnvironmentVariables[EnvironmentVariables.DebugInfoEnabled] = "1"; - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); var expectedStack = new StackTrace( @@ -91,7 +91,7 @@ public void CheckNoLinenumbersIfDisabled(string appName, string framework, strin var runner = new TestApplicationRunner(appName, framework, appAssembly, _output, commandLine: "--scenario 18"); runner.Environment.CustomEnvironmentVariables[EnvironmentVariables.DebugInfoEnabled] = "0"; - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -114,7 +114,7 @@ public void CheckLineNumberAreDisabledByDefault(string appName, string framework { var runner = new TestApplicationRunner(appName, framework, appAssembly, _output, commandLine: "--scenario 18"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/Exceptions/ExceptionsTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/Exceptions/ExceptionsTest.cs index a9f5a09d44b5..bb8fffe46b3f 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/Exceptions/ExceptionsTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/Exceptions/ExceptionsTest.cs @@ -81,7 +81,7 @@ public void ThrowExceptionsInParallel(string appName, string framework, string a runner.Environment.SetVariable(EnvironmentVariables.ExceptionProfilerEnabled, "1"); runner.Environment.SetVariable(EnvironmentVariables.ExceptionSampleLimit, "10000"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -101,7 +101,7 @@ public void ThrowExceptionsInParallel(string appName, string framework, string a foreach (var file in Directory.GetFiles(runner.Environment.LogDir)) { - _output.WriteLine($"Log file: {file}"); + runner.XUnitLogger.WriteLine($"Log file: {file}"); } var logFile = Directory.GetFiles(runner.Environment.LogDir) @@ -201,7 +201,7 @@ public void Sampling(string appName, string framework, string appAssembly) runner.Environment.SetVariable(EnvironmentVariables.ExceptionProfilerEnabled, "1"); runner.Environment.SetVariable(EnvironmentVariables.ExceptionSampleLimit, "100"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); agent.NbCallsOnProfilingEndpoint.Should().BeGreaterThan(0); @@ -255,7 +255,7 @@ public void ExceptionProfilerIsEnabledByDefault(string appName, string framework runner.Environment.SetVariable(EnvironmentVariables.GarbageCollectionProfilerEnabled, "0"); runner.Environment.SetVariable(EnvironmentVariables.ContentionProfilerEnabled, "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -278,7 +278,7 @@ public void ExplicitlyDisableExceptionProfiler(string appName, string framework, EnvironmentHelper.DisableDefaultProfilers(runner); runner.Environment.SetVariable(EnvironmentVariables.WallTimeProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -301,7 +301,7 @@ public void MeasureExceptions(string appName, string framework, string appAssemb EnvironmentHelper.DisableDefaultProfilers(runner); runner.Environment.SetVariable(EnvironmentVariables.ExceptionProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -314,10 +314,11 @@ public void MeasureExceptions(string appName, string framework, string appAssemb Dictionary profiledExceptions = GetProfiledExceptions(exceptionSamples); Dictionary realExceptions = GetRealExceptions(runner.ProcessOutput); - _output.WriteLine("Comparing exceptions"); - _output.WriteLine("-------------------------------------------------------"); - _output.WriteLine(" Count Type"); - _output.WriteLine("-------------------------------------------------------"); + var logger = runner.XUnitLogger; + logger.WriteLine("Comparing exceptions"); + logger.WriteLine("-------------------------------------------------------"); + logger.WriteLine(" Count Type"); + logger.WriteLine("-------------------------------------------------------"); foreach (var exception in profiledExceptions) { var exceptionCount = exception.Value; @@ -337,7 +338,7 @@ public void MeasureExceptions(string appName, string framework, string appAssemb StringBuilder builder = new StringBuilder(); builder.AppendLine($"{exceptionCount,11} {type}"); builder.AppendLine($"{stats,11}"); - _output.WriteLine(builder.ToString()); + logger.WriteLine(builder.ToString()); } } @@ -521,7 +522,7 @@ private void CheckExceptionProfiles(TestApplicationRunner runner, bool withTimes new StackFrame("|lm:Samples.ExceptionGenerator |ns:Samples.ExceptionGenerator |ct:ExceptionsProfilerTestScenario |cg: |fn:Run |fg: |sg:()"), new StackFrame("|lm:Samples.ExceptionGenerator |ns:Samples.ExceptionGenerator |ct:Program |cg: |fn:Main |fg: |sg:(string[] args)")); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/GarbageCollections/GarbageCollectorCpuTimeTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/GarbageCollections/GarbageCollectorCpuTimeTest.cs index 6d0db5bca233..9843554340e7 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/GarbageCollections/GarbageCollectorCpuTimeTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/GarbageCollections/GarbageCollectorCpuTimeTest.cs @@ -41,7 +41,7 @@ public void CheckCpuTimeForGcThreadsIsReported(string appName, string framework, // Enable GC Server runner.Environment.SetVariable("DOTNET_gcServer", "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.True(agent.NbCallsOnProfilingEndpoint > 0); @@ -64,7 +64,7 @@ public void CheckNoGcSampleIfCpuProfilingIsDisabled(string appName, string frame runner.Environment.SetVariable(EnvironmentVariables.CpuProfilerEnabled, "0"); runner.Environment.SetVariable("DOTNET_gcServer", "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.True(agent.NbCallsOnProfilingEndpoint > 0); @@ -83,7 +83,7 @@ public void CheckNoGcSampleIfNotGcServerSetToOne(string appName, string framewor // disable gc server runner.Environment.SetVariable("DOTNET_gcServer", "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.True(agent.NbCallsOnProfilingEndpoint > 0); @@ -102,7 +102,7 @@ public void CheckNoGcSampleIfFeatureDeactivated(string appName, string framework // disable gc server runner.Environment.SetVariable("DOTNET_gcServer", "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.True(agent.NbCallsOnProfilingEndpoint > 0); @@ -121,7 +121,7 @@ public void CheckNoGcSampleIfFeatureDeactivatedByDefault(string appName, string // disable gc server runner.Environment.SetVariable("DOTNET_gcServer", "0"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.True(agent.NbCallsOnProfilingEndpoint > 0); @@ -140,7 +140,7 @@ public void CheckFeatureIsDisabledIfNetCoreVersionIsLessThan_5(string appName, s // enable gc server runner.Environment.SetVariable("COMPlus_gcServer", "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.True(agent.NbCallsOnProfilingEndpoint > 0); @@ -159,7 +159,7 @@ public void CheckFeatureIsDisabledIfDotNetFramework(string appName, string frame // enable gc server runner.Environment.SetVariable("COMPlus_gcServer", "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.True(agent.NbCallsOnProfilingEndpoint > 0); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/SignalHandlerTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/SignalHandlerTest.cs index ce3c02daef5e..f89b3718e3aa 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/SignalHandlerTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/SignalHandlerTest.cs @@ -38,7 +38,7 @@ public void CheckSignalHandlerIsInstalledOnce(string appName, string framework, runner.Environment.SetVariable(EnvironmentVariables.ExceptionProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/TimerCreateCpuProfilerTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/TimerCreateCpuProfilerTest.cs index 953f21091267..a64209c0e367 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/TimerCreateCpuProfilerTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/TimerCreateCpuProfilerTest.cs @@ -61,7 +61,7 @@ public void CheckCpuSamples(string appName, string framework, string appAssembly runner.Environment.SetVariable(EnvironmentVariables.CpuProfilerType, "TimerCreate"); runner.Environment.SetVariable(EnvironmentVariables.CpuProfilingInterval, samplingInterval); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -85,7 +85,7 @@ public void CheckCpuSamplesForDefaultSampingInterval(string appName, string fram runner.Environment.SetVariable(EnvironmentVariables.CpuProfilerType, "TimerCreate"); runner.Environment.SetVariable(EnvironmentVariables.CpuProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/WrapperLibraryTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/WrapperLibraryTest.cs index 38cf62bc65cb..014497e1b6ba 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/WrapperLibraryTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/LinuxOnly/WrapperLibraryTest.cs @@ -33,7 +33,7 @@ public void EnsureProfilerIsDeactivatedIfNoWrapperLibrary(string appName, string // Overwrite the one set in EnvironmentHelper runner.Environment.SetVariable("LD_PRELOAD", string.Empty); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); @@ -53,7 +53,7 @@ public void EnsureProfilerIsDeactivatedIfWrongPathToWrapperLibrary(string appNam // Overwrite the one set in EnvironmentHelper runner.Environment.SetVariable("LD_PRELOAD", "/mnt/does_not_exist/Datadog.Linux.Wrapper.x64.so"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); var logFile = Directory.GetFiles(runner.Environment.LogDir) @@ -72,7 +72,7 @@ public void EnsureAppDoesNotCrashIfProfilerDeactivateAndTracerActivated(string a // Overwrite the one set in EnvironmentHelper runner.Environment.SetVariable("LD_PRELOAD", string.Empty); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); var logFile = Directory.GetFiles(runner.Environment.LogDir) @@ -95,54 +95,55 @@ public void GenerateDumpIfDbgRequested(string appName, string framework, string using var processHelper = runner.LaunchProcess(); var success = runner.WaitForExitOrCaptureDump(processHelper.Process, milliseconds: 30_000); - if (!success) { + var logger = runner.XUnitLogger; + // Note: we don't drain because the process hasn't exited, but it means the output may be incomplete - _output.WriteLine("Standard output:"); - _output.WriteLine(processHelper.StandardOutput); + logger.WriteLine("Standard output:"); + logger.WriteLine(processHelper.StandardOutput); var pid = processHelper.Process.Id; var status = File.ReadAllText($"/proc/{pid}/status"); - _output.WriteLine("Process status:"); - _output.WriteLine(status); + logger.WriteLine("Process status:"); + logger.WriteLine(status); - _output.WriteLine("************************"); + logger.WriteLine("************************"); // Enumerating status for each thread var threads = Directory.GetDirectories($"/proc/{pid}/task"); foreach (var thread in threads) { - _output.WriteLine($"**** {thread}:"); + logger.WriteLine($"**** {thread}:"); try { var threadStatus = File.ReadAllText($"{thread}/status"); - _output.WriteLine(threadStatus); + logger.WriteLine(threadStatus); } catch (Exception ex) { - _output.WriteLine(ex.Message); + logger.WriteLine(ex.Message); } } - _output.WriteLine("************************"); + logger.WriteLine("************************"); var processes = Process.GetProcesses(); - _output.WriteLine("Processes:"); + logger.WriteLine("Processes:"); foreach (var process in processes) { - _output.WriteLine($"Process: {process.ProcessName} ({process.Id})"); + logger.WriteLine($"Process: {process.ProcessName} ({process.Id})"); if (process.ProcessName == "createdump") { var testBaseOutputDir = runner.Environment.GetTestOutputPath(); - process.GetAllThreadsStack(testBaseOutputDir, _output); - process.TakeMemoryDump(testBaseOutputDir, _output); + process.GetAllThreadsStack(testBaseOutputDir, logger); + process.TakeMemoryDump(testBaseOutputDir, logger); } } } diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/LiveObjects/LiveObjectsProfilerTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/LiveObjects/LiveObjectsProfilerTest.cs index 471fabf08a92..13ced9063545 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/LiveObjects/LiveObjectsProfilerTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/LiveObjects/LiveObjectsProfilerTest.cs @@ -32,7 +32,7 @@ public void ShouldGetGarbageCollectionSamples(string appName, string framework, runner.Environment.SetVariable(EnvironmentVariables.LiveHeapProfilerEnabled, "1"); // only garbage collection profiler enabled so should only see the 1 related value per sample + Generation label - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.True(agent.NbCallsOnProfilingEndpoint > 0); Assert.True(CheckSamplesAreLiveObjects(runner.Environment.PprofDir)); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/Logger/NativeLogger.cs b/profiler/test/Datadog.Profiler.IntegrationTests/Logger/NativeLogger.cs index 732a6c0d1e24..c7a67e45973a 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/Logger/NativeLogger.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/Logger/NativeLogger.cs @@ -30,7 +30,7 @@ public void EnsureBackCompatibilityForLogDirectory(string appName, string framew var deprecatedLogPath = Path.Combine(Path.GetTempPath(), "deprecated", System.Environment.ProcessId.ToString()); runner.Environment.SetVariable("DD_PROFILING_LOG_DIR", deprecatedLogPath); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/MetricsTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/MetricsTest.cs index d4a5b585a80a..5aef6d5c66f7 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/MetricsTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/MetricsTest.cs @@ -33,7 +33,7 @@ public void CheckMetrics(string appName, string framework, string appAssembly) runner.Environment.SetVariable(EnvironmentVariables.GarbageCollectionProfilerEnabled, "0"); runner.Environment.SetVariable(EnvironmentVariables.ContentionProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); bool hasMetrics = false; agent.ProfilerRequestReceived += (object sender, EventArgs ctx) => { diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/Signature/SignatureTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/Signature/SignatureTest.cs index 0b1ef254e1e4..3cb031fbeef5 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/Signature/SignatureTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/Signature/SignatureTest.cs @@ -29,7 +29,7 @@ public void ValidateSignatures(string appName, string framework, string appAssem runner.Environment.SetVariable(EnvironmentVariables.TimestampsAsLabelEnabled, "0"); runner.Environment.SetVariable(EnvironmentVariables.ExceptionProfilerEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.True(agent.NbCallsOnProfilingEndpoint > 0); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/SingleStepInstrumentation/SingleStepInstrumentationTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/SingleStepInstrumentation/SingleStepInstrumentationTest.cs index 0bfc53ec43be..49a37021fc04 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/SingleStepInstrumentation/SingleStepInstrumentationTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/SingleStepInstrumentation/SingleStepInstrumentationTest.cs @@ -32,7 +32,7 @@ public void ManualAndProfilingEnvVarNotSet(string appName, string framework, str { var runner = new TestApplicationRunner(appName, framework, appAssembly, _output, commandLine: "--scenario 1", enableProfiler: false); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); List series = []; agent.TelemetryMetricsRequestReceived += (_, ctx) => @@ -53,7 +53,7 @@ public void ManualAndProfilingEnvVarTrue(string appName, string framework, strin { var runner = new TestApplicationRunner(appName, framework, appAssembly, _output, commandLine: "--scenario 1", enableProfiler: true); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); List series = []; agent.TelemetryMetricsRequestReceived += (_, ctx) => @@ -75,7 +75,7 @@ public void ManualAndProfilingEnvVarFalse(string appName, string framework, stri var runner = new TestApplicationRunner(appName, framework, appAssembly, _output, commandLine: "--scenario 1", enableProfiler: false); runner.Environment.SetVariable(EnvironmentVariables.ProfilerEnabled, "false"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); List series = []; agent.TelemetryMetricsRequestReceived += (_, ctx) => @@ -101,7 +101,7 @@ public void SsiAndProfilingEnvVarTrue(string appName, string framework, string a runner.Environment.SetVariable(EnvironmentVariables.SsiTelemetryEnabled, "1"); runner.Environment.SetVariable(EnvironmentVariables.TelemetryToDiskEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); agent.NbCallsOnProfilingEndpoint.Should().BeGreaterThan(0); @@ -129,7 +129,7 @@ public void SsiAndProfilingEnvVarFalse(string appName, string framework, string runner.Environment.SetVariable(EnvironmentVariables.SsiTelemetryEnabled, "1"); runner.Environment.SetVariable(EnvironmentVariables.TelemetryToDiskEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); agent.NbCallsOnProfilingEndpoint.Should().Be(0); @@ -146,7 +146,7 @@ public void CheckSsiAndProfilingEnvVarSetToFalse(string appName, string framewor runner.Environment.SetVariable(EnvironmentVariables.SsiDeployed, "tracer"); runner.Environment.SetVariable(EnvironmentVariables.ProfilerEnabled, "false"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); List series = []; agent.TelemetryMetricsRequestReceived += (_, ctx) => diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/CpuLimitTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/CpuLimitTest.cs index 476471291d1f..103a54da91ee 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/CpuLimitTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/CpuLimitTest.cs @@ -33,12 +33,12 @@ public void CheckCpuLimit(string appName, string framework, string appAssembly) if (double.TryParse(rawCpuLimit, out var cpuLimit) && cpuLimit < 1) { - _output.WriteLine("CPU limit set to <1 CPU, expecting profiler to be disabled"); + runner.XUnitLogger.WriteLine("CPU limit set to <1 CPU, expecting profiler to be disabled"); agent.NbCallsOnProfilingEndpoint.Should().Be(0); } else { - _output.WriteLine("CPU limit set to >=1 CPU or not set, expecting profiler to be enabled"); + runner.XUnitLogger.WriteLine("CPU limit set to >=1 CPU or not set, expecting profiler to be enabled"); agent.NbCallsOnProfilingEndpoint.Should().BeGreaterThan(0); } } diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/SmokeTestRunner.cs b/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/SmokeTestRunner.cs index 5e24bdf25a8d..1f973fc95787 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/SmokeTestRunner.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/SmokeTests/SmokeTestRunner.cs @@ -39,13 +39,15 @@ public SmokeTestRunner( ITestOutputHelper output, TransportType transportType = TransportType.Http) { - _output = output; _transportType = transportType; _testApplicationRunner = new TestApplicationRunner(appName, framework, appAssembly, output, commandLine); + _output = _testApplicationRunner.XUnitLogger; } public int MinimumExpectedNbPprofFiles { get; set; } = 2; + public ITestOutputHelper XUnitLogger => _output; + internal EnvironmentHelper EnvironmentHelper { get => _testApplicationRunner.Environment; diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/Threads/ThreadLifetimeProviderTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/Threads/ThreadLifetimeProviderTest.cs index 569e0327f030..aeb2588d2aa9 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/Threads/ThreadLifetimeProviderTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/Threads/ThreadLifetimeProviderTest.cs @@ -34,7 +34,7 @@ public void ShouldGetThreadLifetimeSamples(string appName, string framework, str runner.Environment.SetVariable(EnvironmentVariables.ThreadLifetimeEnabled, "1"); // only thread lifetime profiler is enabled so should only see the corresponding samples - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.True(agent.NbCallsOnProfilingEndpoint > 0); Assert.True(CheckSamplesAreThreadTimeline(runner.Environment.PprofDir)); @@ -48,7 +48,7 @@ public void ShouldNotGetThreadLifetimeSamplesByDefault(string appName, string fr EnvironmentHelper.DisableDefaultProfilers(runner); // only thread lifetime profiler is enabled so should only see the corresponding samples - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.False(agent.NbCallsOnProfilingEndpoint > 0); Assert.False(CheckSamplesAreThreadTimeline(runner.Environment.PprofDir)); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/Timeline/TimelineTest.cs b/profiler/test/Datadog.Profiler.IntegrationTests/Timeline/TimelineTest.cs index ab64d212d6a1..6da489442797 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/Timeline/TimelineTest.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/Timeline/TimelineTest.cs @@ -34,7 +34,7 @@ public void CheckTimestampAsLabel(string appName, string framework, string appAs runner.Environment.SetVariable(EnvironmentVariables.GarbageCollectionProfilerEnabled, "1"); // TODO: add any new profiler to ensure that all are setting timestamps as label - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); Assert.True(agent.NbCallsOnProfilingEndpoint > 0); Assert.True(CheckTimestampsAsLabelForAllSamples(runner.Environment.PprofDir)); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/EtwEventsTests.cs b/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/EtwEventsTests.cs index f35f15c32b6e..a8074acd0f26 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/EtwEventsTests.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/EtwEventsTests.cs @@ -31,7 +31,7 @@ public void CheckErrorWhenNoAgentIsAvailable(string appName, string framework, s // Overwrite the one set in EnvironmentHelper runner.Environment.SetVariable(EnvironmentVariables.EtwEnabled, "1"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent); diff --git a/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/NamedPipeTestcs.cs b/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/NamedPipeTestcs.cs index 3ac00f50f768..4d47aa468b72 100644 --- a/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/NamedPipeTestcs.cs +++ b/profiler/test/Datadog.Profiler.IntegrationTests/WindowsOnly/NamedPipeTestcs.cs @@ -44,7 +44,7 @@ public void CheckExporterDoesUsePipeNameEvenIfItDoesNotExist(string appName, str // Overwrite the one set in EnvironmentHelper runner.Environment.SetVariable(EnvironmentVariables.NamedPipeName, "ForSureThisPipeDoesNotExist__I_Hope"); - using var agent = MockDatadogAgent.CreateHttpAgent(_output); + using var agent = MockDatadogAgent.CreateHttpAgent(runner.XUnitLogger); runner.Run(agent);