From f2fbd803b9d42cacc53a7e12addbc4c2bf3ce0ef Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 9 Oct 2018 16:11:52 -0700 Subject: [PATCH] Flow request trace context to CreateApplication (#1480) --- .../AspNetCore/ApplicationFactory.h | 14 +++++++++----- .../AspNetCore/applicationinfo.cpp | 15 ++++++++------- .../AspNetCore/applicationinfo.h | 8 ++++---- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h b/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h index 30a0a3359b..4d29b4fb39 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h +++ b/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h @@ -31,13 +31,17 @@ public: HRESULT Execute( _In_ IHttpServer *pServer, - _In_ const IHttpApplication *pHttpApplication, - _Outptr_ IAPPLICATION **pApplication) const noexcept + _In_ IHttpContext *pHttpContext, + _Outptr_ IAPPLICATION **pApplication) const { - std::array parameters { - {"InProcessExeLocation", m_location.data()} + std::array parameters { + { + {"InProcessExeLocation", m_location.data()}, + {"TraceContext", pHttpContext->GetTraceContext()} + } }; - return m_pfnAspNetCoreCreateApplication(pServer, pHttpApplication, parameters.data(), static_cast(parameters.size()), pApplication); + + return m_pfnAspNetCoreCreateApplication(pServer, pHttpContext->GetApplication(), parameters.data(), static_cast(parameters.size()), pApplication); } private: diff --git a/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp b/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp index 9b95d94f16..36b0c2d902 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.cpp @@ -43,7 +43,7 @@ APPLICATION_INFO::CreateHandler( // check if other thread created application RETURN_IF_FAILED(hr = TryCreateHandler(pHttpContext, pHandler)); - // In some cases (adding and removing app_offline quickly) application might start and stop immediately + // In some cases (adding and removing app_offline quickly) application might start and stop immediately // so retry until we get valid handler or error while (hr != S_OK) { @@ -59,7 +59,7 @@ APPLICATION_INFO::CreateHandler( m_pApplicationFactory = nullptr; } - RETURN_IF_FAILED(CreateApplication(*pHttpContext.GetApplication())); + RETURN_IF_FAILED(CreateApplication(pHttpContext)); RETURN_IF_FAILED(hr = TryCreateHandler(pHttpContext, pHandler)); } @@ -69,8 +69,9 @@ APPLICATION_INFO::CreateHandler( } HRESULT -APPLICATION_INFO::CreateApplication(const IHttpApplication& pHttpApplication) +APPLICATION_INFO::CreateApplication(IHttpContext& pHttpContext) { + auto& pHttpApplication = *pHttpContext.GetApplication(); if (AppOfflineApplication::ShouldBeStarted(pHttpApplication)) { LOG_INFO(L"Detected app_offline file, creating polling application"); @@ -85,7 +86,7 @@ APPLICATION_INFO::CreateApplication(const IHttpApplication& pHttpApplication) const WebConfigConfigurationSource configurationSource(m_pServer.GetAdminManager(), pHttpApplication); ShimOptions options(configurationSource); - const auto hr = TryCreateApplication(pHttpApplication, options); + const auto hr = TryCreateApplication(pHttpContext, options); if (FAILED_LOG(hr)) { @@ -130,15 +131,15 @@ APPLICATION_INFO::CreateApplication(const IHttpApplication& pHttpApplication) } HRESULT -APPLICATION_INFO::TryCreateApplication(const IHttpApplication& pHttpApplication, const ShimOptions& options) +APPLICATION_INFO::TryCreateApplication(IHttpContext& pHttpContext, const ShimOptions& options) { - RETURN_IF_FAILED(m_handlerResolver.GetApplicationFactory(pHttpApplication, m_pApplicationFactory, options)); + RETURN_IF_FAILED(m_handlerResolver.GetApplicationFactory(*pHttpContext.GetApplication(), m_pApplicationFactory, options)); LOG_INFO(L"Creating handler application"); IAPPLICATION * newApplication; RETURN_IF_FAILED(m_pApplicationFactory->Execute( &m_pServer, - &pHttpApplication, + &pHttpContext, &newApplication)); m_pApplication.reset(newApplication); diff --git a/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.h b/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.h index 4b190007dd..b40e0a8ba9 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.h +++ b/src/AspNetCoreModuleV2/AspNetCore/applicationinfo.h @@ -50,7 +50,7 @@ public: CreateHandler( IHttpContext& pHttpContext, std::unique_ptr& pHandler); - + bool ConfigurationPathApplies(const std::wstring& path) { // We need to check that the last character of the config path @@ -67,17 +67,17 @@ public: } private: - + HRESULT TryCreateHandler( IHttpContext& pHttpContext, std::unique_ptr& pHandler); HRESULT - CreateApplication(const IHttpApplication& pHttpApplication); + CreateApplication(IHttpContext& pHttpContext); HRESULT - TryCreateApplication(const IHttpApplication& pHttpApplication, const ShimOptions& options); + TryCreateApplication(IHttpContext& pHttpContext, const ShimOptions& options); IHttpServer &m_pServer; HandlerResolver &m_handlerResolver;