Removing hardcoded version numbers from c# telemetry events. (#5283)

* Removing hardcoded version numbers from c# telemetry events.

* Removing dependency on powertoysInterop for getting version string.

* Defensive checks around getting assembly version
This commit is contained in:
ryanbodrug-microsoft
2020-07-29 11:18:21 -07:00
committed by GitHub
parent e23b406364
commit d98d1193fc
5 changed files with 22 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Reflection;
using System.Text;
namespace Microsoft.PowerToys.Telemetry.Events
@@ -12,5 +13,26 @@ namespace Microsoft.PowerToys.Telemetry.Events
public class EventBase
{
public bool UTCReplace_AppSessionGuid => true;
private string _version;
public string Version
{
get
{
if (string.IsNullOrEmpty(_version))
{
_version = GetVersionFromAssembly();
}
return _version;
}
}
private string GetVersionFromAssembly()
{
// For consistency this should be formatted the same way as
// https://github.com/microsoft/PowerToys/blob/710f92d99965109fd788d85ebf8b6b9e0ba1524a/src/common/common.cpp#L635
var version = Assembly.GetExecutingAssembly()?.GetName()?.Version ?? new Version();
return $"v{version.Major}.{version.Minor}.{version.Build}";
}
}
}

View File

@@ -11,11 +11,6 @@ namespace Microsoft.PowerLauncher.Telemetry
[EventData]
public class SettingsBootEvent : EventBase, IEvent
{
/// <summary>
/// Gets The version string. TODO: This should be replaced by a P/Invoke call to get_product_version
/// </summary>
public string Version => "v0.19.3";
public double BootTimeMs { get; set; }
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;

View File

@@ -7,11 +7,6 @@ namespace Microsoft.PowerLauncher.Telemetry
[EventData]
public class LauncherBootEvent : EventBase, IEvent
{
/// <summary>
/// TODO: This should be replaced by a P/Invoke call to get_product_version
/// </summary>
public string Version => "v0.19.3";
public double BootTimeMs { get; set; }
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServicePerformance;

View File

@@ -14,11 +14,6 @@ namespace MarkdownPreviewHandler.Telemetry.Events
[EventData]
public class MarkdownFileHandlerLoaded : EventBase, IEvent
{
/// <summary>
/// Gets The version string. TODO: This should be replaced by a P/Invoke call to get_product_version.
/// </summary>
public string Version => "v0.19.3";
/// <inheritdoc/>
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}

View File

@@ -14,11 +14,6 @@ namespace SvgPreviewHandler.Telemetry.Events
[EventData]
public class SvgFileHandlerLoaded : EventBase, IEvent
{
/// <summary>
/// Gets The version string. TODO: This should be replaced by a P/Invoke call to get_product_version.
/// </summary>
public string Version => "v0.19.3";
/// <inheritdoc/>
public PartA_PrivTags PartA_PrivTags => PartA_PrivTags.ProductAndServiceUsage;
}