You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
make DD_DOTNET_TRACER_HOME optional in managed loader (#7568)
~_This PR is stacked on #7594. Merge that PR first._~
## Summary of changes
Make `DD_DOTNET_TRACER_HOME` optional. If not set, try to figure out the
path from `COR_PROFILER_PATH`/`CORECLR_PROFILER_PATH` and friends.
## Reason for change
One less env var for users to set manually. Easier onboarding, less
error-prone.
I recently worked on an escalation where `DD_DOTNET_TRACER_HOME` was set
to the wrong path so the tracer was not loading.
## Implementation details
The implementation makes `DD_DOTNET_TRACER_HOME` optional by adding
fallback logic to derive the tracer home path from the profiler path
environment variables:
1. **New method `GetTracerHomePath`** (`Startup.cs:150-178`):
- First checks for explicit `DD_DOTNET_TRACER_HOME` setting (preserves
backward compatibility)
- Falls back to computing the path from architecture-specific profiler
path env vars (e.g., `CORECLR_PROFILER_PATH_64`, `COR_PROFILER_PATH_64`)
- If not found, tries the generic profiler path env var (e.g.,
`CORECLR_PROFILER_PATH`, `COR_PROFILER_PATH`)
2. **New method `ComputeTracerHomePathFromProfilerPath`**
(`Startup.cs:180-218`):
- Takes a profiler path like
`C:\tracer\win-x64\Datadog.Trace.ClrProfiler.Native.dll`
- Extracts the parent directory
- If the parent directory name matches a known architecture folder
(e.g., `win-x64`, `linux-arm64`, `osx`), goes up one more level
- Returns the computed tracer home path
3. **Platform-specific helper methods**:
- `GetProfilerPathEnvVarNameForArch()`: Returns the
architecture-specific env var name (`CORECLR_PROFILER_PATH_64` on .NET
Core x64, `COR_PROFILER_PATH_32` on .NET Framework x86, etc.)
- `GetProfilerPathEnvVarNameFallback()`: Returns the generic env var
name (`CORECLR_PROFILER_PATH` or `COR_PROFILER_PATH`)
4. **Architecture directory detection**:
- Maintains a `HashSet<string>` of known architecture directories
(`win-x64`, `win-x86`, `linux-x64`, `linux-arm64`, etc)
## Test coverage
**Unit tests**
(`tracer/test/Datadog.Trace.Tests/ClrProfiler/Managed/Loader/`):
- Environment variable reading and fallback logic
(`StartupNetCoreTests.cs`, `StartupNetFrameworkTests.cs`)
- `GetTracerHomePath()` with explicit `DD_DOTNET_TRACER_HOME`
(with/without whitespace)
- `GetTracerHomePath()` with architecture-specific profiler path
fallback
- `GetTracerHomePath()` with generic profiler path fallback
- `ComputeTracerHomePathFromProfilerPath()` with all architecture
directories
- Edge cases: empty values, whitespace, missing variables, null handling
**Integration tests**:
- Added `WhenOmittingTracerHome_InstrumentsApp()` test in
`InstrumentationTests.cs` that explicitly omits `DD_DOTNET_TRACER_HOME`
and verifies instrumentation works via fallback logic
- Modified all smoke tests (`SmokeTests/SmokeTestBase.cs`) to omit
`DD_DOTNET_TRACER_HOME` by default, providing comprehensive real-world
validation of the fallback behavior across multiple regression scenarios
## Other details
<!-- Fixes #{issue} -->
⚠️ Based on #7567, which was originally [generated by OpenAI
Codex](https://chatgpt.com/codex/tasks/task_b_68d59245fcec832180db94dd256130ba),
but I made substantial changes to clean up and refactor.
<!-- ⚠️ Note:
Where possible, please obtain 2 approvals prior to merging. Unless
CODEOWNERS specifies otherwise, for external teams it is typically best
to have one review from a team member, and one review from apm-dotnet.
Trivial changes do not require 2 reviews.
MergeQueue is NOT enabled in this repository. If you have write access
to the repo, the PR has 1-2 approvals (see above), and all of the
required checks have passed, you can use the Squash and Merge button to
merge the PR. If you don't have write access, or you need help, reach
out in the #apm-dotnet channel in Slack.
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>
// DD_DOTNET_TRACER_HOME was not set and automatic detection from profiler path failed
86
+
StartupLogger.Log("{0} is not set and the tracer home directory could not be determined automatically. Datadog SDK will be disabled. To resolve this issue, set environment variable {0}.",TracerHomePathKey);
87
+
}
88
+
else
89
+
{
90
+
// DD_DOTNET_TRACER_HOME was set but resulted in null (shouldn't happen, but just in case)
91
+
StartupLogger.Log("{0} is set to '{1}' but could not be used. Datadog SDK will be disabled.",TracerHomePathKey,explicitTracerHome);
0 commit comments