Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a workaround for the dotnet runtime issue 77973 #3506

Merged
merged 9 commits into from
Dec 13, 2022
3 changes: 0 additions & 3 deletions tracer/build/_build/docker/smoke.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ ENV DD_PROFILING_LOG_DIR=/var/log/datadog/dotnet

ENV ASPNETCORE_URLS=http://localhost:5000

# see https://github.com/dotnet/runtime/issues/77973
ENV COMPlus_TieredCompilation=0

# Copy the app across
COPY --from=builder /src/publish /app/.

Expand Down
3 changes: 0 additions & 3 deletions tracer/build/_build/docker/smoke.dotnet-tool.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ ENV DD_TRACE_DEBUG=1
ENV ASPNETCORE_URLS=http://localhost:5000
ENV DD_PROFILING_LOG_DIR=/var/log/datadog/dotnet

# see https://github.com/dotnet/runtime/issues/77973
ENV COMPlus_TieredCompilation=0

# Copy the app across
COPY --from=builder /src/publish /app/.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ ENV DD_TRACE_DEBUG=1
ENV ASPNETCORE_URLS=http://localhost:5000
ENV DD_PROFILING_LOG_DIR=/var/log/datadog/dotnet

# see https://github.com/dotnet/runtime/issues/77973
ENV COMPlus_TieredCompilation=0

# Copy the app across
COPY --from=builder /src/publish /app/.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ ENV DD_TRACE_DEBUG=1
ENV ASPNETCORE_URLS=http://localhost:5000
ENV DD_PROFILING_LOG_DIR=/var/log/datadog/dotnet

# see https://github.com/dotnet/runtime/issues/77973
ENV COMPlus_TieredCompilation=0

# Copy the app across
COPY --from=builder /src/publish /app/.

Expand Down
3 changes: 0 additions & 3 deletions tracer/build/_build/docker/smoke.windows.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ ENV DD_PROFILING_ENABLED=1 \
DD_PROFILING_LOG_DIR="C:\logs" \
ASPNETCORE_URLS=http://localhost:5000

# see https://github.com/dotnet/runtime/issues/77973
ENV COMPlus_TieredCompilation=0

# Copy the app across
COPY --from=builder /src/publish /app/.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ ENV DD_PROFILING_ENABLED=1 \
DD_PROFILING_LOG_DIR="C:\logs" \
ASPNETCORE_URLS=http://localhost:5000

# see https://github.com/dotnet/runtime/issues/77973
ENV COMPlus_TieredCompilation=0

# Copy the app across
COPY --from=builder /src/publish /app/.

Expand Down
3 changes: 0 additions & 3 deletions tracer/build/_build/docker/smoke.windows.nuget.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ ENV CORECLR_ENABLE_PROFILING=1 \
DD_PROFILING_ENABLED=1 \
ASPNETCORE_URLS=http://localhost:5000

# see https://github.com/dotnet/runtime/issues/77973
ENV COMPlus_TieredCompilation=0

# Copy the app across
COPY --from=builder /src/publish /app/.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ ENV DD_PROFILING_ENABLED=1 \
DD_PROFILING_LOG_DIR="C:\logs" \
ASPNETCORE_URLS=http://localhost:5000

# see https://github.com/dotnet/runtime/issues/77973
ENV COMPlus_TieredCompilation=0

# Copy the app across
COPY --from=builder /src/publish /app/.

Expand Down
28 changes: 26 additions & 2 deletions tracer/src/Datadog.Tracer.Native/cor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,24 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
return E_FAIL;
}

WSTRING runtimeType = runtime_information_.is_core() ? (runtime_information_.major_version > 4 ? WStr(".NET") : WStr(".NET Core")) : WStr(".NET Framework");
Logger::Info("Runtime Information: ", runtimeType, " ", runtime_information_.major_version, ".", runtime_information_.minor_version, ".", runtime_information_.build_version);

// Check if we have to disable tiered compilation (due to https://github.com/dotnet/runtime/issues/77973)
bool disableTieredCompilation = false;
bool internal_workaround_77973_enabled = true;
shared::TryParseBooleanEnvironmentValue(shared::GetEnvironmentValue(environment::internal_workaround_77973_enabled), internal_workaround_77973_enabled);
if (internal_workaround_77973_enabled)
{
if (runtime_information_.major_version == 5 ||
(runtime_information_.major_version == 6 && runtime_information_.minor_version == 0 && runtime_information_.build_version <= 12) ||
(runtime_information_.major_version == 7 && runtime_information_.minor_version == 0 && runtime_information_.build_version <= 1))
{
Logger::Warn("Tiered Compilation was disabled due to https://github.com/dotnet/runtime/issues/77973. This action can be disabled by setting the environment variable DD_INTERNAL_WORKAROUND_77973_ENABLED=false");
disableTieredCompilation = true;
}
}

auto pInfo = info10 != nullptr ? info10 : this->info_;
auto work_offloader = std::make_shared<RejitWorkOffloader>(pInfo);

Expand Down Expand Up @@ -255,8 +273,14 @@ HRESULT STDMETHODCALLTYPE CorProfiler::Initialize(IUnknown* cor_profiler_info_un
event_mask |= COR_PRF_DISABLE_ALL_NGEN_IMAGES;
}

// set event mask to subscribe to events and disable NGEN images
hr = this->info_->SetEventMask2(event_mask, COR_PRF_HIGH_ADD_ASSEMBLY_REFERENCES);
DWORD high_event_mask = COR_PRF_HIGH_ADD_ASSEMBLY_REFERENCES;
if (disableTieredCompilation)
{
high_event_mask |= COR_PRF_HIGH_DISABLE_TIERED_COMPILATION;
}

// set event mask to subscribe to events
hr = this->info_->SetEventMask2(event_mask, high_event_mask);
if (FAILED(hr))
{
Logger::Warn("DATADOG TRACER DIAGNOSTICS - Failed to attach profiler: unable to set event mask.");
Expand Down
3 changes: 3 additions & 0 deletions tracer/src/Datadog.Tracer.Native/environment_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ namespace environment
// Sets whether the current process must run in CI Visibility mode or not.
const shared::WSTRING ci_visibility_enabled = WStr("DD_CIVISIBILITY_ENABLED");

// Enables the workaround for dotnet issue 77973 (https://github.com/dotnet/runtime/issues/77973)
const shared::WSTRING internal_workaround_77973_enabled = WStr("DD_INTERNAL_WORKAROUND_77973_ENABLED");

} // namespace environment
} // namespace trace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public void SetEnvironmentVariables(
{
string profilerEnabled = AutomaticInstrumentationEnabled ? "1" : "0";
environmentVariables["DD_DOTNET_TRACER_HOME"] = MonitoringHome;
environmentVariables["COMPlus_TieredCompilation"] = "0";

// Everything should be using the native loader now
var nativeLoaderPath = GetNativeLoaderPath();
Expand Down