terminal/src/inc/WilErrorReporting.h

67 lines
4.7 KiB
C
Raw Normal View History

/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- WilErrorReporting.h
--*/
#pragma once
#include <winmeta.h>
#include <wil/common.h>
#define CONSOLE_WIL_TRACELOGGING_COMMON_FAILURE_PARAMS(failure) \
TraceLoggingUInt32((failure).hr, "hresult", "Failure error code"), \
TraceLoggingString((failure).pszFile, "fileName", "Source code file name where the error occurred"), \
TraceLoggingUInt32((failure).uLineNumber, "lineNumber", "Line number within the source code file where the error occurred"), \
TraceLoggingString((failure).pszModule, "module", "Name of the binary where the error occurred"), \
TraceLoggingUInt32(static_cast<DWORD>((failure).type), "failureType", "Indicates what type of failure was observed (exception, returned error, logged error or fail fast"), \
TraceLoggingWideString((failure).pszMessage, "message", "Custom message associated with the failure (if any)"), \
TraceLoggingUInt32((failure).threadId, "threadId", "Identifier of the thread the error occurred on"), \
TraceLoggingString((failure).pszCallContext, "callContext", "List of containing this error"), \
TraceLoggingUInt32((failure).callContextOriginating.contextId, "originatingContextId", "Identifier for the oldest activity containing this error"), \
TraceLoggingString((failure).callContextOriginating.contextName, "originatingContextName", "Name of the oldest activity containing this error"), \
TraceLoggingWideString((failure).callContextOriginating.contextMessage, "originatingContextMessage", "Custom message associated with the oldest activity containing this error (if any)"), \
TraceLoggingUInt32((failure).callContextCurrent.contextId, "currentContextId", "Identifier for the newest activity containing this error"), \
TraceLoggingString((failure).callContextCurrent.contextName, "currentContextName", "Name of the newest activity containing this error"), \
TraceLoggingWideString((failure).callContextCurrent.contextMessage, "currentContextMessage", "Custom message associated with the newest activity containing this error (if any)")
#define CONSOLE_WIL_TRACELOGGING_FAILURE_PARAMS(failure) \
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance), \
TraceLoggingStruct(14, "wilResult"), \
CONSOLE_WIL_TRACELOGGING_COMMON_FAILURE_PARAMS(failure)
namespace Microsoft::Console::ErrorReporting
{
__declspec(selectany) TraceLoggingHProvider FallbackProvider;
__declspec(noinline) inline void WINAPI ReportFailureToFallbackProvider(bool alreadyReported, const wil::FailureInfo& failure) noexcept
try
{
if (!alreadyReported && FallbackProvider)
{
#pragma warning(suppress : 26477 26485 26494 26482 26446) // We don't control TraceLoggingWrite
Set keyword flags on all tracelog events (#10098) Set keyword flags on all events so those sharing a provider with telemetry do not fire unless tracing is enabled ## PR Checklist * [x] Closes #10093 * [x] I work here * [x] Tests passed * [x] Documentation added in `til.h` about how keywords work and at the only other site of keywords we define in the Host project tracing files. ## Detailed Description of the Pull Request / Additional comments I initially thought that we would need to split providers here to accomplish this... but @DHowett helped me realize that might be a lot of additional metadata and bloat binary size. So with help from a friend from fundamentals, I realized that we could use Keywords to differentiate here. We can no longer define 0 keywords as that represents an any/all scenario. Every `TraceLoggingWrite` event now needs a keyword. When our events have a keyword, they're not included in any trace. Additionally, when we have an explicit keyword to check that is different from the ones used for the telemetry pipeline, we can ensure that we only do "hard work" to generate debug trace data when an "ALL" type listener like TraceView or Windows Performance Recorder with our profiles is listening to these providers for ALL keyworded events. ## Validation Steps Performed - [x] - Built with full release build config to confirm performance is worse than dev builds BECAUSE of the telemetry event collector camping our provider and triggering full trace event generation on shared providers. - [x] - Built with full release build config to enable statistics collection and validated trace event collection is excluded and trace event short-circuits work with this change. - [x] - Checked that TraceView still sees both telemetry and tracing events - [x] - Checked that WPR with our .wprp profile sees both telemetry and tracing events
2021-05-15 01:14:26 +02:00
TraceLoggingWrite(FallbackProvider,
"FallbackError",
TraceLoggingKeyword(MICROSOFT_KEYWORD_TELEMETRY),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage),
TraceLoggingLevel(WINEVENT_LEVEL_ERROR),
CONSOLE_WIL_TRACELOGGING_FAILURE_PARAMS(failure));
}
}
catch (...)
{
// Don't log anything. We just failed to trace, where will we go now?
}
__declspec(noinline) inline void EnableFallbackFailureReporting(TraceLoggingHProvider provider) noexcept
try
{
FallbackProvider = provider;
::wil::SetResultTelemetryFallback(::Microsoft::Console::ErrorReporting::ReportFailureToFallbackProvider);
}
catch (...)
{
// Don't log anything. We just failed to set up WIL -- how are we going to log anything?
}
}