diff --git a/tracer/build/_build/docker/smoke.dockerfile b/tracer/build/_build/docker/smoke.dockerfile index b5162d5dc505..89352309d8b5 100644 --- a/tracer/build/_build/docker/smoke.dockerfile +++ b/tracer/build/_build/docker/smoke.dockerfile @@ -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/. diff --git a/tracer/build/_build/docker/smoke.dotnet-tool.dockerfile b/tracer/build/_build/docker/smoke.dotnet-tool.dockerfile index 58c422f69173..37c5d0255928 100644 --- a/tracer/build/_build/docker/smoke.dotnet-tool.dockerfile +++ b/tracer/build/_build/docker/smoke.dotnet-tool.dockerfile @@ -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/. diff --git a/tracer/build/_build/docker/smoke.dotnet-tool.nuget.dockerfile b/tracer/build/_build/docker/smoke.dotnet-tool.nuget.dockerfile index 631c6bb5b1d6..bfb6b78b5cd5 100644 --- a/tracer/build/_build/docker/smoke.dotnet-tool.nuget.dockerfile +++ b/tracer/build/_build/docker/smoke.dotnet-tool.nuget.dockerfile @@ -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/. diff --git a/tracer/build/_build/docker/smoke.dotnet-tool.self-instrument.dockerfile b/tracer/build/_build/docker/smoke.dotnet-tool.self-instrument.dockerfile index 8f9afcdc6c8c..70e10f0b3469 100644 --- a/tracer/build/_build/docker/smoke.dotnet-tool.self-instrument.dockerfile +++ b/tracer/build/_build/docker/smoke.dotnet-tool.self-instrument.dockerfile @@ -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/. diff --git a/tracer/build/_build/docker/smoke.windows.dockerfile b/tracer/build/_build/docker/smoke.windows.dockerfile index 7ba449fe8a8d..d4f73c8a83c5 100644 --- a/tracer/build/_build/docker/smoke.windows.dockerfile +++ b/tracer/build/_build/docker/smoke.windows.dockerfile @@ -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/. diff --git a/tracer/build/_build/docker/smoke.windows.dotnet-tool.dockerfile b/tracer/build/_build/docker/smoke.windows.dotnet-tool.dockerfile index 7a2674291ce2..3a76ff82444f 100644 --- a/tracer/build/_build/docker/smoke.windows.dotnet-tool.dockerfile +++ b/tracer/build/_build/docker/smoke.windows.dotnet-tool.dockerfile @@ -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/. diff --git a/tracer/build/_build/docker/smoke.windows.nuget.dockerfile b/tracer/build/_build/docker/smoke.windows.nuget.dockerfile index 74a3b6d5c107..1beff6f20bef 100644 --- a/tracer/build/_build/docker/smoke.windows.nuget.dockerfile +++ b/tracer/build/_build/docker/smoke.windows.nuget.dockerfile @@ -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/. diff --git a/tracer/build/_build/docker/smoke.windows.tracer-home.dockerfile b/tracer/build/_build/docker/smoke.windows.tracer-home.dockerfile index 7f8e02171112..113a0472208b 100644 --- a/tracer/build/_build/docker/smoke.windows.tracer-home.dockerfile +++ b/tracer/build/_build/docker/smoke.windows.tracer-home.dockerfile @@ -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/. diff --git a/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp b/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp index 3f54f17c9270..12960d26eab7 100644 --- a/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp +++ b/tracer/src/Datadog.Tracer.Native/cor_profiler.cpp @@ -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::Info("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(pInfo); @@ -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."); diff --git a/tracer/src/Datadog.Tracer.Native/environment_variables.h b/tracer/src/Datadog.Tracer.Native/environment_variables.h index 030500859cf7..3f110bcbfa2c 100644 --- a/tracer/src/Datadog.Tracer.Native/environment_variables.h +++ b/tracer/src/Datadog.Tracer.Native/environment_variables.h @@ -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 diff --git a/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs b/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs index e66584bec8ef..0e83501bc235 100644 --- a/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs +++ b/tracer/test/Datadog.Trace.TestHelpers/EnvironmentHelper.cs @@ -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();