public void ActionsTelemetryService_EmitActionEvent_OperationNoOp(NuGetOperationType operationType) { // Arrange var telemetrySession = new Mock <ITelemetrySession>(); TelemetryEvent lastTelemetryEvent = null; telemetrySession .Setup(x => x.PostEvent(It.IsAny <TelemetryEvent>())) .Callback <TelemetryEvent>(x => lastTelemetryEvent = x); var actionTelemetryData = new VSActionsTelemetryEvent( projectIds: new[] { Guid.NewGuid().ToString() }, operationType: operationType, source: OperationSource.PMC, startTime: DateTimeOffset.Now.AddSeconds(-1), status: NuGetOperationStatus.NoOp, packageCount: 1, endTime: DateTimeOffset.Now, duration: .40); var service = new NuGetVSActionTelemetryService(telemetrySession.Object); // Act service.EmitTelemetryEvent(actionTelemetryData); // Assert VerifyTelemetryEventData(service.OperationId, actionTelemetryData, lastTelemetryEvent); }
public void ActionsTelemetryService_EmitActionStepsEvent(string stepName) { // Arrange var telemetrySession = new Mock <ITelemetrySession>(); TelemetryEvent lastTelemetryEvent = null; telemetrySession .Setup(x => x.PostEvent(It.IsAny <TelemetryEvent>())) .Callback <TelemetryEvent>(x => lastTelemetryEvent = x); var duration = 1.12; var stepNameWithProject = string.Format(stepName, "testProject"); var service = new NuGetVSActionTelemetryService(telemetrySession.Object); // Act service.EmitTelemetryEvent(new ActionTelemetryStepEvent(stepNameWithProject, duration)); // Assert Assert.NotNull(lastTelemetryEvent); Assert.Equal(ActionTelemetryStepEvent.NugetActionStepsEventName, lastTelemetryEvent.Name); Assert.Equal(3, lastTelemetryEvent.Count); Assert.Equal(service.OperationId, lastTelemetryEvent["OperationId"].ToString()); Assert.Equal(stepNameWithProject, lastTelemetryEvent["StepName"].ToString()); Assert.Equal(duration, (double)lastTelemetryEvent["Duration"]); }
public void RestoreTelemetryService_EmitRestoreEvent_OperationSucceed(RestoreOperationSource source, NuGetOperationStatus status) { // Arrange var telemetrySession = new Mock <ITelemetrySession>(); TelemetryEvent lastTelemetryEvent = null; telemetrySession .Setup(x => x.PostEvent(It.IsAny <TelemetryEvent>())) .Callback <TelemetryEvent>(x => lastTelemetryEvent = x); var noopProjectsCount = 0; if (status == NuGetOperationStatus.NoOp) { noopProjectsCount = 1; } var stausMessage = status == NuGetOperationStatus.Failed ? "Operation Failed" : string.Empty; var restoreTelemetryData = new RestoreTelemetryEvent( projectIds: new[] { Guid.NewGuid().ToString() }, source: source, startTime: DateTimeOffset.Now.AddSeconds(-3), status: status, packageCount: 2, noOpProjectsCount: noopProjectsCount, endTime: DateTimeOffset.Now, duration: 2.10); var service = new NuGetVSActionTelemetryService(telemetrySession.Object); // Act service.EmitTelemetryEvent(restoreTelemetryData); // Assert VerifyTelemetryEventData(service.OperationId, restoreTelemetryData, lastTelemetryEvent); }
protected override void ProcessRecordCore() { var startTime = DateTimeOffset.Now; // Set to log telemetry granular events for this install operation TelemetryService = new NuGetVSActionTelemetryService(); // start timer for telemetry event TelemetryServiceUtility.StartOrResumeTimer(); // Run Preprocess outside of JTF Preprocess(); NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await _lockService.ExecuteNuGetOperationAsync(() => { SubscribeToProgressEvents(); WarnIfParametersAreNotSupported(); if (!_readFromPackagesConfig && !_readFromDirectPackagePath && _nugetVersion == null) { Task.Run(InstallPackageByIdAsync); } else { var identities = GetPackageIdentities(); Task.Run(() => InstallPackagesAsync(identities)); } WaitAndLogPackageActions(); UnsubscribeFromProgressEvents(); return(Task.FromResult(true)); }, Token); }); // stop timer for telemetry event and create action telemetry event instance TelemetryServiceUtility.StopTimer(); var actionTelemetryEvent = VSTelemetryServiceUtility.GetActionTelemetryEvent( new[] { Project }, NuGetOperationType.Install, OperationSource.PMC, startTime, _status, _packageCount, TelemetryServiceUtility.GetTimerElapsedTimeInSeconds()); // emit telemetry event along with granular level events TelemetryService.EmitTelemetryEvent(actionTelemetryEvent); }
protected override void ProcessRecordCore() { var startTime = DateTimeOffset.Now; // Set to log telemetry granular events for this update operation TelemetryService = new NuGetVSActionTelemetryService(); // start timer for telemetry event TelemetryServiceUtility.StartOrResumeTimer(); // Run Preprocess outside of JTF Preprocess(); NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await _lockService.ExecuteNuGetOperationAsync(() => { SubscribeToProgressEvents(); WarnIfParametersAreNotSupported(); // Update-Package without ID specified if (!_idSpecified) { Task.Run(UpdateOrReinstallAllPackagesAsync); } // Update-Package with Id specified else { Task.Run(UpdateOrReinstallSinglePackageAsync); } WaitAndLogPackageActions(); UnsubscribeFromProgressEvents(); return(Task.FromResult(true)); }, Token); }); // stop timer for telemetry event and create action telemetry event instance TelemetryServiceUtility.StopTimer(); var actionTelemetryEvent = VSTelemetryServiceUtility.GetActionTelemetryEvent( new[] { Project }, NuGetOperationType.Update, OperationSource.PMC, startTime, _status, _packageCount, TelemetryServiceUtility.GetTimerElapsedTimeInSeconds()); // emit telemetry event along with granular level for update operation TelemetryService.EmitTelemetryEvent(actionTelemetryEvent); }
protected override void ProcessRecordCore() { var startTime = DateTimeOffset.Now; _packageCount = 1; // Enable granular level events for this uninstall operation TelemetryService = new NuGetVSActionTelemetryService(); TelemetryServiceUtility.StartOrResumeTimer(); // Run Preprocess outside of JTF Preprocess(); NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await _lockService.ExecuteNuGetOperationAsync(() => { SubscribeToProgressEvents(); Task.Run(UninstallPackageAsync); WaitAndLogPackageActions(); UnsubscribeFromProgressEvents(); return(Task.FromResult(true)); }, Token); }); TelemetryServiceUtility.StopTimer(); var actionTelemetryEvent = VSTelemetryServiceUtility.GetActionTelemetryEvent( new[] { Project }, NuGetOperationType.Uninstall, OperationSource.PMC, startTime, _status, _packageCount, TelemetryServiceUtility.GetTimerElapsedTimeInSeconds()); // emit telemetry event with granular level events TelemetryService.EmitTelemetryEvent(actionTelemetryEvent); }
/// <summary> /// The internal implementation to perform user action. /// </summary> /// <param name="resolveActionsAsync">A function that returns a task that resolves the user /// action into project actions.</param> /// <param name="executeActionsAsync">A function that returns a task that executes /// the project actions.</param> private async Task PerformActionImplAsync( INuGetUI uiService, Func <SourceCacheContext, Task <IReadOnlyList <ResolvedAction> > > resolveActionsAsync, Func <IReadOnlyList <ResolvedAction>, SourceCacheContext, Task> executeActionsAsync, NuGetOperationType operationType, CancellationToken token) { var status = NuGetOperationStatus.Succeeded; var startTime = DateTimeOffset.Now; var packageCount = 0; var operationId = Guid.NewGuid().ToString(); // Enable granular level telemetry events for nuget ui operation var telemetryService = new NuGetVSActionTelemetryService(); uiService.ProjectContext.TelemetryService = telemetryService; await _lockService.ExecuteNuGetOperationAsync(async() => { try { uiService.BeginOperation(); var acceptedFormat = await CheckPackageManagementFormat(uiService, token); if (!acceptedFormat) { return; } TelemetryServiceUtility.StartOrResumeTimer(); using (var sourceCacheContext = new SourceCacheContext()) { var actions = await resolveActionsAsync(sourceCacheContext); var results = GetPreviewResults(actions); if (operationType == NuGetOperationType.Uninstall) { packageCount = results.SelectMany(result => result.Deleted). Select(package => package.Id).Distinct().Count(); } else { var addCount = results.SelectMany(result => result.Added). Select(package => package.Id).Distinct().Count(); var updateCount = results.SelectMany(result => result.Updated). Select(result => result.New.Id).Distinct().Count(); // update packages count packageCount = addCount + updateCount; if (updateCount > 0) { // set operation type to update when there are packages being updated operationType = NuGetOperationType.Update; } } TelemetryServiceUtility.StopTimer(); // Show the preview window. if (uiService.DisplayPreviewWindow) { var shouldContinue = uiService.PromptForPreviewAcceptance(results); if (!shouldContinue) { return; } } TelemetryServiceUtility.StartOrResumeTimer(); // Show the license acceptance window. var accepted = await CheckLicenseAcceptanceAsync(uiService, results, token); TelemetryServiceUtility.StartOrResumeTimer(); if (!accepted) { return; } // Warn about the fact that the "dotnet" TFM is deprecated. if (uiService.DisplayDeprecatedFrameworkWindow) { var shouldContinue = ShouldContinueDueToDotnetDeprecation(uiService, actions, token); TelemetryServiceUtility.StartOrResumeTimer(); if (!shouldContinue) { return; } } if (!token.IsCancellationRequested) { // execute the actions await executeActionsAsync(actions, sourceCacheContext); // fires ActionsExecuted event to update the UI uiService.OnActionsExecuted(actions); } } } catch (System.Net.Http.HttpRequestException ex) { status = NuGetOperationStatus.Failed; if (ex.InnerException != null) { uiService.ShowError(ex.InnerException); } else { uiService.ShowError(ex); } } catch (Exception ex) { status = NuGetOperationStatus.Failed; uiService.ShowError(ex); } finally { TelemetryServiceUtility.StopTimer(); var duration = TelemetryServiceUtility.GetTimerElapsedTime(); uiService.ProjectContext.Log(MessageLevel.Info, string.Format(CultureInfo.CurrentCulture, Resources.Operation_TotalTime, duration)); uiService.EndOperation(); var actionTelemetryEvent = VSTelemetryServiceUtility.GetActionTelemetryEvent( uiService.Projects, operationType, OperationSource.UI, startTime, status, packageCount, duration.TotalSeconds); telemetryService.EmitTelemetryEvent(actionTelemetryEvent); } }, token); }