From 27153604988f61322719336a78e1c36b64be9627 Mon Sep 17 00:00:00 2001 From: NachoEchevarria Date: Fri, 19 Dec 2025 17:07:34 +0100 Subject: [PATCH 1/2] retry mechanism when checking for the telemetry echo log file --- .../InstrumentationTests.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/InstrumentationTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/InstrumentationTests.cs index cb4c7d5a3cdd..33afec35e3ab 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/InstrumentationTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/InstrumentationTests.cs @@ -10,6 +10,7 @@ using System.Runtime.CompilerServices; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using Datadog.Trace.Configuration; using Datadog.Trace.TestHelpers; @@ -798,7 +799,18 @@ private void AssertNativeLoaderLogContainsString(string logDir, string requiredL private void AssertHasExpectedTelemetry(string echoLogFileName, ProcessResult processResult, string pointsJson, string injectResult, string injectResultReason, string injectResultClass) { using var s = new AssertionScope(); - File.Exists(echoLogFileName).Should().BeTrue(); + + // Wait for the telemetry echo file to be written (with timeout) + // The telemetry forwarder may write the file asynchronously after process exit + var fileWaitTimeout = TimeSpan.FromSeconds(10); + var fileWaitStart = DateTime.UtcNow; + while (!File.Exists(echoLogFileName) && (DateTime.UtcNow - fileWaitStart) < fileWaitTimeout) + { + Thread.Sleep(100); + } + + File.Exists(echoLogFileName).Should().BeTrue($"Telemetry echo file should exist at {echoLogFileName} within {fileWaitTimeout.TotalSeconds} seconds"); + var echoLogContent = File.ReadAllText(echoLogFileName); s.AddReportable(echoLogFileName, echoLogContent); From 93289817c2fbd765ece76a0d5650b8e0dc84c317 Mon Sep 17 00:00:00 2001 From: NachoEchevarria Date: Fri, 26 Dec 2025 12:54:16 +0100 Subject: [PATCH 2/2] Make async --- .../InstrumentationTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/InstrumentationTests.cs b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/InstrumentationTests.cs index 33afec35e3ab..51346d7b6e14 100644 --- a/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/InstrumentationTests.cs +++ b/tracer/test/Datadog.Trace.ClrProfiler.IntegrationTests/InstrumentationTests.cs @@ -433,7 +433,7 @@ public async Task OnEolFrameworkInSsi_WhenForwarderPathExists_CallsForwarderWith "name": "library_entrypoint.abort.runtime" }] """; - AssertHasExpectedTelemetry(logFileName, processResult, pointsJson, "abort", ".NET Core 3.0 or lower", "incompatible_runtime"); + await AssertHasExpectedTelemetry(logFileName, processResult, pointsJson, "abort", ".NET Core 3.0 or lower", "incompatible_runtime"); } [SkippableFact] @@ -464,7 +464,7 @@ public async Task OnEolFrameworkInSsi_WhenOverriden_CallsForwarderWithExpectedTe "tags": ["injection_forced:true"] }] """; - AssertHasExpectedTelemetry(logFileName, processResult, pointsJson, "success", "Force instrumentation enabled, incompatible runtime, .NET Core 3.0 or lower", "success_forced"); + await AssertHasExpectedTelemetry(logFileName, processResult, pointsJson, "success", "Force instrumentation enabled, incompatible runtime, .NET Core 3.0 or lower", "success_forced"); } #endif @@ -503,7 +503,7 @@ public async Task OnPreviewFrameworkInSsi_CallsForwarderWithExpectedTelemetry() "tags": ["injection_forced:true"] }] """; - AssertHasExpectedTelemetry(logFileName, processResult, pointsJson, "success", "Force instrumentation enabled, incompatible runtime, .NET 10 or higher", "success_forced"); + await AssertHasExpectedTelemetry(logFileName, processResult, pointsJson, "success", "Force instrumentation enabled, incompatible runtime, .NET 10 or higher", "success_forced"); } [SkippableFact] @@ -536,7 +536,7 @@ public async Task OnPreviewFrameworkInSsi_WhenForwarderPathExists_CallsForwarder "name": "library_entrypoint.abort.runtime" }] """; - AssertHasExpectedTelemetry(logFileName, processResult, pointsJson, "abort", ".NET 10 or higher", "incompatible_runtime"); + await AssertHasExpectedTelemetry(logFileName, processResult, pointsJson, "abort", ".NET 10 or higher", "incompatible_runtime"); } [SkippableFact] @@ -593,7 +593,7 @@ public async Task OnSupportedFrameworkInSsi_CallsForwarderWithExpectedTelemetry( "tags": ["injection_forced:false"] }] """; - AssertHasExpectedTelemetry(logFileName, processResult, pointsJson, "success", "Successfully configured automatic instrumentation", "success"); + await AssertHasExpectedTelemetry(logFileName, processResult, pointsJson, "success", "Successfully configured automatic instrumentation", "success"); } [SkippableFact] @@ -796,7 +796,7 @@ private void AssertNativeLoaderLogContainsString(string logDir, string requiredL nativeLoaderLogFiles.Should().Contain(log => log.Contains(requiredLog)); } - private void AssertHasExpectedTelemetry(string echoLogFileName, ProcessResult processResult, string pointsJson, string injectResult, string injectResultReason, string injectResultClass) + private async Task AssertHasExpectedTelemetry(string echoLogFileName, ProcessResult processResult, string pointsJson, string injectResult, string injectResultReason, string injectResultClass) { using var s = new AssertionScope(); @@ -806,7 +806,7 @@ private void AssertHasExpectedTelemetry(string echoLogFileName, ProcessResult pr var fileWaitStart = DateTime.UtcNow; while (!File.Exists(echoLogFileName) && (DateTime.UtcNow - fileWaitStart) < fileWaitTimeout) { - Thread.Sleep(100); + await Task.Delay(100); } File.Exists(echoLogFileName).Should().BeTrue($"Telemetry echo file should exist at {echoLogFileName} within {fileWaitTimeout.TotalSeconds} seconds");