Skip to content

Commit

Permalink
Addressed offline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AmelBawa-msft committed Dec 9, 2024
1 parent 9a41fff commit ff0ac7b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
23 changes: 9 additions & 14 deletions src/AppInstallerCommonCore/AppInstallerTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define AICLI_TraceLoggingStringView(_sv_,_name_) TraceLoggingCountedUtf8String(_sv_.data(), static_cast<ULONG>(_sv_.size()), _name_)
#define AICLI_TraceLoggingWStringView(_sv_,_name_) TraceLoggingCountedWideString(_sv_.data(), static_cast<ULONG>(_sv_.size()), _name_)
#define AICLI_TraceLoggingJsonWString(_sv_, _name_) TraceLoggingPackedFieldEx(_sv_.c_str(), static_cast<ULONG>((_sv_.size() + 1) * sizeof(wchar_t)), TlgInUNICODESTRING, TlgOutJSON, _name_)
#define AICLI_TraceLoggingJsonString(_sv_, _name_) TraceLoggingPackedFieldEx(_sv_.c_str(), static_cast<ULONG>((_sv_.size() + 1) * sizeof(char)), TlgInUNICODESTRING, TlgOutJSON, _name_)

#define AICLI_TraceLoggingWriteActivity(_eventName_,...) TraceLoggingWriteActivity(\
g_hTraceProvider,\
Expand Down Expand Up @@ -80,23 +81,17 @@ namespace AppInstaller::Logging
}
}

std::wstring GetExperimentsJson(const std::map<Experiment::Key, ExperimentState>& experiments)
std::string GetExperimentsJson(const std::map<Experiment::Key, ExperimentState>& experiments)
{
std::wstringstream ss;
ss << "{";
auto first = 0;
Json::Value root;
for (const auto& experiment : experiments)
{
if (first++ != 0)
{
ss << L",";
}

ss << L"\"" << Utility::ConvertToUTF16(Experiment::GetExperiment(experiment.first).JsonName())
<< L"\":" << experiment.second.ToJson();
auto name = std::string(Experiment::GetExperiment(experiment.first).JsonName());
root[name] = experiment.second.ToJson();
}
ss << L"}";
return ss.str();

Json::StreamWriterBuilder builder;
return Json::writeString(builder, root);
}
}

Expand Down Expand Up @@ -876,7 +871,7 @@ namespace AppInstaller::Logging
TraceLoggingUInt32(m_summary.RepairErrorCode, "RepairErrorCode"),
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance | PDT_ProductAndServiceUsage | PDT_SoftwareSetupAndInventory),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
AICLI_TraceLoggingJsonWString(experimentsJson, "ExperimentsJson"));
AICLI_TraceLoggingJsonString(experimentsJson, "ExperimentsJson"));
}
}
}
Expand Down
26 changes: 21 additions & 5 deletions src/AppInstallerCommonCore/Experiment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,30 @@ namespace AppInstaller::Settings
" is set to " << isEnabled);
return { isEnabled, ExperimentToggleSource::Default };
}

std::string ExperimentToggleSourceToString(ExperimentToggleSource source)
{
switch (source)
{
case ExperimentToggleSource::Default:
return "Default";
case ExperimentToggleSource::Policy:
return "Policy";
case ExperimentToggleSource::UserSetting:
return "UserSetting";
default:
return "Unknown";
}
}
}

std::wstring ExperimentState::ToJson() const
std::string ExperimentState::ToJson() const
{
std::wstringstream ss;
ss << L"{\"IsEnabled\":" << (m_isEnabled ? L"true" : L"false")
<< L",\"ToggleSource\":" << m_toggleSource << L"}";
return ss.str();
Json::Value root;
root["IsEnabled"] = m_isEnabled;
root["ToggleSource"] = ExperimentToggleSourceToString(m_toggleSource);
Json::StreamWriterBuilder builder;
return Json::writeString(builder, root);
}

ExperimentState Experiment::GetStateInternal(Key key)
Expand Down
8 changes: 4 additions & 4 deletions src/AppInstallerCommonCore/Public/winget/Experiment.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace AppInstaller::Settings
{
enum ExperimentToggleSource
{
Default,
Policy,
UserSetting
Default = 0,
Policy = 1,
UserSetting = 2,
};

struct ExperimentState
Expand All @@ -20,7 +20,7 @@ namespace AppInstaller::Settings
ExperimentState(bool isEnabled, ExperimentToggleSource toggleSource) : m_isEnabled(isEnabled), m_toggleSource(toggleSource) {}
bool IsEnabled() const { return m_isEnabled; }
ExperimentToggleSource ToggleSource() const { return m_toggleSource; }
std::wstring ToJson() const;
std::string ToJson() const;
private:
ExperimentToggleSource m_toggleSource;
bool m_isEnabled;
Expand Down

0 comments on commit ff0ac7b

Please sign in to comment.