diff --git a/tracer/build/_build/Build.Steps.cs b/tracer/build/_build/Build.Steps.cs index 8f4140633d38..bb6a3d6b2acc 100644 --- a/tracer/build/_build/Build.Steps.cs +++ b/tracer/build/_build/Build.Steps.cs @@ -652,44 +652,40 @@ async Task DownloadWafVersion(string libddwafVersion = null, string uncompressFo Target CopyNativeFilesForTests => _ => _ .Unlisted() - .After(Clean) - .After(BuildTracerHome) + .After(Clean, BuildTracerHome) + .Before(RunIntegrationTests, RunManagedUnitTests) .Executes(() => { - foreach(var projectName in Projects.NativeFilesDependentTests) + // Copy the native files to all the test projects for simplicity. + var testProjects = Solution.GetProjects("*Tests") + .Where(p => p.SolutionFolder.Name == "test" + && p.Path.ToString().EndsWith(".csproj")); // exclude native test projects + foreach(var projectName in testProjects) { + Logger.Information("Copying native files for project {ProjectName}", projectName); var project = Solution.GetProject(projectName); - var testDir = project.Directory; + var testDir = project!.Directory; var frameworks = project.GetTargetFrameworks(); - var testBinFolder = testDir / "bin" / BuildConfiguration; - if (IsWin) + if (Framework is not null) { - foreach (var framework in frameworks) - { - var source = MonitoringHomeDirectory / $"win-{TargetPlatform}" / "datadog_profiling_ffi.dll"; - var dest = testBinFolder / framework / "LibDatadog.dll"; - CopyFile(source, dest, FileExistsPolicy.Overwrite); - } + frameworks = frameworks.Where(x=> x == Framework).ToList(); } - else if (IsLinux) + + var testBinFolder = testDir / "bin" / BuildConfiguration; + + var (ext, source) = Platform switch { - var (arch, ext) = GetUnixArchitectureAndExtension(); - var source = MonitoringHomeDirectory / arch / $"libdatadog_profiling.{ext}"; - foreach (var framework in frameworks) - { - var dest = testBinFolder / framework / $"LibDatadog.{ext}"; - CopyFile(source, dest, FileExistsPolicy.Overwrite); - } - } - else if (IsOsx) + PlatformFamily.Windows => ("dll", MonitoringHomeDirectory / $"win-{TargetPlatform}" / "datadog_profiling_ffi.dll"), + PlatformFamily.Linux => ("so", MonitoringHomeDirectory / GetUnixArchitectureAndExtension().Arch / "libdatadog_profiling.so"), + PlatformFamily.OSX => ("dylib", MonitoringHomeDirectory / "osx" / $"libdatadog_profiling.dylib"), + _ => throw new NotSupportedException($"Unsupported platform: {Platform}") + }; + + foreach (var framework in frameworks) { - var source = MonitoringHomeDirectory/ "osx" / $"libdatadog_profiling.dylib"; - foreach (var framework in frameworks) - { - var dest = testBinFolder / framework / $"LibDatadog.dylib"; - CopyFile(source, dest, FileExistsPolicy.Overwrite); - } + var dest = testBinFolder / framework / $"LibDatadog.{ext}"; + CopyFile(source, dest, FileExistsPolicy.Overwrite); } } }); diff --git a/tracer/build/_build/Projects.cs b/tracer/build/_build/Projects.cs index 4b9bd09ecfd7..f5993218f317 100644 --- a/tracer/build/_build/Projects.cs +++ b/tracer/build/_build/Projects.cs @@ -41,14 +41,6 @@ public static class Projects public const string DebuggerUnreferencedExternal = "Samples.Probes.Unreferenced.External"; public const string RazorPages = "Samples.AspNetCoreRazorPages"; - - public static readonly string[] NativeFilesDependentTests = { - AppSecUnitTests, - ClrProfilerManagedTests, - TraceIntegrationTests, - TraceTests, - DdTraceIntegrationTests - }; } public static class FileNames diff --git a/tracer/src/Datadog.Trace.Coverage.collector/DataCollectorLogger.cs b/tracer/src/Datadog.Trace.Coverage.collector/DataCollectorLogger.cs index 9c6cd1927a95..ae7f34280586 100644 --- a/tracer/src/Datadog.Trace.Coverage.collector/DataCollectorLogger.cs +++ b/tracer/src/Datadog.Trace.Coverage.collector/DataCollectorLogger.cs @@ -42,7 +42,7 @@ public DataCollectorLogger(DataCollectionLogger logger, DataCollectionContext co fileSizeLimitBytes: fileConfig.MaxLogFileSizeBytes, shared: true); - _datadogLogger = new DatadogSerilogLogger(loggerConfiguration.CreateLogger(), new NullLogRateLimiter(), fileConfig.LogDirectory); + _datadogLogger = new DatadogSerilogLogger(loggerConfiguration.CreateLogger(), new NullLogRateLimiter(), fileConfig); } } diff --git a/tracer/src/Datadog.Trace/Logging/Internal/Configuration/FileLoggingConfiguration.cs b/tracer/src/Datadog.Trace/Logging/Internal/Configuration/FileLoggingConfiguration.cs index 2fc16df62cd1..39420a3d419d 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/Configuration/FileLoggingConfiguration.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/Configuration/FileLoggingConfiguration.cs @@ -6,16 +6,11 @@ #nullable enable namespace Datadog.Trace.Logging.Internal.Configuration; -internal readonly struct FileLoggingConfiguration +internal class FileLoggingConfiguration(long maxLogFileSizeBytes, string logDirectory, int logFileRetentionDays) { - public readonly long MaxLogFileSizeBytes; - public readonly string LogDirectory; - public readonly int LogFileRetentionDays; + public long MaxLogFileSizeBytes { get; } = maxLogFileSizeBytes; - public FileLoggingConfiguration(long maxLogFileSizeBytes, string logDirectory, int logFileRetentionDays) - { - MaxLogFileSizeBytes = maxLogFileSizeBytes; - LogDirectory = logDirectory; - LogFileRetentionDays = logFileRetentionDays; - } + public string LogDirectory { get; } = logDirectory; + + public int LogFileRetentionDays { get; } = logFileRetentionDays; } diff --git a/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs b/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs index 6f5e01acd98d..beeec6fa0e9e 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/DatadogLoggingFactory.cs @@ -149,7 +149,7 @@ static bool Contains(string?[]? array, string toMatch) rateLimiter = new NullLogRateLimiter(); } - return new DatadogSerilogLogger(internalLogger, rateLimiter, config.File?.LogDirectory); + return new DatadogSerilogLogger(internalLogger, rateLimiter, config.File); } // Internal for testing diff --git a/tracer/src/Datadog.Trace/Logging/Internal/DatadogSerilogLogger.cs b/tracer/src/Datadog.Trace/Logging/Internal/DatadogSerilogLogger.cs index 2bcfd34c00da..d797eab68043 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/DatadogSerilogLogger.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/DatadogSerilogLogger.cs @@ -8,6 +8,7 @@ using System; using System.Runtime.CompilerServices; using System.Threading; +using Datadog.Trace.Logging.Internal.Configuration; using Datadog.Trace.Telemetry; using Datadog.Trace.Telemetry.Metrics; using Datadog.Trace.Vendors.Serilog; @@ -24,16 +25,16 @@ internal class DatadogSerilogLogger : IDatadogLogger private readonly ILogRateLimiter _rateLimiter; private ILogger _logger; - public DatadogSerilogLogger(ILogger logger, ILogRateLimiter rateLimiter, string? fileLogDirectory) + public DatadogSerilogLogger(ILogger logger, ILogRateLimiter rateLimiter, FileLoggingConfiguration? fileLoggingConfiguration) { _logger = logger; _rateLimiter = rateLimiter; - FileLogDirectory = fileLogDirectory; + FileLoggingConfiguration = fileLoggingConfiguration; } public static DatadogSerilogLogger NullLogger { get; } = new(SilentLogger.Instance, new NullLogRateLimiter(), null); - public string? FileLogDirectory { get; } + public FileLoggingConfiguration? FileLoggingConfiguration { get; } public bool IsEnabled(LogEventLevel level) => _logger.IsEnabled(level); diff --git a/tracer/src/Datadog.Trace/Logging/Internal/IDatadogLogger.cs b/tracer/src/Datadog.Trace/Logging/Internal/IDatadogLogger.cs index 48e50c86707e..09c6734d1cce 100644 --- a/tracer/src/Datadog.Trace/Logging/Internal/IDatadogLogger.cs +++ b/tracer/src/Datadog.Trace/Logging/Internal/IDatadogLogger.cs @@ -7,13 +7,14 @@ using System; using System.Runtime.CompilerServices; +using Datadog.Trace.Logging.Internal.Configuration; using Datadog.Trace.Vendors.Serilog.Events; namespace Datadog.Trace.Logging { internal interface IDatadogLogger { - public string? FileLogDirectory { get; } + public FileLoggingConfiguration? FileLoggingConfiguration { get; } bool IsEnabled(LogEventLevel level); diff --git a/tracer/src/Datadog.Trace/Logging/TracerFlare/TracerFlareManager.cs b/tracer/src/Datadog.Trace/Logging/TracerFlare/TracerFlareManager.cs index 2326090b88a3..c4294e5005bb 100644 --- a/tracer/src/Datadog.Trace/Logging/TracerFlare/TracerFlareManager.cs +++ b/tracer/src/Datadog.Trace/Logging/TracerFlare/TracerFlareManager.cs @@ -156,7 +156,7 @@ private async Task HandleTracerFlareInitiated(List HandleTracerFlareRequested(List