|
9 | 9 | using System.Linq;
|
10 | 10 | using System.Runtime.CompilerServices;
|
11 | 11 | using System.Text;
|
| 12 | +using System.Text.RegularExpressions; |
12 | 13 | using System.Threading.Tasks;
|
13 | 14 | using Datadog.Trace.Configuration;
|
14 | 15 | using Datadog.Trace.TestHelpers;
|
@@ -83,6 +84,7 @@ public async Task DoesNotInstrumentDotnetBuild()
|
83 | 84 | using var agent = EnvironmentHelper.GetMockAgent(useTelemetry: true);
|
84 | 85 |
|
85 | 86 | var logDir = await RunDotnet("new console -n instrumentation_test -o . --no-restore");
|
| 87 | + FixTfm(workingDir); |
86 | 88 | AssertNotInstrumented(agent, logDir);
|
87 | 89 |
|
88 | 90 | logDir = await RunDotnet("restore");
|
@@ -115,6 +117,7 @@ public async Task DoesNotInstrumentExcludedNames(string excludedProcess)
|
115 | 117 | using var agent = EnvironmentHelper.GetMockAgent(useTelemetry: true);
|
116 | 118 |
|
117 | 119 | var logDir = await RunDotnet($"new console -n {excludedProcess} -o . --no-restore");
|
| 120 | + FixTfm(workingDir); |
118 | 121 | AssertNotInstrumented(agent, logDir);
|
119 | 122 |
|
120 | 123 | var programCs = GetProgramCSThatMakesSpans();
|
@@ -153,7 +156,9 @@ public async Task DoesInstrumentAllowedProcesses(string allowedProcess)
|
153 | 156 | using var agent = EnvironmentHelper.GetMockAgent(useTelemetry: true);
|
154 | 157 |
|
155 | 158 | var logDir = await RunDotnet($"new console -n {allowedProcess} -o . --no-restore");
|
| 159 | + FixTfm(workingDir); |
156 | 160 | AssertNotInstrumented(agent, logDir);
|
| 161 | + |
157 | 162 | var programCs = GetProgramCSThatMakesSpans();
|
158 | 163 |
|
159 | 164 | File.WriteAllText(Path.Combine(workingDir, "Program.cs"), programCs);
|
@@ -594,7 +599,7 @@ private Task<string> RunDotnetCommand(string workingDirectory, MockTracerAgent m
|
594 | 599 | {
|
595 | 600 | // Disable .NET CLI telemetry to prevent extra HTTP spans
|
596 | 601 | SetEnvironmentVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");
|
597 |
| - return RunCommand(workingDirectory, mockTracerAgent, EnvironmentHelper.GetDotnetExe(), arguments); |
| 602 | + return RunCommand(workingDirectory, mockTracerAgent, "dotnet", arguments); |
598 | 603 | }
|
599 | 604 |
|
600 | 605 | private async Task<string> RunCommand(string workingDirectory, MockTracerAgent mockTracerAgent, string exe, string arguments = null)
|
@@ -758,6 +763,28 @@ private bool IsAllLoggingDisabledForBailout()
|
758 | 763 | return loggingDisabled;
|
759 | 764 | }
|
760 | 765 |
|
| 766 | + private void FixTfm(string workingDir) |
| 767 | + { |
| 768 | + // This is a hack because for _some_ reason, we can't set the -f flag in the Linux CI. |
| 769 | + // Force the project to target .NET 8 instead of whatever the SDK defaults to |
| 770 | + foreach (var projectFile in Directory.GetFiles(workingDir, "*.csproj")) |
| 771 | + { |
| 772 | + var projectContent = File.ReadAllText(projectFile); |
| 773 | + |
| 774 | + // Replace any target framework with the updated version |
| 775 | + // and add a langversion update to ensure we still compile |
| 776 | + var replacement = $""" |
| 777 | + <TargetFramework>{EnvironmentHelper.GetTargetFramework()}</TargetFramework> |
| 778 | + <LangVersion>latest</LangVersion> |
| 779 | + """; |
| 780 | + var updatedContent = Regex.Replace( |
| 781 | + projectContent, |
| 782 | + @"<TargetFramework>.+</TargetFramework>", |
| 783 | + replacement); |
| 784 | + File.WriteAllText(projectFile, updatedContent); |
| 785 | + } |
| 786 | + } |
| 787 | + |
761 | 788 | public class TelemetryReporterFixture : IDisposable
|
762 | 789 | {
|
763 | 790 | private readonly string _workingDir = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));
|
|
0 commit comments