diff --git a/.github/actions/spelling/patterns.txt b/.github/actions/spelling/patterns.txt index 6cf1760181..74ab869cb3 100644 --- a/.github/actions/spelling/patterns.txt +++ b/.github/actions/spelling/patterns.txt @@ -32,4 +32,4 @@ El proyecto .* diferentes http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer # schema regex -"pattern": .*$ \ No newline at end of file +"pattern": .*$ diff --git a/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp b/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp index d0d4cce4f9..965d71445f 100644 --- a/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp +++ b/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp @@ -6,6 +6,7 @@ #include "Public/AppInstallerRuntime.h" #include "Public/AppInstallerSHA256.h" #include "Public/AppInstallerStrings.h" +#include "winget/UserSettings.h" #define AICLI_TraceLoggingStringView(_sv_,_name_) TraceLoggingCountedUtf8String(_sv_.data(), static_cast(_sv_.size()), _name_) @@ -34,18 +35,10 @@ namespace AppInstaller::Logging { static const uint32_t s_RootExecutionId = 0; - // Used to disable telemetry on the fly. - std::atomic_bool s_isTelemetryEnabled{ true }; - std::atomic_uint32_t s_executionStage{ 0 }; std::atomic_uint32_t s_subExecutionId{ s_RootExecutionId }; - bool IsTelemetryEnabled() - { - return g_IsTelemetryProviderEnabled && s_isTelemetryEnabled; - } - void __stdcall wilResultLoggingCallback(const wil::FailureInfo& info) noexcept { Telemetry().LogFailure(info); @@ -67,7 +60,10 @@ namespace AppInstaller::Logging TelemetryTraceLogger::TelemetryTraceLogger() { + // TODO: Needs to be made a singleton registration/removal in the future RegisterTraceLogging(); + + m_isSettingEnabled = !Settings::User().Get(); } TelemetryTraceLogger::~TelemetryTraceLogger() @@ -81,6 +77,16 @@ namespace AppInstaller::Logging return instance; } + bool TelemetryTraceLogger::DisableRuntime() + { + return m_isRuntimeEnabled.exchange(false); + } + + void TelemetryTraceLogger::EnableRuntime() + { + m_isRuntimeEnabled = true; + } + void TelemetryTraceLogger::LogFailure(const wil::FailureInfo& failure) const noexcept { if (IsTelemetryEnabled()) @@ -500,6 +506,11 @@ namespace AppInstaller::Logging } } + bool TelemetryTraceLogger::IsTelemetryEnabled() const noexcept + { + return g_IsTelemetryProviderEnabled && m_isSettingEnabled && m_isRuntimeEnabled; + } + #ifndef AICLI_DISABLE_TEST_HOOKS static std::shared_ptr s_TelemetryTraceLogger_TestOverride; #endif @@ -523,14 +534,14 @@ namespace AppInstaller::Logging DisableTelemetryScope::DisableTelemetryScope() { - m_token = s_isTelemetryEnabled.exchange(false); + m_token = Telemetry().DisableRuntime(); } DisableTelemetryScope::~DisableTelemetryScope() { if (m_token) { - s_isTelemetryEnabled = true; + Telemetry().EnableRuntime(); } } diff --git a/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h b/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h index 3eadd93380..4564819481 100644 --- a/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h +++ b/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h @@ -26,6 +26,10 @@ namespace AppInstaller::Logging // Gets the singleton instance of this type. static TelemetryTraceLogger& GetInstance(); + // Control whether this trace logger is enabled at runtime. + bool DisableRuntime(); + void EnableRuntime(); + // Logs the failure info. void LogFailure(const wil::FailureInfo& failure) const noexcept; @@ -112,6 +116,11 @@ namespace AppInstaller::Logging protected: TelemetryTraceLogger(); + + bool IsTelemetryEnabled() const noexcept; + + bool m_isSettingEnabled = true; + std::atomic_bool m_isRuntimeEnabled{ true }; }; // Helper to make the call sites look clean. diff --git a/src/AppInstallerCommonCore/Public/winget/UserSettings.h b/src/AppInstallerCommonCore/Public/winget/UserSettings.h index 37a9230a61..088c7a3a28 100644 --- a/src/AppInstallerCommonCore/Public/winget/UserSettings.h +++ b/src/AppInstallerCommonCore/Public/winget/UserSettings.h @@ -10,11 +10,11 @@ #include #include +using namespace std::chrono_literals; +using namespace std::string_view_literals; + namespace AppInstaller::Settings { - using namespace std::chrono_literals; - using namespace std::string_view_literals; - // The type of argument. enum class UserSettingsType { @@ -54,6 +54,7 @@ namespace AppInstaller::Settings EFUninstall, EFImport, EFExport, + TelemetryDisable, Max }; @@ -91,6 +92,7 @@ namespace AppInstaller::Settings SETTINGMAPPING_SPECIALIZATION(Setting::EFUninstall, bool, bool, false, ".experimentalFeatures.uninstall"sv); SETTINGMAPPING_SPECIALIZATION(Setting::EFImport, bool, bool, false, ".experimentalFeatures.import"sv); SETTINGMAPPING_SPECIALIZATION(Setting::EFExport, bool, bool, false, ".experimentalFeatures.export"sv); + SETTINGMAPPING_SPECIALIZATION(Setting::TelemetryDisable, bool, bool, false, ".telemetry.disable"sv); // Used to deduce the SettingVariant type; making a variant that includes std::monostate and all SettingMapping types. template diff --git a/src/AppInstallerCommonCore/UserSettings.cpp b/src/AppInstallerCommonCore/UserSettings.cpp index 260bb8ad24..091424e3dc 100644 --- a/src/AppInstallerCommonCore/UserSettings.cpp +++ b/src/AppInstallerCommonCore/UserSettings.cpp @@ -151,6 +151,14 @@ namespace AppInstaller::Settings namespace details { + // Stamps out a validate function that simply returns the input value. +#define WINGET_VALIDATE_PASS_THROUGH(_setting_) \ + std::optional::value_t> \ + SettingMapping::Validate(const SettingMapping::json_t& value) \ + { \ + return value; \ + } + std::optional::value_t> SettingMapping::Validate(const SettingMapping::json_t& value) { @@ -181,53 +189,15 @@ namespace AppInstaller::Settings return {}; } - std::optional::value_t> - SettingMapping::Validate(const SettingMapping::json_t& value) - { - return value; - } - - std::optional::value_t> - SettingMapping::Validate(const SettingMapping::json_t& value) - { - return value; - } - - std::optional::value_t> - SettingMapping::Validate(const SettingMapping::json_t& value) - { - return value; - } - - std::optional::value_t> - SettingMapping::Validate(const SettingMapping::json_t& value) - { - return value; - } - - std::optional::value_t> - SettingMapping::Validate(const SettingMapping::json_t& value) - { - return value; - } - - std::optional::value_t> - SettingMapping::Validate(const SettingMapping::json_t& value) - { - return value; - } - - std::optional::value_t> - SettingMapping::Validate(const SettingMapping::json_t& value) - { - return value; - } - - std::optional::value_t> - SettingMapping::Validate(const SettingMapping::json_t& value) - { - return value; - } + WINGET_VALIDATE_PASS_THROUGH(EFExperimentalCmd) + WINGET_VALIDATE_PASS_THROUGH(EFExperimentalArg) + WINGET_VALIDATE_PASS_THROUGH(EFExperimentalMSStore) + WINGET_VALIDATE_PASS_THROUGH(EFList) + WINGET_VALIDATE_PASS_THROUGH(EFExperimentalUpgrade) + WINGET_VALIDATE_PASS_THROUGH(EFUninstall) + WINGET_VALIDATE_PASS_THROUGH(EFImport) + WINGET_VALIDATE_PASS_THROUGH(EFExport) + WINGET_VALIDATE_PASS_THROUGH(TelemetryDisable) } UserSettings::UserSettings() : m_type(UserSettingsType::Default)