Skip to content

Commit eb7beb6

Browse files
chojomokclaude
andcommitted
Add regression test for GH-7214 dd-dotnet bundle detection bug
TracingWithBundle is exposed as internal (not private) so ProcessBasicCheckTests can exercise it directly. No behavior change yet - DetectsBundleWhenLaunchedAsDotnetDll documents the still-open bug where `dotnet app.dll` launches (e.g. Azure App Service Linux) report the dotnet host as MainModule instead of the app directory, so the bundle check never matches. Other tests confirm existing working scenarios (matching MainModule, non-bundle rejection, Windows suffixes) are unaffected. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent fb753df commit eb7beb6

2 files changed

Lines changed: 99 additions & 1 deletion

File tree

tracer/src/Datadog.Trace.Tools.dd_dotnet/Checks/ProcessBasicCheck.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ private static bool ParseBooleanConfigurationValue(string value)
629629
or "1";
630630
}
631631

632-
private static bool TracingWithBundle(string?[] profilerPathValues, ProcessInfo process)
632+
internal static bool TracingWithBundle(string?[] profilerPathValues, ProcessInfo process)
633633
{
634634
// Get the file path of the main module (the .exe file)
635635
string? filePath = process.MainModule;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// <copyright file="ProcessBasicCheckTests.cs" company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
6+
using System.Collections.Generic;
7+
using Datadog.Trace.TestHelpers;
8+
using Datadog.Trace.Tools.dd_dotnet.Checks;
9+
using Datadog.Trace.Tools.Shared;
10+
using FluentAssertions;
11+
using Xunit;
12+
13+
namespace Datadog.Trace.Tools.dd_dotnet.Tests
14+
{
15+
public class ProcessBasicCheckTests
16+
{
17+
[Theory]
18+
[InlineData("/app/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so")]
19+
[InlineData("/app/datadog/linux-musl-x64/Datadog.Trace.ClrProfiler.Native.so")]
20+
[InlineData("/app/datadog/linux-arm64/Datadog.Trace.ClrProfiler.Native.so")]
21+
[InlineData("/app/datadog/linux-musl-arm64/Datadog.Trace.ClrProfiler.Native.so")]
22+
public void DetectsBundleWhenMainModuleDirectoryMatchesAppDirectory(string profilerPath)
23+
{
24+
var process = CreateProcessInfo(mainModuleDirectory: "/app");
25+
26+
var result = ProcessBasicCheck.TracingWithBundle(new[] { profilerPath }, process);
27+
28+
result.Should().BeTrue();
29+
}
30+
31+
[SkippableTheory]
32+
[InlineData(@"\datadog\win-x64\Datadog.Trace.ClrProfiler.Native.dll")]
33+
[InlineData(@"\datadog\win-x86\Datadog.Trace.ClrProfiler.Native.dll")]
34+
public void DetectsBundleWhenMainModuleDirectoryMatchesAppDirectoryOnWindows(string bundleSuffix)
35+
{
36+
SkipOn.Platform(SkipOn.PlatformValue.Linux);
37+
SkipOn.Platform(SkipOn.PlatformValue.MacOs);
38+
39+
var process = CreateProcessInfo(mainModuleDirectory: @"C:\app");
40+
41+
var result = ProcessBasicCheck.TracingWithBundle(new[] { @"C:\app" + bundleSuffix }, process);
42+
43+
result.Should().BeTrue();
44+
}
45+
46+
[Fact]
47+
public void DetectsBundleWhenLaunchedAsDotnetDll()
48+
{
49+
// GH-7214: `dotnet app.dll` launches (e.g. Azure App Service Linux) report the
50+
// dotnet host as MainModule, not the app's own directory.
51+
var process = CreateProcessInfo(mainModuleDirectory: "/usr/share/dotnet");
52+
var profilerPath = "/app/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so";
53+
54+
var result = ProcessBasicCheck.TracingWithBundle(new[] { profilerPath }, process);
55+
56+
result.Should().BeTrue();
57+
}
58+
59+
[Theory]
60+
[InlineData(null)]
61+
[InlineData("/opt/datadog/Datadog.Trace.ClrProfiler.Native.so")]
62+
[InlineData("/app/datadog/linux-x64/Datadog.Tracer.Native.so")]
63+
public void DoesNotDetectBundleForNonBundlePaths(string profilerPath)
64+
{
65+
var process = CreateProcessInfo(mainModuleDirectory: "/app");
66+
67+
var result = ProcessBasicCheck.TracingWithBundle(new[] { profilerPath }, process);
68+
69+
result.Should().BeFalse();
70+
}
71+
72+
[Fact]
73+
public void DetectsBundleWhenAnyProfilerPathValueMatches()
74+
{
75+
var process = CreateProcessInfo(mainModuleDirectory: "/app");
76+
string[] profilerPathValues =
77+
{
78+
null,
79+
"/opt/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so",
80+
"/app/datadog/linux-x64/Datadog.Trace.ClrProfiler.Native.so"
81+
};
82+
83+
var result = ProcessBasicCheck.TracingWithBundle(profilerPathValues, process);
84+
85+
result.Should().BeTrue();
86+
}
87+
88+
private static ProcessInfo CreateProcessInfo(string mainModuleDirectory)
89+
{
90+
return new ProcessInfo(
91+
"app",
92+
1,
93+
new Dictionary<string, string>(),
94+
mainModule: $"{mainModuleDirectory}/app",
95+
modules: System.Array.Empty<string>());
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)