Skip to content

Commit

Permalink
Adds projectKind and projectId to PMUIRefresh event (#4981)
Browse files Browse the repository at this point in the history
Fixes https://github.com/NuGet/Client.Engineering/issues/1997

Adds projectId and projectKind to pmuirefresh event.
  • Loading branch information
Fernando Aguilar authored Dec 13, 2022
1 parent 0e7accb commit d3639a5
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,31 @@ private async ValueTask RefreshWhenNotExecutingActionAsync(RefreshOperationSourc

private void EmitRefreshEvent(TimeSpan timeSpan, RefreshOperationSource refreshOperationSource, RefreshOperationStatus status, bool isUIFiltering = false, double? duration = null)
{
TelemetryActivity.EmitTelemetryEvent(
new PackageManagerUIRefreshEvent(
if (Model.IsSolution)
{
TelemetryActivity.EmitTelemetryEvent(PackageManagerUIRefreshEvent.ForSolution(
_sessionGuid,
Model.IsSolution,
refreshOperationSource,
status,
_topPanel.Filter.ToString(),
UIUtility.ToContractsItemFilter(_topPanel.Filter),
isUIFiltering,
timeSpan,
duration));
}
else
{
IProjectContextInfo project = Model.Context.Projects.First();
TelemetryActivity.EmitTelemetryEvent(PackageManagerUIRefreshEvent.ForProject(
_sessionGuid,
refreshOperationSource,
status,
UIUtility.ToContractsItemFilter(_topPanel.Filter),
isUIFiltering,
timeSpan,
duration,
project.ProjectId,
project.ProjectKind));
}
}

private void EmitPMUIClosingTelemetry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@

using System;
using NuGet.Common;
using NuGet.VisualStudio.Internal.Contracts;

namespace NuGet.PackageManagement.Telemetry
{
public sealed class PackageManagerUIRefreshEvent : TelemetryEvent
{
private const string EventName = "PMUIRefresh";

public PackageManagerUIRefreshEvent(
private PackageManagerUIRefreshEvent(
Guid parentId,
bool isSolutionLevel,
RefreshOperationSource refreshSource,
RefreshOperationStatus refreshStatus,
string tab,
ItemFilter tab,
bool isUIFiltering,
TimeSpan timeSinceLastRefresh,
double? duration) : base(EventName)
double? duration,
string projectId = null,
NuGetProjectKind? projectKind = null) : base(EventName)
{
base["ParentId"] = parentId.ToString();
base["IsSolutionLevel"] = isSolutionLevel;
Expand All @@ -28,11 +31,71 @@ public PackageManagerUIRefreshEvent(
base["IsUIFiltering"] = isUIFiltering;
base["TimeSinceLastRefresh"] = timeSinceLastRefresh.TotalMilliseconds;

if (!isSolutionLevel)
{
if (projectId != null)
{
base["ProjectId"] = projectId;
}
if (projectKind.HasValue)
{
base["ProjectKind"] = projectKind;
}
}

if (duration.HasValue)
{
base["Duration"] = duration;
}
}

public static PackageManagerUIRefreshEvent ForProject(
Guid parentId,
RefreshOperationSource refreshSource,
RefreshOperationStatus refreshStatus,
ItemFilter tab,
bool isUIFiltering,
TimeSpan timeSinceLastRefresh,
double? duration,
string projectId,
NuGetProjectKind projectKind)
{
var evt = new PackageManagerUIRefreshEvent(
parentId,
isSolutionLevel: false,
refreshSource,
refreshStatus,
tab,
isUIFiltering,
timeSinceLastRefresh,
duration,
projectId,
projectKind);

return evt;
}

public static PackageManagerUIRefreshEvent ForSolution(
Guid parentId,
RefreshOperationSource refreshSource,
RefreshOperationStatus refreshStatus,
ItemFilter tab,
bool isUIFiltering,
TimeSpan timeSinceLastRefresh,
double? duration)
{
var evt = new PackageManagerUIRefreshEvent(
parentId,
isSolutionLevel: true,
refreshSource,
refreshStatus,
tab,
isUIFiltering,
timeSinceLastRefresh,
duration);

return evt;
}
}

public enum RefreshOperationSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="Services\TestSharedServiceState.cs" />
<Compile Include="Services\NuGetPackageSearchServiceTests.cs" />
<Compile Include="Telemetry\ActionsTelemetryServiceTests.cs" />
<Compile Include="Telemetry\PackageManagerUIRefreshTelemetryTests.cs" />
<Compile Include="Telemetry\TelemetryOnceEmitterTests.cs" />
<Compile Include="Telemetry\HyperlinkClickedTelemetryEventTests.cs" />
<Compile Include="Telemetry\IntervalTrackerTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NuGet.Common;
using NuGet.PackageManagement.Telemetry;
using NuGet.VisualStudio;
using NuGet.VisualStudio.Internal.Contracts;
using Xunit;

namespace NuGet.PackageManagement.VisualStudio.Test
Expand Down Expand Up @@ -102,10 +103,10 @@ public void NuGetTelemetryService_EmitsPMUIRefreshEvent(RefreshOperationSource e

var expectedGuid = Guid.NewGuid();
var expectedIsSolutionLevel = true;
var expectedTab = "All";
var expectedTab = ItemFilter.All;
var expectedTimeSinceLastRefresh = TimeSpan.FromSeconds(1);
var expectedDuration = TimeSpan.FromSeconds(1);
var refreshEvent = new PackageManagerUIRefreshEvent(expectedGuid, expectedIsSolutionLevel, expectedRefreshSource, expectedRefreshStatus, expectedTab, isUIFiltering: expectedUiFiltering, expectedTimeSinceLastRefresh, expectedDuration.TotalMilliseconds);
var refreshEvent = PackageManagerUIRefreshEvent.ForSolution(expectedGuid, expectedRefreshSource, expectedRefreshStatus, expectedTab, isUIFiltering: expectedUiFiltering, expectedTimeSinceLastRefresh, expectedDuration.TotalMilliseconds);
var target = new NuGetVSTelemetryService(telemetrySession.Object);

// Act
Expand Down Expand Up @@ -139,7 +140,7 @@ public void NuGetTelemetryService_EmitsPMUIRefreshEvent(RefreshOperationSource e

var tab = lastTelemetryEvent["Tab"];
Assert.NotNull(tab);
Assert.IsType<string>(tab);
Assert.IsType<ItemFilter>(tab);
Assert.Equal(expectedTab, tab);

var isUIFiltering = lastTelemetryEvent["IsUIFiltering"];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Moq;
using NuGet.PackageManagement.Telemetry;
using NuGet.VisualStudio.Internal.Contracts;
using Xunit;

namespace NuGet.PackageManagement.VisualStudio.Test
{
public class PackageManagerUIRefreshTelemetryTests
{
[Fact]
public void ForSolution_SimulatedData_NoProjectKindIfIsSolutionLevelSetToTrue()
{
var telemetryEvent = PackageManagerUIRefreshEvent.ForSolution(
It.IsAny<Guid>(),
It.IsAny<RefreshOperationSource>(),
It.IsAny<RefreshOperationStatus>(),
tab: It.IsAny<ItemFilter>(),
isUIFiltering: It.IsAny<bool>(),
It.IsAny<TimeSpan>(),
It.IsAny<double?>());

Assert.Null(telemetryEvent["ProjectKind"]);
Assert.Null(telemetryEvent["ProjectId"]);
}

[Fact]
public void ForProject_SimulatedData_ProjectKindAndProjectIdSet()
{
NuGetProjectKind kind = NuGetProjectKind.PackageReference;
string projectId = "simulated-project-id-Guid";
var telemetryEvent = PackageManagerUIRefreshEvent.ForProject(
It.IsAny<Guid>(),
It.IsAny<RefreshOperationSource>(),
It.IsAny<RefreshOperationStatus>(),
tab: It.IsAny<ItemFilter>(),
isUIFiltering: It.IsAny<bool>(),
It.IsAny<TimeSpan>(),
It.IsAny<double?>(),
projectId,
kind);

Assert.NotNull(telemetryEvent["ProjectKind"]);
Assert.NotNull(telemetryEvent["ProjectId"]);
}
}
}

0 comments on commit d3639a5

Please sign in to comment.