diff --git a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.cpp b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.cpp index f5098f71f6..e3574d88e8 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.cpp @@ -5,7 +5,7 @@ #include "HandleWrapper.h" -REQUEST_NOTIFICATION_STATUS AppOfflineHandler::OnExecuteRequestHandler() +REQUEST_NOTIFICATION_STATUS AppOfflineHandler::ExecuteRequestHandler() { HTTP_DATA_CHUNK DataChunk {}; auto pResponse = m_pContext.GetResponse(); diff --git a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.h b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.h index e0ffd5d7cc..87f729bf82 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.h +++ b/src/AspNetCoreModuleV2/AspNetCore/AppOfflineHandler.h @@ -10,12 +10,13 @@ class AppOfflineHandler: public REQUEST_HANDLER { public: AppOfflineHandler(IHttpContext& pContext, const std::string appOfflineContent) - : m_pContext(pContext), + : REQUEST_HANDLER(pContext), + m_pContext(pContext), m_strAppOfflineContent(appOfflineContent) { } - REQUEST_NOTIFICATION_STATUS OnExecuteRequestHandler() override; + REQUEST_NOTIFICATION_STATUS ExecuteRequestHandler() override; private: IHttpContext& m_pContext; diff --git a/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h b/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h index 4d29b4fb39..ed9733b68a 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h +++ b/src/AspNetCoreModuleV2/AspNetCore/ApplicationFactory.h @@ -34,9 +34,11 @@ public: _In_ IHttpContext *pHttpContext, _Outptr_ IAPPLICATION **pApplication) const { + // m_location.data() is const ptr copy to local to get mutable pointer + auto location = m_location; std::array parameters { { - {"InProcessExeLocation", m_location.data()}, + {"InProcessExeLocation", location.data()}, {"TraceContext", pHttpContext->GetTraceContext()} } }; diff --git a/src/AspNetCoreModuleV2/AspNetCore/ancm.mof b/src/AspNetCoreModuleV2/AspNetCore/ancm.mof index 289225477d..359806f8a2 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/ancm.mof +++ b/src/AspNetCoreModuleV2/AspNetCore/ancm.mof @@ -5,7 +5,7 @@ /* * AspNetCore module trace events layout * Uncomment the following class to run mof2trace to generate header file - * comment it back before checking it in + * comment it back before checking it in [Dynamic, Description("IIS: WWW Server"), Guid("{3a2a4e84-4c21-4981-ae10-3fda0d9b0f83}"), @@ -187,7 +187,7 @@ class ANCMWinHttpCallBack:ANCM_Events [Dynamic, Description("Starting inprocess execute request") : amended, - EventType(8), + EventType(7), EventLevel(4), EventTypeName("ANCM_INPROC_EXECUTE_REQUEST_START") : amended ] @@ -203,7 +203,7 @@ class ANCMExecuteStart:ANCM_Events [Dynamic, Description("Ending inprocess execute request") : amended, - EventType(10), + EventType(8), EventLevel(5), EventTypeName("ANCM_INPROC_EXECUTE_REQUEST_COMPLETION") : amended ] @@ -224,7 +224,7 @@ class ANCMExecuteEnd:ANCM_Events [Dynamic, Description("Starting inprocess async completion") : amended, - EventType(8), + EventType(9), EventLevel(5), EventTypeName("ANCM_INPROC_ASYNC_COMPLETION_START") : amended ] @@ -293,7 +293,7 @@ class ANCMRequestDisconnect:ANCM_Events [Dynamic, Description("Indicate managed request complete") : amended, - EventType(12), + EventType(13), EventLevel(4), EventTypeName("ANCM_INPROC_MANAGED_REQUEST_COMPLETION") : amended ] @@ -306,3 +306,66 @@ class ANCMManagedRequestCompletion:ANCM_Events read] object ContextId; }; + +[Dynamic, + Description("Failed HRESULT") : amended, + EventType(14), + EventLevel(3), + EventTypeName("ANCM_HRESULT_FAILED") : amended +] +class ANCMHRESULTFailed:ANCM_Events +{ + [WmiDataId(1), + Description("Context ID") : amended, + extension("Guid"), + ActivityID, + read] + object ContextId; + [WmiDataId(2), + Description("Failed source file location") : amended, + StringTermination("NullTerminated"), + read] + string File; + [WmiDataId(3), + Description("Failed line number") : amended, + format("d"), + read] + uint32 Line; + [WmiDataId(4), + Description("HResult") : amended, + format("x"), + read] + uint32 HResult; +}; + +[Dynamic, + Description("Caught exception") : amended, + EventType(15), + EventLevel(3), + EventTypeName("ANCM_EXCEPTION_CAUGHT") : amended +] +class ANCMExceptionCaughFailed:ANCM_Events +{ + [WmiDataId(1), + Description("Context ID") : amended, + extension("Guid"), + ActivityID, + read] + object ContextId; + [WmiDataId(2), + Description("Exception catch file location") : amended, + StringTermination("NullTerminated"), + read] + string File; + [WmiDataId(3), + Description("Exception catch line number") : amended, + format("d"), + read] + uint32 Line; + [WmiDataId(2), + Description("Exception description") : amended, + StringTermination("NullTerminated"), + read] + string Description; +}; + diff --git a/src/AspNetCoreModuleV2/AspNetCore/proxymodule.cpp b/src/AspNetCoreModuleV2/AspNetCore/proxymodule.cpp index e6b234d667..01707ffa9e 100644 --- a/src/AspNetCoreModuleV2/AspNetCore/proxymodule.cpp +++ b/src/AspNetCoreModuleV2/AspNetCore/proxymodule.cpp @@ -86,6 +86,7 @@ ASPNET_CORE_PROXY_MODULE::OnExecuteRequestHandler( HRESULT hr = S_OK; REQUEST_NOTIFICATION_STATUS retVal = RQ_NOTIFICATION_CONTINUE; + TraceContextScope traceScope(pHttpContext->GetTraceContext()); // We don't want OnAsyncCompletion to complete request before OnExecuteRequestHandler exits auto lock = SRWExclusiveLock(m_requestLock); @@ -131,13 +132,14 @@ Finished: __override REQUEST_NOTIFICATION_STATUS ASPNET_CORE_PROXY_MODULE::OnAsyncCompletion( - IHttpContext *, + IHttpContext * pHttpContext, DWORD, BOOL, IHttpEventProvider *, IHttpCompletionInfo * pCompletionInfo ) { + TraceContextScope traceScope(pHttpContext->GetTraceContext()); // We don't want OnAsyncCompletion to complete request before OnExecuteRequestHandler exits auto lock = SRWExclusiveLock(m_requestLock); diff --git a/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj b/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj index 7968238f90..0ddec2fcb1 100644 --- a/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj +++ b/src/AspNetCoreModuleV2/CommonLib/CommonLib.vcxproj @@ -205,6 +205,7 @@ + @@ -219,8 +220,7 @@ - - + diff --git a/src/AspNetCoreModuleV2/CommonLib/EventTracing.h b/src/AspNetCoreModuleV2/CommonLib/EventTracing.h new file mode 100644 index 0000000000..3734068aae --- /dev/null +++ b/src/AspNetCoreModuleV2/CommonLib/EventTracing.h @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +#pragma once + +#include + +#pragma warning( push ) +#pragma warning ( disable : ALL_CODE_ANALYSIS_WARNINGS ) + +#include "aspnetcore_event.h" + +#pragma warning( pop ) + +template< class EVENT, typename ...Params > +void RaiseEvent(IHttpTraceContext * pTraceContext,Params&&... params) +{ + if (pTraceContext != nullptr && EVENT::IsEnabled(pTraceContext)) + { + EVENT::RaiseEvent(pTraceContext, std::forward(params)...); + } +} + +template< class EVENT, typename ...Params > +void RaiseEvent(IHttpContext * pHttpContext,Params&&... params) +{ + ::RaiseEvent(pHttpContext->GetTraceContext(), std::forward(params)...); +} diff --git a/src/AspNetCoreModuleV2/CommonLib/ModuleTracer.h b/src/AspNetCoreModuleV2/CommonLib/ModuleTracer.h deleted file mode 100644 index 6ef03fb53a..0000000000 --- a/src/AspNetCoreModuleV2/CommonLib/ModuleTracer.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -#pragma once -#include "aspnetcore_event.h" - -class ModuleTracer -{ -public: - - ModuleTracer(IHttpTraceContext* traceContext) - { - m_traceContext = traceContext; - } - - VOID - ExecuteRequestStart() - { - if (ANCMEvents::ANCM_INPROC_EXECUTE_REQUEST_START::IsEnabled(m_traceContext)) - { - ANCMEvents::ANCM_INPROC_EXECUTE_REQUEST_START::RaiseEvent( - m_traceContext, - NULL); - } - } - - VOID - ExecuteRequestEnd(REQUEST_NOTIFICATION_STATUS status) - { - if (ANCMEvents::ANCM_INPROC_EXECUTE_REQUEST_COMPLETION::IsEnabled(m_traceContext)) - { - ANCMEvents::ANCM_INPROC_EXECUTE_REQUEST_COMPLETION::RaiseEvent( - m_traceContext, - NULL, - status); - } - } - - VOID - AsyncCompletionStart() - { - - if (ANCMEvents::ANCM_INPROC_ASYNC_COMPLETION_START::IsEnabled(m_traceContext)) - { - ANCMEvents::ANCM_INPROC_ASYNC_COMPLETION_START::RaiseEvent( - m_traceContext, - NULL); - } - } - - VOID - AsyncCompletionEnd(REQUEST_NOTIFICATION_STATUS status) - { - if (ANCMEvents::ANCM_INPROC_ASYNC_COMPLETION_COMPLETION::IsEnabled(m_traceContext)) - { - ANCMEvents::ANCM_INPROC_ASYNC_COMPLETION_COMPLETION::RaiseEvent( - m_traceContext, - NULL, - status); - } - } - - VOID - RequestShutdown() - { - if (ANCMEvents::ANCM_INPROC_REQUEST_SHUTDOWN::IsEnabled(m_traceContext)) - { - ANCMEvents::ANCM_INPROC_REQUEST_SHUTDOWN::RaiseEvent( - m_traceContext, - NULL); - } - } - - VOID - RequestDisconnect() - { - if (ANCMEvents::ANCM_INPROC_REQUEST_DISCONNECT::IsEnabled(m_traceContext)) - { - ANCMEvents::ANCM_INPROC_REQUEST_DISCONNECT::RaiseEvent( - m_traceContext, - NULL); - } - } - - VOID - ManagedCompletion() - { - if (ANCMEvents::ANCM_INPROC_MANAGED_REQUEST_COMPLETION::IsEnabled(m_traceContext)) - { - ANCMEvents::ANCM_INPROC_MANAGED_REQUEST_COMPLETION::RaiseEvent( - m_traceContext, - NULL); - } - } - -private: - IHttpTraceContext * m_traceContext; -}; diff --git a/src/AspNetCoreModuleV2/CommonLib/ServerErrorHandler.h b/src/AspNetCoreModuleV2/CommonLib/ServerErrorHandler.h index 69aa0d440a..eb493ce722 100644 --- a/src/AspNetCoreModuleV2/CommonLib/ServerErrorHandler.h +++ b/src/AspNetCoreModuleV2/CommonLib/ServerErrorHandler.h @@ -10,8 +10,9 @@ class ServerErrorHandler : public REQUEST_HANDLER { public: - ServerErrorHandler(IHttpContext &pContext, USHORT statusCode, USHORT subStatusCode, std::string statusText, HRESULT hr, HINSTANCE moduleInstance, bool disableStartupPage, int page) - : m_pContext(pContext), + ServerErrorHandler(IHttpContext &pContext, USHORT statusCode, USHORT subStatusCode, std::string statusText, HRESULT hr, HINSTANCE moduleInstance, bool disableStartupPage, int page) noexcept + : REQUEST_HANDLER(pContext), + m_pContext(pContext), m_HR(hr), m_disableStartupPage(disableStartupPage), m_page(page), @@ -22,7 +23,7 @@ public: { } - REQUEST_NOTIFICATION_STATUS OnExecuteRequestHandler() override + REQUEST_NOTIFICATION_STATUS ExecuteRequestHandler() override { static std::string s_html500Page = GetHtml(m_moduleInstance, m_page); diff --git a/src/AspNetCoreModuleV2/CommonLib/application.h b/src/AspNetCoreModuleV2/CommonLib/application.h index 814be8aae6..add050b208 100644 --- a/src/AspNetCoreModuleV2/CommonLib/application.h +++ b/src/AspNetCoreModuleV2/CommonLib/application.h @@ -7,6 +7,7 @@ #include "iapplication.h" #include "ntassert.h" #include "SRWExclusiveLock.h" +#include "exceptions.h" class APPLICATION : public IAPPLICATION { @@ -20,6 +21,7 @@ public: _In_ IHttpContext *pHttpContext, _Outptr_result_maybenull_ IREQUEST_HANDLER **pRequestHandler) override { + TraceContextScope traceScope(pHttpContext->GetTraceContext()); *pRequestHandler = nullptr; if (m_fStopCalled) diff --git a/src/AspNetCoreModuleV2/CommonLib/aspnetcore_event.h b/src/AspNetCoreModuleV2/CommonLib/aspnetcore_event.h index f40dc0d2bb..d3ed02223a 100644 --- a/src/AspNetCoreModuleV2/CommonLib/aspnetcore_event.h +++ b/src/AspNetCoreModuleV2/CommonLib/aspnetcore_event.h @@ -3,16 +3,16 @@ #define __ASPNETCOREEVENT_H__ /*++ -Copyright (c) 2005 Microsoft Corporation + Copyright (c) 2005 Microsoft Corporation -Module Name: + Module Name: -aspnetcore_event.h + aspnetcore_event.h -Abstract: + Abstract: -Header file has been generated from mof file containing -IIS trace event descriptions + Header file has been generated from mof file containing + IIS trace event descriptions --*/ @@ -24,18 +24,16 @@ IIS trace event descriptions // Description: IIS: WWW Server // -#include "httptrace.h" - class WWWServerTraceProvider { public: static - LPCGUID - GetProviderGuid(VOID) - // return GUID for the current event class + LPCGUID + GetProviderGuid( VOID ) + // return GUID for the current event class { - static const GUID ProviderGuid = - { 0x3a2a4e84,0x4c21,0x4981,{ 0xae,0x10,0x3f,0xda,0x0d,0x9b,0x0f,0x83 } }; + static const GUID ProviderGuid = + {0x3a2a4e84,0x4c21,0x4981,{0xae,0x10,0x3f,0xda,0x0d,0x9b,0x0f,0x83}}; return &ProviderGuid; }; enum enumAreaFlags @@ -44,10 +42,10 @@ public: ANCM = 0x10000 }; static - LPCWSTR - TranslateEnumAreaFlagsToString(enum enumAreaFlags EnumValue) + LPCWSTR + TranslateEnumAreaFlagsToString( enum enumAreaFlags EnumValue) { - switch ((DWORD)EnumValue) + switch( (DWORD) EnumValue ) { case 0x10000: return L"ANCM"; } @@ -55,26 +53,26 @@ public: }; static - BOOL - CheckTracingEnabled( - IHttpTraceContext * pHttpTraceContext, - enumAreaFlags AreaFlags, - DWORD dwVerbosity) + BOOL + CheckTracingEnabled( + IHttpTraceContext * pHttpTraceContext, + enumAreaFlags AreaFlags, + DWORD dwVerbosity ) { HRESULT hr; HTTP_TRACE_CONFIGURATION TraceConfig; TraceConfig.pProviderGuid = GetProviderGuid(); - hr = pHttpTraceContext->GetTraceConfiguration(&TraceConfig); - if (FAILED(hr) || !TraceConfig.fProviderEnabled) + hr = pHttpTraceContext->GetTraceConfiguration( &TraceConfig ); + if ( FAILED( hr ) || !TraceConfig.fProviderEnabled ) { return FALSE; } - if (TraceConfig.dwVerbosity >= dwVerbosity && - (TraceConfig.dwAreas == (DWORD)AreaFlags || - (TraceConfig.dwAreas & (DWORD)AreaFlags) == (DWORD)AreaFlags)) - { + if ( TraceConfig.dwVerbosity >= dwVerbosity && + ( TraceConfig.dwAreas == (DWORD) AreaFlags || + ( TraceConfig.dwAreas & (DWORD)AreaFlags ) == (DWORD)AreaFlags ) ) + { return TRUE; - } + } return FALSE; }; }; @@ -89,12 +87,12 @@ class ANCMEvents { public: static - LPCGUID - GetAreaGuid(VOID) - // return GUID for the current event class + LPCGUID + GetAreaGuid( VOID ) + // return GUID for the current event class { - static const GUID AreaGuid = - { 0x82adead7,0x12b2,0x4781,{ 0xbd,0xca,0x5a,0x4b,0x6c,0x75,0x71,0x91 } }; + static const GUID AreaGuid = + {0x82adead7,0x12b2,0x4781,{0xbd,0xca,0x5a,0x4b,0x6c,0x75,0x71,0x91}}; return &AreaGuid; }; @@ -105,24 +103,24 @@ public: // EventType: 1 // EventLevel: 4 // - + class ANCM_START_APPLICATION_SUCCESS { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId, - LPCWSTR pAppDescription - ) - // - // Raise ANCM_START_APPLICATION_SUCCESS Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId, + LPCWSTR pAppDescription + ) + // + // Raise ANCM_START_APPLICATION_SUCCESS Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); Event.dwEvent = 1; Event.pszEventName = L"ANCM_START_APPLICATION_SUCCESS"; @@ -133,36 +131,36 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[2]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; - Items[1].pszName = L"AppDescription"; - Items[1].dwDataType = HTTP_TRACE_TYPE_LPCWSTR; // mof type (string) - Items[1].pbData = (PBYTE)pAppDescription; - Items[1].cbData = - (Items[1].pbData == NULL) ? 0 : (sizeof(WCHAR) * (1 + (DWORD)wcslen((PWSTR)Items[1].pbData))); - Items[1].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 2 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; + Items[ 1 ].pszName = L"AppDescription"; + Items[ 1 ].dwDataType = HTTP_TRACE_TYPE_LPCWSTR; // mof type (string) + Items[ 1 ].pbData = (PBYTE) pAppDescription; + Items[ 1 ].cbData = + ( Items[ 1 ].pbData == NULL )? 0 : ( sizeof(WCHAR) * (1 + (DWORD) wcslen( (PWSTR) Items[ 1 ].pbData ) ) ); + Items[ 1 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 4); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 4 ); //Verbosity }; }; // @@ -172,24 +170,24 @@ public: // EventType: 2 // EventLevel: 2 // - + class ANCM_START_APPLICATION_FAIL { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId, - LPCWSTR pFailureDescription - ) - // - // Raise ANCM_START_APPLICATION_FAIL Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId, + LPCWSTR pFailureDescription + ) + // + // Raise ANCM_START_APPLICATION_FAIL Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); Event.dwEvent = 2; Event.pszEventName = L"ANCM_START_APPLICATION_FAIL"; @@ -200,36 +198,36 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[2]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; - Items[1].pszName = L"FailureDescription"; - Items[1].dwDataType = HTTP_TRACE_TYPE_LPCWSTR; // mof type (string) - Items[1].pbData = (PBYTE)pFailureDescription; - Items[1].cbData = - (Items[1].pbData == NULL) ? 0 : (sizeof(WCHAR) * (1 + (DWORD)wcslen((PWSTR)Items[1].pbData))); - Items[1].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 2 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; + Items[ 1 ].pszName = L"FailureDescription"; + Items[ 1 ].dwDataType = HTTP_TRACE_TYPE_LPCWSTR; // mof type (string) + Items[ 1 ].pbData = (PBYTE) pFailureDescription; + Items[ 1 ].cbData = + ( Items[ 1 ].pbData == NULL )? 0 : ( sizeof(WCHAR) * (1 + (DWORD) wcslen( (PWSTR) Items[ 1 ].pbData ) ) ); + Items[ 1 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 2); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 2 ); //Verbosity }; }; // @@ -239,23 +237,23 @@ public: // EventType: 3 // EventLevel: 4 // - + class ANCM_REQUEST_FORWARD_START { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId - ) - // - // Raise ANCM_REQUEST_FORWARD_START Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId + ) + // + // Raise ANCM_REQUEST_FORWARD_START Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); Event.dwEvent = 3; Event.pszEventName = L"ANCM_REQUEST_FORWARD_START"; @@ -266,30 +264,30 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[1]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 1 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 4); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 4 ); //Verbosity }; }; // @@ -299,23 +297,23 @@ public: // EventType: 4 // EventLevel: 4 // - + class ANCM_REQUEST_FORWARD_END { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId - ) - // - // Raise ANCM_REQUEST_FORWARD_END Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId + ) + // + // Raise ANCM_REQUEST_FORWARD_END Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); Event.dwEvent = 4; Event.pszEventName = L"ANCM_REQUEST_FORWARD_END"; @@ -326,30 +324,30 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[1]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 1 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 4); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 4 ); //Verbosity }; }; // @@ -359,24 +357,24 @@ public: // EventType: 5 // EventLevel: 2 // - + class ANCM_REQUEST_FORWARD_FAIL { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId, - ULONG ErrorCode - ) - // - // Raise ANCM_REQUEST_FORWARD_FAIL Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId, + ULONG ErrorCode + ) + // + // Raise ANCM_REQUEST_FORWARD_FAIL Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); Event.dwEvent = 5; Event.pszEventName = L"ANCM_REQUEST_FORWARD_FAIL"; @@ -387,35 +385,35 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[2]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; - Items[1].pszName = L"ErrorCode"; - Items[1].dwDataType = HTTP_TRACE_TYPE_ULONG; // mof type (uint32) - Items[1].pbData = (PBYTE)&ErrorCode; - Items[1].cbData = 4; - Items[1].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 2 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; + Items[ 1 ].pszName = L"ErrorCode"; + Items[ 1 ].dwDataType = HTTP_TRACE_TYPE_ULONG; // mof type (uint32) + Items[ 1 ].pbData = (PBYTE) &ErrorCode; + Items[ 1 ].cbData = 4; + Items[ 1 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 2); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 2 ); //Verbosity }; }; // @@ -425,24 +423,24 @@ public: // EventType: 6 // EventLevel: 4 // - + class ANCM_WINHTTP_CALLBACK { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId, - ULONG InternetStatus - ) - // - // Raise ANCM_WINHTTP_CALLBACK Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId, + ULONG InternetStatus + ) + // + // Raise ANCM_WINHTTP_CALLBACK Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); Event.dwEvent = 6; Event.pszEventName = L"ANCM_WINHTTP_CALLBACK"; @@ -453,63 +451,63 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[2]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; - Items[1].pszName = L"InternetStatus"; - Items[1].dwDataType = HTTP_TRACE_TYPE_ULONG; // mof type (uint32) - Items[1].pbData = (PBYTE)&InternetStatus; - Items[1].cbData = 4; - Items[1].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 2 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; + Items[ 1 ].pszName = L"InternetStatus"; + Items[ 1 ].dwDataType = HTTP_TRACE_TYPE_ULONG; // mof type (uint32) + Items[ 1 ].pbData = (PBYTE) &InternetStatus; + Items[ 1 ].cbData = 4; + Items[ 1 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 4); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 4 ); //Verbosity }; }; // // Event: mof class name ANCMExecuteStart, // Description: Starting inprocess execute request // EventTypeName: ANCM_INPROC_EXECUTE_REQUEST_START - // EventType: 8 + // EventType: 7 // EventLevel: 4 // - + class ANCM_INPROC_EXECUTE_REQUEST_START { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId - ) - // - // Raise ANCM_INPROC_EXECUTE_REQUEST_START Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId + ) + // + // Raise ANCM_INPROC_EXECUTE_REQUEST_START Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); - Event.dwEvent = 8; + Event.dwEvent = 7; Event.pszEventName = L"ANCM_INPROC_EXECUTE_REQUEST_START"; Event.dwEventVersion = 1; Event.dwVerbosity = 4; @@ -518,59 +516,59 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[1]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 1 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 4); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 4 ); //Verbosity }; }; // // Event: mof class name ANCMExecuteEnd, // Description: Ending inprocess execute request // EventTypeName: ANCM_INPROC_EXECUTE_REQUEST_COMPLETION - // EventType: 10 + // EventType: 8 // EventLevel: 5 // - + class ANCM_INPROC_EXECUTE_REQUEST_COMPLETION { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId, - ULONG requestStatus - ) - // - // Raise ANCM_INPROC_EXECUTE_REQUEST_COMPLETION Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId, + ULONG requestStatus + ) + // + // Raise ANCM_INPROC_EXECUTE_REQUEST_COMPLETION Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); - Event.dwEvent = 10; + Event.dwEvent = 8; Event.pszEventName = L"ANCM_INPROC_EXECUTE_REQUEST_COMPLETION"; Event.dwEventVersion = 1; Event.dwVerbosity = 5; @@ -579,63 +577,63 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[2]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; - Items[1].pszName = L"requestStatus"; - Items[1].dwDataType = HTTP_TRACE_TYPE_ULONG; // mof type (uint32) - Items[1].pbData = (PBYTE)&requestStatus; - Items[1].cbData = 4; - Items[1].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 2 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; + Items[ 1 ].pszName = L"requestStatus"; + Items[ 1 ].dwDataType = HTTP_TRACE_TYPE_ULONG; // mof type (uint32) + Items[ 1 ].pbData = (PBYTE) &requestStatus; + Items[ 1 ].cbData = 4; + Items[ 1 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 5); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 5 ); //Verbosity }; }; // // Event: mof class name ANCMAsyncStart, // Description: Starting inprocess async completion // EventTypeName: ANCM_INPROC_ASYNC_COMPLETION_START - // EventType: 8 + // EventType: 9 // EventLevel: 5 // - + class ANCM_INPROC_ASYNC_COMPLETION_START { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId - ) - // - // Raise ANCM_INPROC_ASYNC_COMPLETION_START Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId + ) + // + // Raise ANCM_INPROC_ASYNC_COMPLETION_START Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); - Event.dwEvent = 8; + Event.dwEvent = 9; Event.pszEventName = L"ANCM_INPROC_ASYNC_COMPLETION_START"; Event.dwEventVersion = 1; Event.dwVerbosity = 5; @@ -644,30 +642,30 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[1]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 1 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 5); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 5 ); //Verbosity }; }; // @@ -677,24 +675,24 @@ public: // EventType: 10 // EventLevel: 5 // - + class ANCM_INPROC_ASYNC_COMPLETION_COMPLETION { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId, - ULONG requestStatus - ) - // - // Raise ANCM_INPROC_ASYNC_COMPLETION_COMPLETION Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId, + ULONG requestStatus + ) + // + // Raise ANCM_INPROC_ASYNC_COMPLETION_COMPLETION Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); Event.dwEvent = 10; Event.pszEventName = L"ANCM_INPROC_ASYNC_COMPLETION_COMPLETION"; @@ -705,35 +703,35 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[2]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; - Items[1].pszName = L"requestStatus"; - Items[1].dwDataType = HTTP_TRACE_TYPE_ULONG; // mof type (uint32) - Items[1].pbData = (PBYTE)&requestStatus; - Items[1].cbData = 4; - Items[1].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 2 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; + Items[ 1 ].pszName = L"requestStatus"; + Items[ 1 ].dwDataType = HTTP_TRACE_TYPE_ULONG; // mof type (uint32) + Items[ 1 ].pbData = (PBYTE) &requestStatus; + Items[ 1 ].cbData = 4; + Items[ 1 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 5); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 5 ); //Verbosity }; }; // @@ -743,23 +741,23 @@ public: // EventType: 11 // EventLevel: 4 // - + class ANCM_INPROC_REQUEST_SHUTDOWN { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId - ) - // - // Raise ANCM_INPROC_REQUEST_SHUTDOWN Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId + ) + // + // Raise ANCM_INPROC_REQUEST_SHUTDOWN Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); Event.dwEvent = 11; Event.pszEventName = L"ANCM_INPROC_REQUEST_SHUTDOWN"; @@ -770,30 +768,30 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[1]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 1 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 4); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 4 ); //Verbosity }; }; // @@ -803,23 +801,23 @@ public: // EventType: 12 // EventLevel: 4 // - + class ANCM_INPROC_REQUEST_DISCONNECT { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId - ) - // - // Raise ANCM_INPROC_REQUEST_DISCONNECT Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId + ) + // + // Raise ANCM_INPROC_REQUEST_DISCONNECT Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); Event.dwEvent = 12; Event.pszEventName = L"ANCM_INPROC_REQUEST_DISCONNECT"; @@ -830,58 +828,58 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[1]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 1 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 4); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 4 ); //Verbosity }; }; // // Event: mof class name ANCMManagedRequestCompletion, // Description: Indicate managed request complete // EventTypeName: ANCM_INPROC_MANAGED_REQUEST_COMPLETION - // EventType: 12 + // EventType: 13 // EventLevel: 4 // - + class ANCM_INPROC_MANAGED_REQUEST_COMPLETION { public: static - HRESULT - RaiseEvent( - IHttpTraceContext * pHttpTraceContext, - LPCGUID pContextId - ) - // - // Raise ANCM_INPROC_MANAGED_REQUEST_COMPLETION Event - // + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId + ) + // + // Raise ANCM_INPROC_MANAGED_REQUEST_COMPLETION Event + // { HTTP_TRACE_EVENT Event; Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); - Event.dwArea = WWWServerTraceProvider::ANCM; + Event.dwArea = WWWServerTraceProvider::ANCM; Event.pAreaGuid = ANCMEvents::GetAreaGuid(); - Event.dwEvent = 12; + Event.dwEvent = 13; Event.pszEventName = L"ANCM_INPROC_MANAGED_REQUEST_COMPLETION"; Event.dwEventVersion = 1; Event.dwVerbosity = 4; @@ -890,31 +888,190 @@ public: Event.pRelatedActivityGuid = NULL; Event.dwTimeStamp = 0; Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; - + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS - - HTTP_TRACE_EVENT_ITEM Items[1]; - Items[0].pszName = L"ContextId"; - Items[0].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) - Items[0].pbData = (PBYTE)pContextId; - Items[0].cbData = 16; - Items[0].pszDataDescription = NULL; + + HTTP_TRACE_EVENT_ITEM Items[ 1 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; Event.pEventItems = Items; - pHttpTraceContext->RaiseTraceEvent(&Event); + pHttpTraceContext->RaiseTraceEvent( &Event ); return S_OK; }; - + static - BOOL - IsEnabled( - IHttpTraceContext * pHttpTraceContext) - // Check if tracing for this event is enabled + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled { - return WWWServerTraceProvider::CheckTracingEnabled( - pHttpTraceContext, - WWWServerTraceProvider::ANCM, - 4); //Verbosity + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 4 ); //Verbosity + }; + }; + // + // Event: mof class name ANCMHRESULTFailed, + // Description: Failed HRESULT + // EventTypeName: ANCM_HRESULT_FAILED + // EventType: 14 + // EventLevel: 3 + // + + class ANCM_HRESULT_FAILED + { + public: + static + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId, + LPCSTR pFile, + ULONG Line, + ULONG HResult + ) + // + // Raise ANCM_HRESULT_FAILED Event + // + { + HTTP_TRACE_EVENT Event; + Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); + Event.dwArea = WWWServerTraceProvider::ANCM; + Event.pAreaGuid = ANCMEvents::GetAreaGuid(); + Event.dwEvent = 14; + Event.pszEventName = L"ANCM_HRESULT_FAILED"; + Event.dwEventVersion = 1; + Event.dwVerbosity = 3; + Event.cEventItems = 4; + Event.pActivityGuid = NULL; + Event.pRelatedActivityGuid = NULL; + Event.dwTimeStamp = 0; + Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; + + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS + + HTTP_TRACE_EVENT_ITEM Items[ 4 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; + Items[ 1 ].pszName = L"File"; + Items[ 1 ].dwDataType = HTTP_TRACE_TYPE_LPCSTR; // mof type (string) + Items[ 1 ].pbData = (PBYTE) pFile; + Items[ 1 ].cbData = + ( Items[ 1 ].pbData == NULL )? 0 : (1 + (DWORD) strlen( (PSTR) Items[ 1 ].pbData ) ); + Items[ 1 ].pszDataDescription = NULL; + Items[ 2 ].pszName = L"Line"; + Items[ 2 ].dwDataType = HTTP_TRACE_TYPE_ULONG; // mof type (uint32) + Items[ 2 ].pbData = (PBYTE) &Line; + Items[ 2 ].cbData = 4; + Items[ 2 ].pszDataDescription = NULL; + Items[ 3 ].pszName = L"HResult"; + Items[ 3 ].dwDataType = HTTP_TRACE_TYPE_ULONG; // mof type (uint32) + Items[ 3 ].pbData = (PBYTE) &HResult; + Items[ 3 ].cbData = 4; + Items[ 3 ].pszDataDescription = NULL; + Event.pEventItems = Items; + pHttpTraceContext->RaiseTraceEvent( &Event ); + return S_OK; + }; + + static + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled + { + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 3 ); //Verbosity + }; + }; + // + // Event: mof class name ANCMExceptionCaughFailed, + // Description: Caught exception + // EventTypeName: ANCM_EXCEPTION_CAUGHT + // EventType: 15 + // EventLevel: 3 + // + + class ANCM_EXCEPTION_CAUGHT + { + public: + static + HRESULT + RaiseEvent( + IHttpTraceContext * pHttpTraceContext, + LPCGUID pContextId, + LPCSTR pFile, + ULONG Line, + LPCSTR pDescription + ) + // + // Raise ANCM_EXCEPTION_CAUGHT Event + // + { + HTTP_TRACE_EVENT Event; + Event.pProviderGuid = WWWServerTraceProvider::GetProviderGuid(); + Event.dwArea = WWWServerTraceProvider::ANCM; + Event.pAreaGuid = ANCMEvents::GetAreaGuid(); + Event.dwEvent = 15; + Event.pszEventName = L"ANCM_EXCEPTION_CAUGHT"; + Event.dwEventVersion = 1; + Event.dwVerbosity = 3; + Event.cEventItems = 4; + Event.pActivityGuid = NULL; + Event.pRelatedActivityGuid = NULL; + Event.dwTimeStamp = 0; + Event.dwFlags = HTTP_TRACE_EVENT_FLAG_STATIC_DESCRIPTIVE_FIELDS; + + // pActivityGuid, pRelatedActivityGuid, Timestamp to be filled in by IIS + + HTTP_TRACE_EVENT_ITEM Items[ 4 ]; + Items[ 0 ].pszName = L"ContextId"; + Items[ 0 ].dwDataType = HTTP_TRACE_TYPE_LPCGUID; // mof type (object) + Items[ 0 ].pbData = (PBYTE) pContextId; + Items[ 0 ].cbData = 16; + Items[ 0 ].pszDataDescription = NULL; + Items[ 1 ].pszName = L"File"; + Items[ 1 ].dwDataType = HTTP_TRACE_TYPE_LPCSTR; // mof type (string) + Items[ 1 ].pbData = (PBYTE) pFile; + Items[ 1 ].cbData = + ( Items[ 1 ].pbData == NULL )? 0 : (1 + (DWORD) strlen( (PSTR) Items[ 1 ].pbData ) ); + Items[ 1 ].pszDataDescription = NULL; + Items[ 2 ].pszName = L"Line"; + Items[ 2 ].dwDataType = HTTP_TRACE_TYPE_ULONG; // mof type (uint32) + Items[ 2 ].pbData = (PBYTE) &Line; + Items[ 2 ].cbData = 4; + Items[ 2 ].pszDataDescription = NULL; + Items[ 3 ].pszName = L"Description"; + Items[ 3 ].dwDataType = HTTP_TRACE_TYPE_LPCSTR; // mof type (string) + Items[ 3 ].pbData = (PBYTE) pDescription; + Items[ 3 ].cbData = + ( Items[ 3 ].pbData == NULL )? 0 : (1 + (DWORD) strlen( (PSTR) Items[ 3 ].pbData ) ); + Items[ 3 ].pszDataDescription = NULL; + Event.pEventItems = Items; + pHttpTraceContext->RaiseTraceEvent( &Event ); + return S_OK; + }; + + static + BOOL + IsEnabled( + IHttpTraceContext * pHttpTraceContext ) + // Check if tracing for this event is enabled + { + return WWWServerTraceProvider::CheckTracingEnabled( + pHttpTraceContext, + WWWServerTraceProvider::ANCM, + 3 ); //Verbosity }; }; }; -#endif +#endif \ No newline at end of file diff --git a/src/AspNetCoreModuleV2/CommonLib/exceptions.h b/src/AspNetCoreModuleV2/CommonLib/exceptions.h index f79b9e99e5..18115c0e48 100644 --- a/src/AspNetCoreModuleV2/CommonLib/exceptions.h +++ b/src/AspNetCoreModuleV2/CommonLib/exceptions.h @@ -9,6 +9,9 @@ #include "debugutil.h" #include "StringHelpers.h" #include "InvalidOperationException.h" +#include "ntassert.h" +#include "NonCopyable.h" +#include "EventTracing.h" #define LOCATION_INFO_ENABLED TRUE @@ -53,7 +56,7 @@ __pragma(warning(pop)) -#define FINISHED(hrr) do { _HR_RET(hrr); if (_CHECK_FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); } hr = __hrRet; _GOTO_FINISHED(); } while (0, 0) +#define FINISHED(hrr) do { _HR_RET(hrr); if (_CHECK_FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); } hr = __hrRet; _GOTO_FINISHED(); } while (0, 0) #define FINISHED_IF_FAILED(hrr) do { _HR_RET(hrr); if (FAILED(__hrRet)) { LogHResultFailed(LOCATION_INFO, __hrRet); hr = __hrRet; _GOTO_FINISHED(); }} while (0, 0) #define FINISHED_IF_NULL_ALLOC(ptr) do { if ((ptr) == nullptr) { hr = LogHResultFailed(LOCATION_INFO, E_OUTOFMEMORY); _GOTO_FINISHED(); }} while (0, 0) #define FINISHED_LAST_ERROR_IF(condition) do { if (condition) { hr = LogLastError(LOCATION_INFO); _GOTO_FINISHED(); }} while (0, 0) @@ -74,6 +77,18 @@ #define SUCCEEDED_LOG(hr) SUCCEEDED(LOG_IF_FAILED(hr)) #define FAILED_LOG(hr) FAILED(LOG_IF_FAILED(hr)) +inline thread_local IHttpTraceContext* g_traceContext; + + __declspec(noinline) inline VOID TraceHRESULT(LOCATION_ARGUMENTS HRESULT hr) +{ + ::RaiseEvent(g_traceContext, nullptr, fileName, lineNumber, hr); +} + + __declspec(noinline) inline VOID TraceException(LOCATION_ARGUMENTS const std::exception& exception) +{ + ::RaiseEvent(g_traceContext, nullptr, fileName, lineNumber, exception.what()); +} + class ResultException: public std::runtime_error { public: @@ -86,7 +101,7 @@ public: HRESULT GetResult() const noexcept { return m_hr; } private: - + #pragma warning( push ) #pragma warning ( disable : 26495 ) // bug in CA: m_hr is reported as uninitialized const HRESULT m_hr = S_OK; @@ -103,6 +118,7 @@ private: const auto lastError = GetLastError(); const auto hr = HRESULT_FROM_WIN32(lastError); + TraceHRESULT(LOCATION_CALL hr); DebugPrintf(ASPNETCORE_DEBUG_FLAG_ERROR, LOCATION_FORMAT "Operation failed with LastError: %d HR: 0x%x", LOCATION_CALL lastError, hr); return hr; @@ -120,6 +136,7 @@ private: __declspec(noinline) inline VOID ReportException(LOCATION_ARGUMENTS const std::exception& exception) { + TraceException(LOCATION_CALL exception); DebugPrintf(ASPNETCORE_DEBUG_FLAG_ERROR, "Exception '%s' caught at " LOCATION_FORMAT, exception.what(), LOCATION_CALL_ONLY); } @@ -127,6 +144,7 @@ private: { if (FAILED(hr)) { + TraceHRESULT(LOCATION_CALL hr); DebugPrintf(ASPNETCORE_DEBUG_FLAG_ERROR, "Failed HRESULT returned: 0x%x at " LOCATION_FORMAT, hr, LOCATION_CALL_ONLY); } return hr; @@ -178,3 +196,21 @@ __declspec(noinline) inline std::wstring GetUnexpectedExceptionMessage(const std { return format(L"Unexpected exception: %S", ex.what()); } + +class TraceContextScope: NonCopyable +{ +public: + TraceContextScope(IHttpTraceContext* pTraceContext) noexcept + { + m_pPreviousTraceContext = g_traceContext; + g_traceContext = pTraceContext; + } + + ~TraceContextScope() + { + g_traceContext = m_pPreviousTraceContext; + } + private: + IHttpTraceContext* m_pPreviousTraceContext; +}; + diff --git a/src/AspNetCoreModuleV2/CommonLib/iapplication.h b/src/AspNetCoreModuleV2/CommonLib/iapplication.h index 2e8660748f..52a1a7e2a9 100644 --- a/src/AspNetCoreModuleV2/CommonLib/iapplication.h +++ b/src/AspNetCoreModuleV2/CommonLib/iapplication.h @@ -9,7 +9,7 @@ struct APPLICATION_PARAMETER { LPCSTR pzName; - const void *pValue; + void *pValue; }; class IAPPLICATION @@ -61,3 +61,15 @@ std::unique_ptr make_application(Params&&... #pragma warning( pop ) } +template< class TYPE > +TYPE FindParameter(LPCSTR sRequiredParameter, APPLICATION_PARAMETER *pParameters, DWORD nParameters) +{ + for (DWORD i = 0; i < nParameters; i++) + { + if (_stricmp(pParameters[i].pzName, sRequiredParameter) == 0) + { + return reinterpret_cast(pParameters[i].pValue); + } + } + return nullptr; +} diff --git a/src/AspNetCoreModuleV2/CommonLib/requesthandler.h b/src/AspNetCoreModuleV2/CommonLib/requesthandler.h index a5e16bf022..8bac2885b0 100644 --- a/src/AspNetCoreModuleV2/CommonLib/requesthandler.h +++ b/src/AspNetCoreModuleV2/CommonLib/requesthandler.h @@ -5,14 +5,22 @@ #include "irequesthandler.h" #include "ntassert.h" +#include "exceptions.h" // // Pure abstract class // class REQUEST_HANDLER: public virtual IREQUEST_HANDLER { - public: + REQUEST_HANDLER(IHttpContext& pHttpContext) noexcept : m_pHttpContext(pHttpContext) + { + } + + virtual + REQUEST_NOTIFICATION_STATUS + ExecuteRequestHandler() = 0; + VOID ReferenceRequestHandler() noexcept override { @@ -30,7 +38,26 @@ public: } } - REQUEST_NOTIFICATION_STATUS OnAsyncCompletion(DWORD cbCompletion, HRESULT hrCompletionStatus) override + + REQUEST_NOTIFICATION_STATUS + OnExecuteRequestHandler() final + { + TraceContextScope traceScope(m_pHttpContext.GetTraceContext()); + return ExecuteRequestHandler(); + } + + REQUEST_NOTIFICATION_STATUS + OnAsyncCompletion( + DWORD cbCompletion, + HRESULT hrCompletionStatus + ) final + { + TraceContextScope traceScope(m_pHttpContext.GetTraceContext()); + return AsyncCompletion(cbCompletion, hrCompletionStatus); + }; + + virtual + REQUEST_NOTIFICATION_STATUS AsyncCompletion(DWORD cbCompletion, HRESULT hrCompletionStatus) { UNREFERENCED_PARAMETER(cbCompletion); UNREFERENCED_PARAMETER(hrCompletionStatus); @@ -47,5 +74,6 @@ public: } private: - mutable LONG m_cRefs = 1; + IHttpContext& m_pHttpContext; + mutable LONG m_cRefs = 1; }; diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/ShuttingDownApplication.h b/src/AspNetCoreModuleV2/InProcessRequestHandler/ShuttingDownApplication.h index 6195877234..171ad4a2ef 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/ShuttingDownApplication.h +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/ShuttingDownApplication.h @@ -8,11 +8,13 @@ class ShuttingDownHandler : public REQUEST_HANDLER { public: - ShuttingDownHandler(IHttpContext* pContext) : m_pContext(pContext) + ShuttingDownHandler(IHttpContext* pContext) + : REQUEST_HANDLER(*pContext), + m_pContext(pContext) { } - REQUEST_NOTIFICATION_STATUS OnExecuteRequestHandler() override + REQUEST_NOTIFICATION_STATUS ExecuteRequestHandler() override { return ServerShutdownMessage(m_pContext); } diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp b/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp index aafb2c799f..eb84da2869 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp @@ -17,7 +17,6 @@ #include "WebConfigConfigurationSource.h" #include "ConfigurationLoadException.h" #include "StartupExceptionApplication.h" -#include "aspnetcore_event.h" DECLARE_DEBUG_PRINT_OBJECT("aspnetcorev2_inprocess.dll"); @@ -100,6 +99,7 @@ CreateApplication( _Out_ IAPPLICATION **ppApplication ) { + TraceContextScope traceScope(FindParameter("TraceContext", pParameters, nParameters)); try { HRESULT hr = S_OK; diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp index 44d2455251..c351dbc4c1 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocessapplication.cpp @@ -28,12 +28,10 @@ IN_PROCESS_APPLICATION::IN_PROCESS_APPLICATION( { DBG_ASSERT(m_pConfig); - for (DWORD i = 0; i < nParameters; i++) + const auto knownLocation = FindParameter(s_exeLocationParameterName, pParameters, nParameters); + if (knownLocation != nullptr) { - if (_stricmp(pParameters[i].pzName, s_exeLocationParameterName) == 0) - { - m_dotnetExeKnownLocation = reinterpret_cast(pParameters[i].pValue); - } + m_dotnetExeKnownLocation = knownLocation; } } diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp index 16938d0009..8fee377a30 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.cpp @@ -6,18 +6,18 @@ #include "IOutputManager.h" #include "ShuttingDownApplication.h" #include "ntassert.h" -#include "ModuleTracer.h" ALLOC_CACHE_HANDLER * IN_PROCESS_HANDLER::sm_pAlloc = NULL; IN_PROCESS_HANDLER::IN_PROCESS_HANDLER( _In_ std::unique_ptr pApplication, - _In_ IHttpContext *pW3Context, + _In_ IHttpContext *pW3Context, _In_ PFN_REQUEST_HANDLER pRequestHandler, _In_ void * pRequestHandlerContext, _In_ PFN_DISCONNECT_HANDLER pDisconnectHandler, _In_ PFN_ASYNC_COMPLETION_HANDLER pAsyncCompletion -): m_pManagedHttpContext(nullptr), +): REQUEST_HANDLER(*pW3Context), + m_pManagedHttpContext(nullptr), m_requestNotificationStatus(RQ_NOTIFICATION_PENDING), m_fManagedRequestComplete(FALSE), m_pW3Context(pW3Context), @@ -26,7 +26,6 @@ IN_PROCESS_HANDLER::IN_PROCESS_HANDLER( m_pRequestHandlerContext(pRequestHandlerContext), m_pAsyncCompletionHandler(pAsyncCompletion), m_pDisconnectHandler(pDisconnectHandler), - m_moduleTracer(pW3Context->GetTraceContext()), m_disconnectFired(false) { InitializeSRWLock(&m_srwDisconnectLock); @@ -34,14 +33,13 @@ IN_PROCESS_HANDLER::IN_PROCESS_HANDLER( __override REQUEST_NOTIFICATION_STATUS -IN_PROCESS_HANDLER::OnExecuteRequestHandler() +IN_PROCESS_HANDLER::ExecuteRequestHandler() { - // FREB log - m_moduleTracer.ExecuteRequestStart(); + ::RaiseEvent(m_pW3Context, nullptr); if (m_pRequestHandler == NULL) { - m_moduleTracer.ExecuteRequestEnd(RQ_NOTIFICATION_FINISH_REQUEST); + ::RaiseEvent(m_pW3Context, nullptr, RQ_NOTIFICATION_FINISH_REQUEST); return RQ_NOTIFICATION_FINISH_REQUEST; } else if (m_pApplication->QueryBlockCallbacksIntoManaged()) @@ -50,24 +48,25 @@ IN_PROCESS_HANDLER::OnExecuteRequestHandler() } auto status = m_pRequestHandler(this, m_pRequestHandlerContext); - m_moduleTracer.ExecuteRequestEnd(status); + ::RaiseEvent(m_pW3Context, nullptr, status); return status; } __override REQUEST_NOTIFICATION_STATUS -IN_PROCESS_HANDLER::OnAsyncCompletion( +IN_PROCESS_HANDLER::AsyncCompletion( DWORD cbCompletion, HRESULT hrCompletionStatus ) { - m_moduleTracer.AsyncCompletionStart(); + + ::RaiseEvent(m_pW3Context, nullptr); if (m_fManagedRequestComplete) { // means PostCompletion has been called and this is the associated callback. - m_moduleTracer.AsyncCompletionEnd(m_requestNotificationStatus); - return m_requestNotificationStatus; + ::RaiseEvent(m_pW3Context, nullptr, m_requestNotificationStatus); + return m_requestNotificationStatus; } if (m_pApplication->QueryBlockCallbacksIntoManaged()) { @@ -81,20 +80,20 @@ IN_PROCESS_HANDLER::OnAsyncCompletion( // Call the managed handler for async completion. auto status = m_pAsyncCompletionHandler(m_pManagedHttpContext, hrCompletionStatus, cbCompletion); - m_moduleTracer.AsyncCompletionEnd(status); + ::RaiseEvent(m_pW3Context, nullptr, status); return status; } -REQUEST_NOTIFICATION_STATUS IN_PROCESS_HANDLER::ServerShutdownMessage() +REQUEST_NOTIFICATION_STATUS IN_PROCESS_HANDLER::ServerShutdownMessage() const { - m_moduleTracer.RequestShutdown(); + ::RaiseEvent(m_pW3Context, nullptr); return ShuttingDownHandler::ServerShutdownMessage(m_pW3Context); } VOID IN_PROCESS_HANDLER::NotifyDisconnect() { - m_moduleTracer.RequestDisconnect(); + ::RaiseEvent(m_pW3Context, nullptr); if (m_pApplication->QueryBlockCallbacksIntoManaged() || m_fManagedRequestComplete) @@ -126,7 +125,7 @@ IN_PROCESS_HANDLER::IndicateManagedRequestComplete( { m_fManagedRequestComplete = TRUE; m_pManagedHttpContext = nullptr; - m_moduleTracer.ManagedCompletion(); + ::RaiseEvent(m_pW3Context, nullptr); } VOID diff --git a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.h b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.h index 743c2323a1..20a5192c18 100644 --- a/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.h +++ b/src/AspNetCoreModuleV2/InProcessRequestHandler/inprocesshandler.h @@ -7,7 +7,6 @@ #include #include "iapplication.h" #include "inprocessapplication.h" -#include "ModuleTracer.h" class IN_PROCESS_APPLICATION; @@ -26,11 +25,11 @@ public: __override REQUEST_NOTIFICATION_STATUS - OnExecuteRequestHandler() override; + ExecuteRequestHandler() override; __override REQUEST_NOTIFICATION_STATUS - OnAsyncCompletion( + AsyncCompletion( DWORD cbCompletion, HRESULT hrCompletionStatus ) override; @@ -72,7 +71,7 @@ public: private: REQUEST_NOTIFICATION_STATUS - ServerShutdownMessage(); + ServerShutdownMessage() const; PVOID m_pManagedHttpContext; BOOL m_fManagedRequestComplete; @@ -84,7 +83,6 @@ private: PFN_ASYNC_COMPLETION_HANDLER m_pAsyncCompletionHandler; PFN_DISCONNECT_HANDLER m_pDisconnectHandler; static ALLOC_CACHE_HANDLER * sm_pAlloc; - ModuleTracer m_moduleTracer; bool m_disconnectFired; SRWLOCK m_srwDisconnectLock; }; diff --git a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp index 24c166a056..981e3acd36 100644 --- a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp +++ b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/dllmain.cpp @@ -250,8 +250,7 @@ CreateApplication( _Out_ IAPPLICATION **ppApplication ) { - UNREFERENCED_PARAMETER(pParameters); - UNREFERENCED_PARAMETER(nParameters); + TraceContextScope traceScope(FindParameter("TraceContext", pParameters, nParameters)); InitializeGlobalConfiguration(pServer); diff --git a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp index d97a55a17e..c8c0640803 100644 --- a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp +++ b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.cpp @@ -26,7 +26,7 @@ RESPONSE_HEADER_HASH * FORWARDING_HANDLER::sm_pResponseHeaderHash = NULL; FORWARDING_HANDLER::FORWARDING_HANDLER( _In_ IHttpContext *pW3Context, _In_ std::unique_ptr pApplication -) : REQUEST_HANDLER(), +) : REQUEST_HANDLER(*pW3Context), m_Signature(FORWARDING_HANDLER_SIGNATURE), m_RequestStatus(FORWARDER_START), m_fClientDisconnected(FALSE), @@ -90,7 +90,7 @@ FORWARDING_HANDLER::~FORWARDING_HANDLER( __override REQUEST_NOTIFICATION_STATUS -FORWARDING_HANDLER::OnExecuteRequestHandler() +FORWARDING_HANDLER::ExecuteRequestHandler() { REQUEST_NOTIFICATION_STATUS retVal = RQ_NOTIFICATION_CONTINUE; HRESULT hr = S_OK; @@ -320,7 +320,7 @@ Failure: else if (fFailedToStartKestrel && !m_pApplication->QueryConfig()->QueryDisableStartUpErrorPage()) { ServerErrorHandler handler(*m_pW3Context, 502, 5, "Bad Gateway", hr, g_hOutOfProcessRHModule, m_pApplication->QueryConfig()->QueryDisableStartUpErrorPage(), OUT_OF_PROCESS_RH_STATIC_HTML); - handler.OnExecuteRequestHandler(); + handler.ExecuteRequestHandler(); } else { @@ -353,7 +353,7 @@ Finished: __override REQUEST_NOTIFICATION_STATUS -FORWARDING_HANDLER::OnAsyncCompletion( +FORWARDING_HANDLER::AsyncCompletion( DWORD cbCompletion, HRESULT hrCompletionStatus ) diff --git a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.h b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.h index e30d69b6c0..cc855dfcf2 100644 --- a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.h +++ b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/forwardinghandler.h @@ -30,11 +30,11 @@ public: __override REQUEST_NOTIFICATION_STATUS - OnExecuteRequestHandler(); + ExecuteRequestHandler(); __override REQUEST_NOTIFICATION_STATUS - OnAsyncCompletion( + AsyncCompletion( DWORD cbCompletion, HRESULT hrCompletionStatus ); diff --git a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/stdafx.h b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/stdafx.h index 0134ac111e..91b6b002dc 100644 --- a/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/stdafx.h +++ b/src/AspNetCoreModuleV2/OutOfProcessRequestHandler/stdafx.h @@ -57,7 +57,7 @@ #include "requesthandler.h" #include "application.h" #include "resources.h" -#include "aspnetcore_event.h" +#include "EventTracing.h" #include "aspnetcore_msg.h" #include "requesthandler_config.h" diff --git a/test/Common.FunctionalTests/Inprocess/FrebTests.cs b/test/Common.FunctionalTests/Inprocess/FrebTests.cs index 2143659e33..12e2f6ae53 100644 --- a/test/Common.FunctionalTests/Inprocess/FrebTests.cs +++ b/test/Common.FunctionalTests/Inprocess/FrebTests.cs @@ -49,6 +49,22 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests AssertFrebLogs(result, FrebChecks()); } + [ConditionalFact] + [RequiresNewShim] + [RequiresIIS(IISCapability.FailedRequestTracingModule)] + public async Task FrebIncludesHResultFailures() + { + var parameters = _fixture.GetBaseDeploymentParameters(publish: true); + parameters.TransformArguments((args, _) => string.Empty); + var result = await SetupFrebApp(parameters); + + await result.HttpClient.GetAsync("HelloWorld"); + + StopServer(); + + AssertFrebLogs(result, new FrebLogItem("ANCM_HRESULT_FAILED"), new FrebLogItem("ANCM_EXCEPTION_CAUGHT")); + } + [ConditionalFact] [RequiresIIS(IISCapability.FailedRequestTracingModule)] public async Task CheckFailedRequestEvents() @@ -86,9 +102,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests AssertFrebLogs(result, new FrebLogItem("ANCM_INPROC_REQUEST_DISCONNECT"), new FrebLogItem("ANCM_INPROC_MANAGED_REQUEST_COMPLETION")); } - private async Task SetupFrebApp() + private async Task SetupFrebApp(IISDeploymentParameters parameters = null) { - var parameters = _fixture.GetBaseDeploymentParameters(publish: true); + parameters = parameters ?? _fixture.GetBaseDeploymentParameters(publish: true); parameters.EnableFreb("Verbose", _logFolderPath); Directory.CreateDirectory(_logFolderPath); diff --git a/test/Common.FunctionalTests/LogFileTests.cs b/test/Common.FunctionalTests/LogFileTests.cs index 829a736b6e..1e15cde5c2 100644 --- a/test/Common.FunctionalTests/LogFileTests.cs +++ b/test/Common.FunctionalTests/LogFileTests.cs @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests var deploymentResult = await DeployAsync(deploymentParameters); await Helpers.AssertStarts(deploymentResult, path); - + StopServer(); var contents = Helpers.ReadAllTextFromFile(Helpers.GetExpectedLogName(deploymentResult, _logFolderPath), Logger);