private void EmitRestoreTelemetryEvent(IEnumerable <NuGetProject> projects,
                                               bool forceRestore,
                                               RestoreOperationSource source,
                                               DateTimeOffset startTime,
                                               double duration,
                                               PackageSourceTelemetry.Totals protocolDiagnosticTotals,
                                               IntervalTracker intervalTimingTracker)
        {
            var sortedProjects = projects.OrderBy(
                project => project.GetMetadata <string>(NuGetProjectMetadataKeys.UniqueName));
            var projectIds = sortedProjects.Select(
                project => project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId)).ToArray();

            var restoreTelemetryEvent = new RestoreTelemetryEvent(
                _nuGetProjectContext.OperationId.ToString(),
                projectIds,
                forceRestore,
                source,
                startTime,
                _status,
                _packageCount,
                _upToDateProjectCount,
                _noOpProjectsCount,
                DateTimeOffset.Now,
                duration,
                intervalTimingTracker);

            TelemetryActivity.EmitTelemetryEvent(restoreTelemetryEvent);

            var sources     = _sourceRepositoryProvider.PackageSourceProvider.LoadPackageSources().ToList();
            var sourceEvent = SourceTelemetry.GetRestoreSourceSummaryEvent(_nuGetProjectContext.OperationId, sources, protocolDiagnosticTotals);

            TelemetryActivity.EmitTelemetryEvent(sourceEvent);
        }
Example #2
0
 public SourceSummaryTelemetryEvent(
     string eventName,
     Guid parentId,
     int local,
     int httpV2,
     int httpV3,
     string nugetOrg,
     bool vsOfflinePackages,
     bool dotnetCuratedFeed,
     PackageSourceTelemetry.Totals protocolDiagnosticTotals,
     int httpsV2,
     int httpsV3)
     : base(eventName)
 {
     this["NumLocalFeeds"]     = local;
     this["NumHTTPv2Feeds"]    = httpV2;
     this["NumHTTPv3Feeds"]    = httpV3;
     this["NumHTTPSv2Feeds"]   = httpsV2;
     this["NumHTTPSv3Feeds"]   = httpsV3;
     this["NuGetOrg"]          = nugetOrg;
     this["VsOfflinePackages"] = vsOfflinePackages;
     this["DotnetCuratedFeed"] = dotnetCuratedFeed;
     this["ParentId"]          = parentId.ToString();
     this["protocol.requests"] = protocolDiagnosticTotals.Requests;
     this["protocol.bytes"]    = protocolDiagnosticTotals.Bytes;
     this["protocol.duration"] = protocolDiagnosticTotals.Duration.TotalMilliseconds;
 }
Example #3
0
 public static TelemetryEvent GetSearchSourceSummaryEvent(
     Guid parentId,
     IEnumerable <PackageSource> packageSources,
     PackageSourceTelemetry.Totals protocolDiagnosticTotals)
 {
     return(GetSourceSummaryEvent(
                "SearchPackageSourceSummary",
                parentId,
                packageSources,
                protocolDiagnosticTotals));
 }
Example #4
0
        private void EmitRestoreTelemetryEvent(IEnumerable <NuGetProject> projects,
                                               bool forceRestore,
                                               RestoreOperationSource source,
                                               DateTimeOffset startTime,
                                               double duration,
                                               PackageSourceTelemetry.Totals protocolDiagnosticTotals,
                                               IntervalTracker intervalTimingTracker)
        {
            var sortedProjects = projects.OrderBy(
                project => project.GetMetadata <string>(NuGetProjectMetadataKeys.UniqueName));
            var projectIds = sortedProjects.Select(
                project => project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId)).ToArray();
            var projectDictionary = sortedProjects
                                    .GroupBy(x => x.ProjectStyle)
                                    .ToDictionary(x => x.Key, y => y.Count());

            var  packageSourceMapping          = PackageSourceMapping.GetPackageSourceMapping(_settings);
            bool isPackageSourceMappingEnabled = packageSourceMapping?.IsEnabled ?? false;

            var restoreTelemetryEvent = new RestoreTelemetryEvent(
                _nuGetProjectContext.OperationId.ToString(),
                projectIds,
                forceRestore,
                source,
                startTime,
                _status,
                packageCount: _packageCount,
                noOpProjectsCount: _noOpProjectsCount,
                upToDateProjectsCount: _upToDateProjectCount,
                unknownProjectsCount: projectDictionary.GetValueOrDefault(ProjectStyle.Unknown, 0), // appears in DependencyGraphRestoreUtility
                projectJsonProjectsCount: projectDictionary.GetValueOrDefault(ProjectStyle.ProjectJson, 0),
                packageReferenceProjectsCount: projectDictionary.GetValueOrDefault(ProjectStyle.PackageReference, 0),
                legacyPackageReferenceProjectsCount: sortedProjects.Where(x => x.ProjectStyle == ProjectStyle.PackageReference && x is LegacyPackageReferenceProject).Count(),
                cpsPackageReferenceProjectsCount: sortedProjects.Where(x => x.ProjectStyle == ProjectStyle.PackageReference && x is CpsPackageReferenceProject).Count(),
                dotnetCliToolProjectsCount: projectDictionary.GetValueOrDefault(ProjectStyle.DotnetCliTool, 0), // appears in DependencyGraphRestoreUtility
                packagesConfigProjectsCount: projectDictionary.GetValueOrDefault(ProjectStyle.PackagesConfig, 0),
                DateTimeOffset.Now,
                duration,
                _trackingData,
                intervalTimingTracker,
                isPackageSourceMappingEnabled);

            TelemetryActivity.EmitTelemetryEvent(restoreTelemetryEvent);

            var sources     = _sourceRepositoryProvider.PackageSourceProvider.LoadPackageSources().ToList();
            var sourceEvent = SourceTelemetry.GetRestoreSourceSummaryEvent(_nuGetProjectContext.OperationId, sources, protocolDiagnosticTotals);

            TelemetryActivity.EmitTelemetryEvent(sourceEvent);
        }
Example #5
0
        /// <summary>
        /// Create a SourceSummaryEvent event with counts of local vs http and v2 vs v3 feeds.
        /// </summary>
        private static TelemetryEvent GetSourceSummaryEvent(
            string eventName,
            Guid parentId,
            IEnumerable <PackageSource> packageSources,
            PackageSourceTelemetry.Totals protocolDiagnosticTotals)
        {
            var local             = 0;
            var httpV2            = 0;
            var httpV3            = 0;
            var nugetOrg          = HttpStyle.NotPresent;
            var vsOfflinePackages = false;
            var dotnetCuratedFeed = false;

            if (packageSources != null)
            {
                foreach (var source in packageSources)
                {
                    // Ignore disabled sources
                    if (source.IsEnabled)
                    {
                        if (source.IsHttp)
                        {
                            if (TelemetryUtility.IsHttpV3(source))
                            {
                                // Http V3 feed
                                httpV3++;

                                if (TelemetryUtility.IsNuGetOrg(source.Source))
                                {
                                    nugetOrg |= HttpStyle.YesV3;
                                }
                            }
                            else
                            {
                                // Http V2 feed
                                httpV2++;

                                if (TelemetryUtility.IsNuGetOrg(source.Source))
                                {
                                    if (source.Source.IndexOf(
                                            "api/v2/curated-feeds/microsoftdotnet",
                                            StringComparison.OrdinalIgnoreCase) >= 0)
                                    {
                                        dotnetCuratedFeed = true;
                                    }
                                    else
                                    {
                                        nugetOrg |= HttpStyle.YesV2;
                                    }
                                }
                            }
                        }
                        else
                        {
                            // Local or UNC feed
                            local++;

                            if (TelemetryUtility.IsVsOfflineFeed(source))
                            {
                                vsOfflinePackages = true;
                            }
                        }
                    }
                }
            }

            return(new SourceSummaryTelemetryEvent(
                       eventName,
                       parentId,
                       local,
                       httpV2,
                       httpV3,
                       nugetOrg.ToString(),
                       vsOfflinePackages,
                       dotnetCuratedFeed,
                       protocolDiagnosticTotals));
        }