diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp index bea3fc3d87..68e13e4c8f 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/cor_profiler.cpp @@ -36,8 +36,6 @@ #include #endif -using namespace std::chrono_literals; - #ifdef _WIN32 #include "netfx_assembly_redirection.h" #endif @@ -53,6 +51,8 @@ using namespace std::chrono_literals; return E_FAIL; \ } +using namespace std::chrono_literals; + namespace trace { @@ -788,10 +788,10 @@ HRESULT STDMETHODCALLTYPE CorProfiler::ModuleLoadFinished(ModuleID module_id, HR // We call the function to analyze the module and request the ReJIT of integrations defined in this module. if (tracer_integration_preprocessor != nullptr && !integration_definitions_.empty()) { - std::promise promise; - std::future future = promise.get_future(); + auto promise = std::make_shared>(); + std::future future = promise->get_future(); tracer_integration_preprocessor->EnqueueRequestRejitForLoadedModules(std::vector{module_id}, - integration_definitions_, &promise); + integration_definitions_, promise); // wait and get the value from the future const auto status = future.wait_for(100ms); @@ -1109,14 +1109,24 @@ void CorProfiler::InternalAddInstrumentation(WCHAR* id, CallTargetDefinition* it { if (rejit_handler != nullptr) { - std::promise promise; - std::future future = promise.get_future(); + auto promise = std::make_shared>(); + std::future future = promise->get_future(); tracer_integration_preprocessor->EnqueueRequestRejitForLoadedModules(module_ids_, - integrationDefinitions, &promise); + integrationDefinitions, promise); - // wait and get the value from the future - const auto& numReJITs = future.get(); - Logger::Debug("Total number of ReJIT Requested: ", numReJITs); + // wait and get the value from the future + const auto status = future.wait_for(100ms); + + if (status != std::future_status::timeout) + { + const auto& numReJITs = future.get(); + Logger::Debug("Total number of ReJIT Requested: ", numReJITs); + } + else + { + Logger::Warn("Timeout while waiting for the rejit requests to be processed. Rejit will continue " + "asynchronously, but some initial calls may not be instrumented"); + } } integration_definitions_.reserve(integration_definitions_.size() + integrationDefinitions.size()); diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/rejit_preprocessor.cpp b/src/OpenTelemetry.AutoInstrumentation.Native/rejit_preprocessor.cpp index 96dd521f95..2cdf67dddf 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/rejit_preprocessor.cpp +++ b/src/OpenTelemetry.AutoInstrumentation.Native/rejit_preprocessor.cpp @@ -395,7 +395,7 @@ template void RejitPreprocessor::EnqueueRequestRejitForLoadedModules( const std::vector& modulesVector, const std::vector& definitions, - std::promise* promise) + std::shared_ptr> promise) { if (m_rejit_handler->IsShutdownRequested()) { diff --git a/src/OpenTelemetry.AutoInstrumentation.Native/rejit_preprocessor.h b/src/OpenTelemetry.AutoInstrumentation.Native/rejit_preprocessor.h index 5401d1c78e..0cef022626 100644 --- a/src/OpenTelemetry.AutoInstrumentation.Native/rejit_preprocessor.h +++ b/src/OpenTelemetry.AutoInstrumentation.Native/rejit_preprocessor.h @@ -53,7 +53,7 @@ class RejitPreprocessor void EnqueueRequestRejitForLoadedModules(const std::vector& modulesVector, const std::vector& requests, - std::promise* promise); + std::shared_ptr> promise); }; ///