Skip to content

Conversation

@zacharycmontoya
Copy link
Contributor

Goal: Use DD_DOTNET_TRACER_HOME to locate both definition json file and the managed assemblies for the CLR automatic instrumentation. This eliminates the need for the separate DD_INTEGRATIONS environment variable and reduce the number of non-profiler environment variables to 1.

This PR does the following:

  1. Remove DD_INTEGRATIONS from the Windows MSI.
  2. If DD_INTEGRATIONS is undefined -- the new default case -- load the integrations file specified at $DD_DOTNET_TRACER_HOME/integrations.json
  3. If DD_DOTNET_TRACER_HOME is undefined -- which may occur when upgrading the profiler to 1.8.0+ -- infer the location of the managed assemblies on disk from the DD_INTEGRATIONS variable.

@DataDog/apm-dotnet

@zacharycmontoya zacharycmontoya added area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) area:installers labels Dec 6, 2019
@zacharycmontoya zacharycmontoya added this to the 1.11.0 milestone Dec 6, 2019
@zacharycmontoya zacharycmontoya self-assigned this Dec 6, 2019
@zacharycmontoya zacharycmontoya added the status:work-in-progress Actively worked on. If this is a PR, no review needed yet. WIP. label Dec 6, 2019
@zacharycmontoya zacharycmontoya marked this pull request as ready for review December 6, 2019 21:19
@zacharycmontoya zacharycmontoya requested a review from a team as a code owner December 6, 2019 21:19
@zacharycmontoya
Copy link
Contributor Author

Opening for review to get automatic CI. Will remove the status:work-in-progress label when it's truly ready. Currently missing is my good regression test and the actual changes in cor_profiler.cpp to do the fallback for missing DD_INTEGRATIONS variable.

… is set but not DD_DOTNET_TRACER_HOME. No crash, but no instrumentation.
…uild variable. For every test project, copy the managed profiler assets into the profiler directory, to simulate the customer scenario.
…ts. This will help later with this PR.

Fix integration_loader_test
…we pass DD_DOTNET_TRACER_HOME in CI. Will modify this...
@zacharycmontoya zacharycmontoya force-pushed the zach/feature/remove_dd_integrations_env branch from 00cfba1 to 28e4412 Compare December 6, 2019 21:25
…ied by the test case, and edit MissingDotnetTracerHomeEnvTest to remove DD_DOTNET_TRACER_HOME
…nd the managed assemblies on-disk when DD_DOTNET_TRACER_HOME is not set but DD_INTEGRATIONS is still set.
…S) when the CI returns the empty string for DD_DOTNET_TRACER_HOME instead of null.
…k all the tests. They'll pass again when I fix the profiler to fill in the DD_INTEGRATIONS path from DD_DOTNET_TRACER_HOME.
…ionsFromEnvironment, in various environment variable scenarios.
</ItemGroup>

<Target Name="AfterBuildCopyManagedProfiler" AfterTargets="AfterBuild" Condition=" '$(LoadManagedProfilerFromProfilerDirectory)' == 'true'">
<Target Name="AfterBuildCopyManagedProfiler" AfterTargets="AfterBuild">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing $(LoadManagedProfilerFromProfilerDirectory) because it's not intuitive when to use it. For now, while wasteful, we'll always copy all managed binaries to a sample app's profiler-lib directory.


<ComponentGroup Id="EnvironmentVariables.Machine" Directory="INSTALLFOLDER">
<Component Id="EnvironmentVariablesShared" Guid="{C314A305-9C24-4E46-9ECF-E5EEA703BDEA}" Win64="$(var.Win64)">
<CreateFolder/>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing DD_INTEGRATIONS from our MSI since we can key off DD_DOTNET_TRACER_HOME. If for some reason the user has a different integrations.json file they want to use, they can manually set DD_INTEGRATIONS to prioritize that one.

"CORECLR_PROFILER": "{846F5F1C-F9AE-4B07-969E-05C26BC060D8}",
"CORECLR_PROFILER_PATH": "$(ProjectDir)$(OutputPath)profiler-lib\\Datadog.Trace.ClrProfiler.Native.dll",

"DD_INTEGRATIONS": "$(ProjectDir)$(OutputPath)profiler-lib\\integrations.json"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This very simple test program uses DD_INTEGRATIONS and doesn't use DD_DOTNET_TRACER_HOME to simulate a user who has upgraded the profiler without updating the environment variables.

var tracerHomeDirectory = Environment.GetEnvironmentVariable("DD_DOTNET_TRACER_HOME") ?? string.Empty;

var tracerHomeDirectory = Environment.GetEnvironmentVariable("DD_DOTNET_TRACER_HOME");
if (string.IsNullOrWhiteSpace(tracerHomeDirectory))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET Core: Fallback to DD_INTEGRATIONS if DD_DOTNET_TRACER_HOME was not set.


var tracerHomeDirectory = Environment.GetEnvironmentVariable("DD_DOTNET_TRACER_HOME") ?? string.Empty;
var tracerHomeDirectory = Environment.GetEnvironmentVariable("DD_DOTNET_TRACER_HOME");
if (string.IsNullOrWhiteSpace(tracerHomeDirectory))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET Framework: Fallback to DD_INTEGRATIONS if DD_DOTNET_TRACER_HOME was not set.

auto profiler_home_path =
GetEnvironmentValue(environment::profiler_home_path);

if (!profiler_home_path.empty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple fallback in the profiler: if DD_INTEGRATIONS was not set (as a result, it's the empty string), try DD_DOTNET_TRACER_HOME and if it is not empty, create an integrations.json path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We duplicate this logic in integration_loader.cpp just so we can raise an immediate error immediately here if the environment variables don't look right. Also, for testing purposes, it's much easier to do all of the environment variable processing again in LoadIntegrationsFromEnvironment so we can unit test it.

@zacharycmontoya zacharycmontoya removed the status:work-in-progress Actively worked on. If this is a PR, no review needed yet. WIP. label Dec 7, 2019
GetEnvironmentValue(environment::profiler_home_path);

if (!profiler_home_path.empty()) {
const auto fallback_integration_path = std::filesystem::path(profiler_home_path) / "integrations.json";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use std::filesystem unless we update to a newer build system on Linux.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started working on updating the Linux build a few months ago. It's on branch lpimentel/update-linux-build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this PR, which solution would you prefer:

  1. Writing our own routine that does simple path appending (you can see that work in some of the recent commits that I reverted)
  2. Updating the Linux build to take advantage of std::filesystem?

Copy link
Contributor Author

@zacharycmontoya zacharycmontoya Dec 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to update the build system right now, starting with the changes from your branch. I'll let you know how that goes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've spent all day trying to update the build system just to use the filesystem::append method but the result is that std::experimental::filesystem is available but not std::filesystem. I'm going to give up on this approach for the PR because I spent an entire day on this already. Unless you can help me take care of that, I will roll our own simple path function for this PR.

std::vector<WSTRING> GetEnvironmentValues(const WSTRING &name) {
return GetEnvironmentValues(name, L';');
std::vector<WSTRING> GetValues(const WSTRING &delimited_values) {
return GetValues(delimited_values, L';');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but this should really default to ; on Windows and : on Linux.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant to change the default behavior right now in this PR, but this would make for a good follow-up PR

@colin-higgins colin-higgins removed this from the 1.11.0-prerelease milestone Dec 10, 2019
@lucaspimentel lucaspimentel added this to the 1.11.1 milestone Dec 11, 2019
@bobuva bobuva modified the milestones: 1.11.1, 1.11.2 Jan 13, 2020
@zacharycmontoya zacharycmontoya removed this from the 1.11.2 milestone Jan 14, 2020
@lucaspimentel lucaspimentel requested a review from a team February 4, 2020 19:02
@lucaspimentel lucaspimentel added the type:enhancement Improvement to an existing feature label Feb 4, 2020
@lucaspimentel lucaspimentel marked this pull request as draft May 1, 2020 15:02
@lucaspimentel lucaspimentel added the status:work-in-progress Actively worked on. If this is a PR, no review needed yet. WIP. label May 1, 2020
@lucaspimentel lucaspimentel changed the title [ClrProfiler] Add fallback logic for DD_INTEGRATIONS and DD_DOTNET_TRACER_HOME Add fallback logic for DD_INTEGRATIONS and DD_DOTNET_TRACER_HOME May 1, 2020
@zacharycmontoya zacharycmontoya deleted the zach/feature/remove_dd_integrations_env branch January 29, 2021 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:installers area:native-library Automatic instrumentation native C++ code (Datadog.Trace.ClrProfiler.Native) status:work-in-progress Actively worked on. If this is a PR, no review needed yet. WIP. type:enhancement Improvement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants