Merged PR 10794979: Add Recall Telemetry

**Snapshot**
EventName: `RecallSnapshot`
Payload example:` { "CalcMode": "Standard"}`
**_Fires when a snapshot (UserActivityRequested) is triggered_**

**Restore**
EventName: `RecallRestore`
Payload example:`{ "CalcMode": "Standard"}`
**_Fires when launching by snapshot (recall restore)**

**Error**
EventName: `Exception`
Payload example: `{ "CalcMode": "Standard", "FunctionName" : "MainPage::ShowSnapshotLaunchErrorAsync", "Message": "SnapshotRestoreError" }`
**_Fires when launching by snapshot failed_**

Related work items: #51114542
This commit is contained in:
Jian Zhang 2024-05-27 06:25:50 +00:00 committed by Han Zhang 👾
commit 7ebd296d69
3 changed files with 64 additions and 6 deletions

View file

@ -43,6 +43,8 @@ namespace CalculatorApp
constexpr auto EVENT_NAME_VARIABLE_SETTING_CHANGED = L"VariableSettingChanged"; constexpr auto EVENT_NAME_VARIABLE_SETTING_CHANGED = L"VariableSettingChanged";
constexpr auto EVENT_NAME_GRAPH_SETTINGS_CHANGED = L"GraphSettingsChanged"; constexpr auto EVENT_NAME_GRAPH_SETTINGS_CHANGED = L"GraphSettingsChanged";
constexpr auto EVENT_NAME_GRAPH_THEME = L"GraphTheme"; constexpr auto EVENT_NAME_GRAPH_THEME = L"GraphTheme";
constexpr auto EVENT_NAME_RECALL_SNAPSHOT = L"RecallSnapshot";
constexpr auto EVENT_NAME_RECALL_RESTORE = L"RecallRestore";
constexpr auto EVENT_NAME_EXCEPTION = L"Exception"; constexpr auto EVENT_NAME_EXCEPTION = L"Exception";
@ -328,4 +330,27 @@ namespace CalculatorApp
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_GRAPH_THEME), fields); TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_GRAPH_THEME), fields);
} }
void TraceLogger::LogRecallSnapshot(ViewMode mode)
{
auto fields = ref new LoggingFields();
fields->AddString(StringReference(CALC_MODE), NavCategoryStates::GetFriendlyName(mode));
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_RECALL_SNAPSHOT), fields);
}
void TraceLogger::LogRecallRestore(ViewMode mode)
{
auto fields = ref new LoggingFields();
fields->AddString(StringReference(CALC_MODE), NavCategoryStates::GetFriendlyName(mode));
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_RECALL_RESTORE), fields);
}
void TraceLogger::LogRecallError(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String^ message)
{
auto fields = ref new LoggingFields();
fields->AddString(StringReference(CALC_MODE), NavCategoryStates::GetFriendlyName(mode));
fields->AddString(StringReference(L"FunctionName"), L"Recall");
fields->AddString(StringReference(L"Message"), message);
TraceLoggingCommon::GetInstance()->LogLevel2Event(StringReference(EVENT_NAME_EXCEPTION), fields);
}
} }

View file

@ -85,6 +85,9 @@ namespace CalculatorApp::ViewModel::Common
void LogGraphTheme(Platform::String ^ graphTheme); void LogGraphTheme(Platform::String ^ graphTheme);
void LogInputPasted(CalculatorApp::ViewModel::Common::ViewMode mode); void LogInputPasted(CalculatorApp::ViewModel::Common::ViewMode mode);
void LogPlatformExceptionInfo(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::String ^ message, int hresult); void LogPlatformExceptionInfo(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::String ^ message, int hresult);
void LogRecallSnapshot(CalculatorApp::ViewModel::Common::ViewMode mode);
void LogRecallRestore(CalculatorApp::ViewModel::Common::ViewMode mode);
void LogRecallError(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ message);
internal: internal:
void LogPlatformException(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::Exception ^ e); void LogPlatformException(CalculatorApp::ViewModel::Common::ViewMode mode, Platform::String ^ functionName, Platform::Exception ^ e);

View file

@ -78,6 +78,7 @@ namespace CalculatorApp
await activity.SaveAsync(); await activity.SaveAsync();
args.Request.SetUserActivity(activity); args.Request.SetUserActivity(activity);
deferral.Complete(); deferral.Complete();
TraceLogger.GetInstance().LogRecallSnapshot(Model.Mode);
}; };
} }
@ -169,17 +170,14 @@ namespace CalculatorApp
var channel = UserActivityChannel.GetDefault(); var channel = UserActivityChannel.GetDefault();
var activity = await channel.GetOrCreateUserActivityAsync(snapshotArgs.ActivityId); var activity = await channel.GetOrCreateUserActivityAsync(snapshotArgs.ActivityId);
// Work around for bug https://microsoft.visualstudio.com/DefaultCollection/OS/_workitems/edit/48931227 if (TryRestoreFromActivity(snapshotArgs, activity, out var errorMessage))
// where ContentInfo can't be directly accessed.
if (snapshotArgs.VerifyIncomingActivity(activity) &&
JsonObject.TryParse(activity.ToJson(), out var activityJson) &&
activityJson.ContainsKey("contentInfo") &&
Model.TryRestoreFromSnapshot(activityJson.GetNamedObject("contentInfo")))
{ {
TraceLogger.GetInstance().LogRecallRestore(Model.Mode);
SelectNavigationItemByModel(); SelectNavigationItemByModel();
} }
else else
{ {
TraceLogger.GetInstance().LogRecallError(Model.Mode, errorMessage);
await ShowSnapshotLaunchErrorAsync(); await ShowSnapshotLaunchErrorAsync();
} }
}); });
@ -191,6 +189,38 @@ namespace CalculatorApp
} }
} }
private bool TryRestoreFromActivity(SnapshotLaunchArguments snapshotArgs, UserActivity activity, out string errorMessage)
{
if (!snapshotArgs.VerifyIncomingActivity(activity))
{
errorMessage = "IncomingActivityFailed";
return false;
}
// Work around for bug https://microsoft.visualstudio.com/DefaultCollection/OS/_workitems/edit/48931227
// where ContentInfo can't be directly accessed.
if (!JsonObject.TryParse(activity.ToJson(), out var activityJson))
{
errorMessage = "ParseJsonError";
return false;
}
if (!activityJson.ContainsKey("contentInfo"))
{
errorMessage = "ContentInfoNotExist";
return false;
}
if (!Model.TryRestoreFromSnapshot(activityJson.GetNamedObject("contentInfo")))
{
errorMessage = "RestoreFromSnapshotFailed";
return false;
}
errorMessage = string.Empty;
return true;
}
private void InitializeNavViewCategoriesSource() private void InitializeNavViewCategoriesSource()
{ {
NavViewCategoriesSource = ExpandNavViewCategoryGroups(Model.Categories); NavViewCategoriesSource = ExpandNavViewCategoryGroups(Model.Categories);